bug_id
stringlengths 5
6
| issue_url
stringlengths 49
50
| bug_type
stringclasses 3
values | base_commit
stringlengths 40
40
| knowledge_cutoff
timestamp[s]date 2024-01-02 12:49:15
2025-03-27 17:54:31
| lit_test_dir
sequencelengths 1
4
| hints
dict | patch
stringlengths 789
17.7k
| tests
listlengths 1
35
| issue
dict | verified
bool 1
class | test_commit
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
91691 | https://github.com/llvm/llvm-project/issues/91691 | miscompilation | 1fadb2b0c881ced247931f442fdee6c4ed96dccb | 2024-05-10T02:43:43 | [
"llvm/test/Transforms/InstCombine"
] | {
"fix_commit": "b5f4210e9f51f938ae517f219f04f9ab431a2684",
"components": [
"InstCombine"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [
[
3343,
3349
],
[
3366,
3371
],
[
3379,
3384
],
[
3448,
3461
]
],
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [
"foldBitCeil",
"isSafeToRemoveBitCeilSelect"
],
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit b5f4210e9f51f938ae517f219f04f9ab431a2684
Author: Yingwei Zheng <[email protected]>
Date: Mon May 13 14:27:59 2024 +0800
[InstCombine] Drop nuw flag when CtlzOp is a sub nuw (#91776)
See the following case:
```
define i32 @src1(i32 %x) {
%dec = sub nuw i32 -2, %x
%ctlz = tail call i32 @llvm.ctlz.i32(i32 %dec, i1 false)
%sub = sub nsw i32 32, %ctlz
%shl = shl i32 1, %sub
%ugt = icmp ult i32 %x, -2
%sel = select i1 %ugt, i32 %shl, i32 1
ret i32 %sel
}
define i32 @tgt1(i32 %x) {
%dec = sub nuw i32 -2, %x
%ctlz = tail call i32 @llvm.ctlz.i32(i32 %dec, i1 false)
%sub = sub nsw i32 32, %ctlz
%and = and i32 %sub, 31
%shl = shl nuw i32 1, %and
ret i32 %shl
}
```
`nuw` in `%dec` should be dropped after the select instruction is
eliminated.
Alive2: https://alive2.llvm.org/ce/z/7S9529
Fixes https://github.com/llvm/llvm-project/issues/91691.
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index ee090e012508..a3ddb402bf66 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -3343,7 +3343,8 @@ Instruction *InstCombinerImpl::foldSelectOfBools(SelectInst &SI) {
// pattern.
static bool isSafeToRemoveBitCeilSelect(ICmpInst::Predicate Pred, Value *Cond0,
const APInt *Cond1, Value *CtlzOp,
- unsigned BitWidth) {
+ unsigned BitWidth,
+ bool &ShouldDropNUW) {
// The challenge in recognizing std::bit_ceil(X) is that the operand is used
// for the CTLZ proper and select condition, each possibly with some
// operation like add and sub.
@@ -3366,6 +3367,8 @@ static bool isSafeToRemoveBitCeilSelect(ICmpInst::Predicate Pred, Value *Cond0,
ConstantRange CR = ConstantRange::makeExactICmpRegion(
CmpInst::getInversePredicate(Pred), *Cond1);
+ ShouldDropNUW = false;
+
// Match the operation that's used to compute CtlzOp from CommonAncestor. If
// CtlzOp == CommonAncestor, return true as no operation is needed. If a
// match is found, execute the operation on CR, update CR, and return true.
@@ -3379,6 +3382,7 @@ static bool isSafeToRemoveBitCeilSelect(ICmpInst::Predicate Pred, Value *Cond0,
return true;
}
if (match(CtlzOp, m_Sub(m_APInt(C), m_Specific(CommonAncestor)))) {
+ ShouldDropNUW = true;
CR = ConstantRange(*C).sub(CR);
return true;
}
@@ -3448,14 +3452,20 @@ static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder) {
Pred = CmpInst::getInversePredicate(Pred);
}
+ bool ShouldDropNUW;
+
if (!match(FalseVal, m_One()) ||
!match(TrueVal,
m_OneUse(m_Shl(m_One(), m_OneUse(m_Sub(m_SpecificInt(BitWidth),
m_Value(Ctlz)))))) ||
!match(Ctlz, m_Intrinsic<Intrinsic::ctlz>(m_Value(CtlzOp), m_Zero())) ||
- !isSafeToRemoveBitCeilSelect(Pred, Cond0, Cond1, CtlzOp, BitWidth))
+ !isSafeToRemoveBitCeilSelect(Pred, Cond0, Cond1, CtlzOp, BitWidth,
+ ShouldDropNUW))
return nullptr;
+ if (ShouldDropNUW)
+ cast<Instruction>(CtlzOp)->setHasNoUnsignedWrap(false);
+
// Build 1 << (-CTLZ & (BitWidth-1)). The negation likely corresponds to a
// single hardware instruction as opposed to BitWidth - CTLZ, where BitWidth
// is an integer constant. Masking with BitWidth-1 comes free on some
| [
{
"file": "llvm/test/Transforms/InstCombine/bit_ceil.ll",
"commands": [
"opt < %s -passes=instcombine -S"
],
"tests": [
{
"test_name": "pr91691",
"test_body": "define i32 @pr91691(i32 %0) {\n %2 = sub nuw i32 -2, %0\n %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)\n %4 = sub i32 32, %3\n %5 = shl i32 1, %4\n %6 = icmp ult i32 %0, -2\n %7 = select i1 %6, i32 %5, i32 1\n ret i32 %7\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctlz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "bit_ceil_v4i32",
"test_body": "define <4 x i32> @bit_ceil_v4i32(<4 x i32> %x) {\n %dec = add <4 x i32> %x, splat (i32 -1)\n %ctlz = tail call <4 x i32> @llvm.ctlz.v4i32(<4 x i32> %dec, i1 false)\n %sub = sub <4 x i32> splat (i32 32), %ctlz\n %shl = shl <4 x i32> splat (i32 1), %sub\n %ugt = icmp ugt <4 x i32> %x, splat (i32 1)\n %sel = select <4 x i1> %ugt, <4 x i32> %shl, <4 x i32> splat (i32 1)\n ret <4 x i32> %sel\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i32> @llvm.ctlz.v4i32(<4 x i32>, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "pr91691_keep_nsw",
"test_body": "define i32 @pr91691_keep_nsw(i32 %0) {\n %2 = sub nsw i32 -2, %0\n %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)\n %4 = sub i32 32, %3\n %5 = shl i32 1, %4\n %6 = icmp ult i32 %0, -2\n %7 = select i1 %6, i32 %5, i32 1\n ret i32 %7\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.ctlz.i32(i32, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "instcombine removes a select, making code more poisonous",
"body": "https://alive2.llvm.org/ce/z/c__jy8\r\n\r\nthis function:\r\n```llvm\r\ndefine i32 @f(i32 %0) {\r\n %2 = sub nuw i32 -2, %0\r\n %3 = tail call i32 @llvm.ctlz.i32(i32 %2, i1 false)\r\n %4 = sub i32 32, %3\r\n %5 = shl i32 1, %4\r\n %6 = icmp ult i32 %0, -2\r\n %7 = select i1 %6, i32 %5, i32 1\r\n ret i32 %7\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i32 @llvm.ctlz.i32(i32, i1 immarg) #0\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\n\r\nis getting rewritten to not have the select, but the select was blocking a poison value. the bad thing happens when -1 is passed as an argument, see the Alive link for a detailed execution trace\r\n\r\n```llvm\r\ndefine i32 @f(i32 %0) {\r\n %2 = sub nuw i32 -2, %0\r\n %3 = tail call range(i32 0, 33) i32 @llvm.ctlz.i32(i32 %2, i1 false)\r\n %4 = sub nsw i32 0, %3\r\n %5 = and i32 %4, 31\r\n %6 = shl nuw i32 1, %5\r\n ret i32 %6\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i32 @llvm.ctlz.i32(i32, i1 immarg) #0\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\n\r\ncc @nunoplopes ",
"author": "regehr",
"labels": [
"miscompilation",
"llvm:instcombine"
],
"comments": []
} | true | null |
125357 | https://github.com/llvm/llvm-project/issues/125357 | crash | cdeeb390a9ea21540fc44ba10dede66fbc0b2fc8 | 2025-02-01T20:11:30 | [
"llvm/test/Transforms/SLPVectorizer"
] | {
"fix_commit": "0c70a26f46e4efd5a29eb281ff99d2cf7f04c6f6",
"components": [
"SLPVectorizer"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
[
20147,
20153
]
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
"tryToReduce"
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 0c70a26f46e4efd5a29eb281ff99d2cf7f04c6f6
Author: Alexey Bataev <[email protected]>
Date: Mon Feb 3 04:37:49 2025 -0800
[SLP]Clear root node reordering only if the root node is not re-used in graph
The reordering of the root node can be safely cleared only if the root
node is not reused, otherwise the graph might be broken
Fixes #125357
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 4f83b9cfa18d..539c9227af7e 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -20147,7 +20147,7 @@ public:
}
V.reorderTopToBottom();
// No need to reorder the root node at all.
- V.reorderBottomToTop(/*IgnoreReorder=*/true);
+ V.reorderBottomToTop(!V.doesRootHaveInTreeUses());
// Keep extracted other reduction values, if they are used in the
// vectorization trees.
BoUpSLP::ExtraValueToDebugLocsMap LocalExternallyUsedValues(
| [
{
"file": "llvm/test/Transforms/SLPVectorizer/X86/root-node-reordered-reused.ll",
"commands": [
"opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s"
],
"tests": [
{
"test_name": "<module>",
"test_body": "; ModuleID = 'test.ll'\nsource_filename = \"test.c\"\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @main(i32 %0) {\nentry:\n %tobool.not = icmp eq i32 %0, 0\n br i1 %tobool.not, label %if.end6, label %if.then\n\nif.then: ; preds = %entry\n br i1 %tobool.not, label %if.end, label %i\n\nif.end: ; preds = %if.then\n br i1 %tobool.not, label %if.end6, label %i\n\nif.end6: ; preds = %if.end, %entry\n %h.0 = phi i32 [ %0, %if.end ], [ 0, %entry ]\n br i1 %tobool.not, label %i, label %if.end13\n\ni: ; preds = %if.end13, %if.end6, %if.end, %if.then\n %h.1 = phi i32 [ %0, %if.then ], [ %h.2, %if.end13 ], [ %0, %if.end ], [ %h.0, %if.end6 ]\n %j.0 = phi i32 [ undef, %if.then ], [ %j.1, %if.end13 ], [ undef, %if.end ], [ %0, %if.end6 ]\n %k.0 = phi i32 [ undef, %if.then ], [ %k.1, %if.end13 ], [ undef, %if.end ], [ %0, %if.end6 ]\n %l.0 = phi i32 [ undef, %if.then ], [ %l.1, %if.end13 ], [ undef, %if.end ], [ %0, %if.end6 ]\n %or = or i32 %j.0, %h.1\n %or9 = or i32 %or, %k.0\n %or10 = or i32 %or9, %l.0\n %tobool11.not = icmp eq i32 %or10, 0\n br i1 %tobool11.not, label %if.end13, label %land.rhs\n\nland.rhs: ; preds = %i\n br label %if.end13\n\nif.end13: ; preds = %i, %land.rhs, %if.end6\n %h.2 = phi i32 [ %h.0, %if.end6 ], [ %h.1, %land.rhs ], [ %h.1, %i ]\n %j.1 = phi i32 [ %0, %if.end6 ], [ %j.0, %land.rhs ], [ %j.0, %i ]\n %k.1 = phi i32 [ %0, %if.end6 ], [ %k.0, %land.rhs ], [ %k.0, %i ]\n %l.1 = phi i32 [ %0, %if.end6 ], [ %l.0, %land.rhs ], [ %l.0, %i ]\n br i1 true, label %if.end15, label %i\n\nif.end15: ; preds = %if.end13\n ret i32 0\n\n; uselistorder directives\n uselistorder i32 %k.0, { 1, 2, 0 }\n uselistorder i32 %l.0, { 1, 2, 0 }\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "clang crashes on valid code at -O{s,2,3} on x86_64-linux-gnu: Assertion `TE->isSame(VL) && \"Expected same scalars.\"' failed",
"body": "It appears to be a recent regression as it doesn't reproduce with 19.1.0 and earlier.\n\nCompiler Explorer: https://godbolt.org/z/6ca9841xE\n\n```\n[512] % clangtk -v\nclang version 21.0.0git (https://github.com/llvm/llvm-project.git 7612dcc6e8d8e7f19b364084effbb01946294720)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nCandidate multilib: .;@m64\nSelected multilib: .;@m64\n[513] % \n[513] % clangtk -O3 small.c\nclang-21: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:3011: llvm::slpvectorizer::BoUpSLP::TreeEntry* llvm::slpvectorizer::BoUpSLP::getVectorizedOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int): Assertion `TE->isSame(VL) && \"Expected same scalars.\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\nStack dump:\n0.\tProgram arguments: /local/suz-local/software/local/clang-trunk/bin/clang-21 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/local/suz-local/software/emitesting/bugs/20250201-clangtk-m64-O3-build-174536/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20250201-clangtk-m64-O3-build-174536/delta -resource-dir /local/suz-local/software/local/clang-trunk/lib/clang/21 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/suz-local/software/local/clang-trunk/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-b035e7.o -x c small.c\n1.\t<eof> parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function<eager-inv>(float2int,lower-constant-intrinsics,chr,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O3>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"small.c\"\n4.\tRunning pass \"slp-vectorizer\" on function \"main\"\n #0 0x00005596296c84af llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x479d4af)\n #1 0x00005596296c5c84 SignalHandler(int) Signals.cpp:0:0\n #2 0x00007fe817057420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\n #3 0x00007fe816a8e00b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\n #4 0x00007fe816a6d859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\n #5 0x00007fe816a6d729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\n #6 0x00007fe816a6d729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\n #7 0x00007fe816a7efd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\n #8 0x000055962b1df5c7 llvm::slpvectorizer::BoUpSLP::getSpillCost() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x62b45c7)\n #9 0x000055962b243030 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x6318030)\n#10 0x000055962b247f34 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&, llvm::AssumptionCache*) SLPVectorizer.cpp:0:0\n#11 0x000055962b24a205 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x631f205)\n#12 0x000055962b24ee25 bool llvm::SLPVectorizerPass::vectorizeCmpInsts<std::reverse_iterator<llvm::CmpInst* const*>>(llvm::iterator_range<std::reverse_iterator<llvm::CmpInst* const*>>, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x6323e25)\n#13 0x000055962b24fedb llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&)::'lambda3'(bool)::operator()(bool) const SLPVectorizer.cpp:0:0\n#14 0x000055962b253720 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x6328720)\n#15 0x000055962b259f46 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\n#16 0x000055962b25aaa3 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x632faa3)\n#17 0x000055962ac7c7e6 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5d517e6)\n#18 0x000055962903ed49 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4113d49)\n#19 0x000055962693a376 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x1a0f376)\n#20 0x000055962903d5b2 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x41125b2)\n#21 0x0000559626938aa6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x1a0daa6)\n#22 0x000055962903cfd1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4111fd1)\n#23 0x0000559629991596 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#24 0x0000559629995253 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x4a6a253)\n#25 0x000055962a09f2ce clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x51742ce)\n#26 0x000055962ba0f29c clang::ParseAST(clang::Sema&, bool, bool) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x6ae429c)\n#27 0x000055962a09f708 clang::CodeGenAction::ExecuteAction() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x5174708)\n#28 0x000055962a3719d9 clang::FrontendAction::Execute() (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x54469d9)\n#29 0x000055962a2f25be clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x53c75be)\n#30 0x000055962a466746 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x553b746)\n#31 0x00005596264d4a87 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x15a9a87)\n#32 0x00005596264cc33a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#33 0x00005596264d0471 clang_main(int, char**, llvm::ToolContext const&) (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x15a5471)\n#34 0x00005596263bb29b main (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x149029b)\n#35 0x00007fe816a6f083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\n#36 0x00005596264cbdce _start (/local/suz-local/software/local/clang-trunk/bin/clang-21+0x15a0dce)\nclangtk: error: unable to execute command: Aborted\nclangtk: error: clang frontend command failed due to signal (use -v to see invocation)\nclang version 21.0.0git (https://github.com/llvm/llvm-project.git 7612dcc6e8d8e7f19b364084effbb01946294720)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nclangtk: note: diagnostic msg: \n********************\n\nPLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\nPreprocessed source(s) and associated run script(s) are located at:\nclangtk: note: diagnostic msg: /tmp/small-401f68.c\nclangtk: note: diagnostic msg: /tmp/small-401f68.sh\nclangtk: note: diagnostic msg: \n\n********************\n[514] % \n[514] % cat small.c\nint a, b, c, d, e;\nvolatile int f;\nint main() {\n int h = 0, j, k, l;\n if (d) {\n h = c;\n if (f)\n goto i;\n if (f)\n goto i;\n }\n l = j = k = d;\n if (!b)\n i:\n (l | (h | j) | k) && f;\n if (a != e)\n goto i;\n return 0;\n}\n```\n\n\n",
"author": "zhendongsu",
"labels": [
"llvm:SLPVectorizer",
"crash",
"generated by fuzzer"
],
"comments": [
{
"author": "dtcxzyw",
"body": "Reduced reproducer: https://godbolt.org/z/TWadzP8Gc\n"
}
]
} | true | null |
122558 | https://github.com/llvm/llvm-project/issues/122558 | crash | 25f28ddd69ed2453726c0934ba6feea8ae6f10f8 | 2025-01-11T00:36:48 | [
"llvm/test/Transforms/LoopVectorize"
] | {
"fix_commit": "1de3dc7d23dd6b856efad3a3a04f2396328726d7",
"components": [
"LoopVectorize"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
[
4052,
4058
],
[
4064,
4069
]
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
"LoopVectorizationCostModel::computeMaxVF"
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 1de3dc7d23dd6b856efad3a3a04f2396328726d7
Author: Florian Hahn <[email protected]>
Date: Tue Jan 14 22:07:38 2025 +0000
[LV] Bail out early if BTC+1 wraps.
Currently we fail to detect the case where BTC + 1 wraps, i.e. the
vector trip count is 0, In those cases, the minimum iteration count
check will fail, and the vector code will never be executed.
Explicitly check for this condition in computeMaxVF and avoid trying to
vectorize alltogether.
Note that a number of tests needed to be updated, because the vector
loop would never be executed given the input IR.
Fixes https://github.com/llvm/llvm-project/issues/122558.
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 744faef19243..fe2fb5e9faae 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -4052,7 +4052,8 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) {
return FixedScalableVFPair::getNone();
}
- unsigned TC = PSE.getSE()->getSmallConstantTripCount(TheLoop);
+ ScalarEvolution *SE = PSE.getSE();
+ unsigned TC = SE->getSmallConstantTripCount(TheLoop);
unsigned MaxTC = PSE.getSmallConstantMaxTripCount();
LLVM_DEBUG(dbgs() << "LV: Found trip count: " << TC << '\n');
if (TC != MaxTC)
@@ -4064,6 +4065,22 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) {
return FixedScalableVFPair::getNone();
}
+ // If BTC matches the widest induction type and is -1 then the trip count
+ // computation will wrap to 0 and the vector trip count will be 0. Do not try
+ // to vectorize.
+ const SCEV *BTC = SE->getBackedgeTakenCount(TheLoop);
+ if (!isa<SCEVCouldNotCompute>(BTC) &&
+ BTC->getType()->getScalarSizeInBits() >=
+ Legal->getWidestInductionType()->getScalarSizeInBits() &&
+ SE->isKnownPredicate(CmpInst::ICMP_EQ, BTC,
+ SE->getMinusOne(BTC->getType()))) {
+ reportVectorizationFailure(
+ "Trip count computation wrapped",
+ "backedge-taken count is -1, loop trip count wrapped to 0",
+ "TripCountWrapped", ORE, TheLoop);
+ return FixedScalableVFPair::getNone();
+ }
+
switch (ScalarEpilogueStatus) {
case CM_ScalarEpilogueAllowed:
return computeFeasibleMaxVF(MaxTC, UserVF, false);
| [
{
"file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product-epilogue.ll",
"commands": [
"opt -mattr=+dotprod -passes=loop-vectorize -force-vector-interleave=1 -S < %s"
],
"tests": [
{
"test_name": "dotp",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product-mixed.ll",
"commands": [
"opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+i8mm,+dotprod -S < %s",
"opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+dotprod -S < %s"
],
"tests": [
{
"test_name": "dotp_z_s",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp_z_s(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "dotp_s_z",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp_s_z(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product-neon.ll",
"commands": [
"opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+neon,+dotprod -force-vector-interleave=1 -S < %s",
"opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+neon,+dotprod -S < %s",
"opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+neon,+dotprod -force-vector-interleave=1 -vectorizer-maximize-bandwidth -S < %s"
],
"tests": [
{
"test_name": "dotp_unrolled",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @dotp_unrolled(i32 %num_out, i64 %num_in, ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum3 = phi i32 [ 0, %entry ], [ %add.a3, %for.body ]\n %accum2 = phi i32 [ 0, %entry ], [ %add.a2, %for.body ]\n %accum1 = phi i32 [ 0, %entry ], [ %add.a1, %for.body ]\n %accum0 = phi i32 [ 0, %entry ], [ %add.a0, %for.body ]\n %gep.a0 = getelementptr inbounds i8, ptr %a, i64 %iv\n %gep.b0 = getelementptr inbounds i8, ptr %b, i64 %iv\n %offset.1 = or disjoint i64 %iv, 1\n %gep.a1 = getelementptr inbounds i8, ptr %a, i64 %offset.1\n %gep.b1 = getelementptr inbounds i8, ptr %b, i64 %offset.1\n %offset.2 = or disjoint i64 %iv, 2\n %gep.a2 = getelementptr inbounds i8, ptr %a, i64 %offset.2\n %gep.b2 = getelementptr inbounds i8, ptr %b, i64 %offset.2\n %offset.3 = or disjoint i64 %iv, 3\n %gep.a3 = getelementptr inbounds i8, ptr %a, i64 %offset.3\n %gep.b3 = getelementptr inbounds i8, ptr %b, i64 %offset.3\n %load.a0 = load i8, ptr %gep.a0, align 1\n %ext.a0 = sext i8 %load.a0 to i32\n %load.b0 = load i8, ptr %gep.b0, align 1\n %ext.b0 = sext i8 %load.b0 to i32\n %mul.a0 = mul nsw i32 %ext.b0, %ext.a0\n %add.a0 = add nsw i32 %mul.a0, %accum0\n %load.a1 = load i8, ptr %gep.a1, align 1\n %ext.a1 = sext i8 %load.a1 to i32\n %load.b1 = load i8, ptr %gep.b1, align 1\n %ext.b1 = sext i8 %load.b1 to i32\n %mul.a1 = mul nsw i32 %ext.a1, %ext.b1\n %add.a1 = add nsw i32 %mul.a1, %accum1\n %load.a2 = load i8, ptr %gep.a2, align 1\n %ext.a2 = sext i8 %load.a2 to i32\n %load.b2 = load i8, ptr %gep.b2, align 1\n %ext.b2 = sext i8 %load.b2 to i32\n %mul.a2 = mul nsw i32 %ext.a2, %ext.b2\n %add.a2 = add nsw i32 %mul.a2, %accum2\n %load.a3 = load i8, ptr %gep.a3, align 1\n %ext.a3 = sext i8 %load.a3 to i32\n %load.b3 = load i8, ptr %gep.b3, align 1\n %ext.b3 = sext i8 %load.b3 to i32\n %mul.a3 = mul nsw i32 %ext.a3, %ext.b3\n %add.a3 = add nsw i32 %mul.a3, %accum3\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %num_in\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n %result0 = add nsw i32 %add.a0, %add.a1\n %result1 = add nsw i32 %add.a2, %add.a3\n %result = add nsw i32 %result0, %result1\n ret i32 %result\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "dotp",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @dotp(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "not_dotp_predicated_pragma",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_predicated_pragma(i64 %N, ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds i8, ptr %b, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.a2 = getelementptr inbounds i8, ptr %a, i64 %iv\n %load.b = load i8, ptr %gep.a2, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul nsw i32 %ext.b, %ext.a\n %add = add nsw i32 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %N\n br i1 %exitcond.not, label %exit, label %for.body, !llvm.loop !0\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n\n!0 = distinct !{!0, !1, !2, !3}\n!1 = !{!\"llvm.loop.mustprogress\"}\n!2 = !{!\"llvm.loop.vectorize.predicate.enable\", i1 true}\n!3 = !{!\"llvm.loop.vectorize.enable\", i1 true}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "not_dotp_not_loop_carried",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_not_loop_carried(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %mul, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "not_dotp_different_types",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_different_types(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i16, ptr %gep.b, align 2\n %ext.b = zext i16 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "not_dotp_not_phi",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_not_phi(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %ext.b\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "not_dotp_extend_user",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_extend_user(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n %result = add i32 %add, %ext.b\n ret i32 %result\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "not_dotp_predicated",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp_predicated(i64 %N, ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.b = getelementptr inbounds i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul nsw i32 %ext.b, %ext.a\n %add = add nsw i32 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %N\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-dot-product.ll",
"commands": [
"opt -passes=loop-vectorize -force-vector-interleave=1 -enable-epilogue-vectorization=false -S < %s",
"opt -passes=loop-vectorize -enable-epilogue-vectorization=false -S < %s",
"opt -passes=loop-vectorize -force-vector-interleave=1 -vectorizer-maximize-bandwidth -enable-epilogue-vectorization=false -S < %s"
],
"tests": [
{
"test_name": "not_dotp_not_phi2",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine void @not_dotp_not_phi2(ptr %matrix, i32 %n) #0 {\nentry:\n %cmp = icmp sgt i32 %n, 0\n br i1 %cmp, label %for.preheader, label %exit\n\nfor.preheader: ; preds = %entry\n %load.a = load i8, ptr null, align 1\n %load.a1 = load i8, ptr inttoptr (i64 1 to ptr), align 1\n %a.ext = sext i8 %load.a to i32\n %a.ext1 = sext i8 %load.a1 to i32\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.preheader\n %iv = phi i32 [ %iv.next, %for.body ], [ 0, %for.preheader ]\n %ptr = phi ptr [ %scevgep, %for.body ], [ %matrix, %for.preheader ]\n %accum = phi i32 [ %add.1, %for.body ], [ 0, %for.preheader ]\n %gep.b = getelementptr i8, ptr %ptr, i64 1\n %gep.b1 = getelementptr i8, ptr %ptr, i64 2\n %load.b = load i8, ptr %gep.b, align 1\n %b.ext = sext i8 %load.b to i32\n %mul = mul nsw i32 %a.ext, %b.ext\n %add = add i32 %mul, %accum\n %load.b1 = load i8, ptr %gep.b1, align 1\n %b.ext1 = sext i8 %load.b1 to i32\n %mul.1 = mul nsw i32 %a.ext1, %b.ext1\n %add.1 = add i32 %mul.1, %add\n %scevgep = getelementptr i8, ptr %ptr, i64 16\n %iv.next = add nuw nsw i32 %iv, 1\n %exitcond.not = icmp eq i32 %iv.next, %n\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n %add.1.lcssa = phi i32 [ %add.1, %for.body ]\n %add.float = sitofp i32 %add.1.lcssa to float\n br label %exit\n\nexit: ; preds = %for.exit, %entry\n %result = phi float [ 0.000000e+00, %entry ], [ %add.float, %for.exit ]\n store float %result, ptr %matrix, align 4\n ret void\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "not_dotp_ext_outside_plan2",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i64 @not_dotp_ext_outside_plan2(ptr %a, i16 %b, i64 %n) #0 {\nentry:\n %cmp = icmp eq i64 %n, 0\n br i1 %cmp, label %exit, label %for.ph\n\nfor.ph: ; preds = %entry\n %ext.b = zext i16 %b to i64\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.ph\n %iv = phi i64 [ 0, %for.ph ], [ %iv.next, %for.body ]\n %accum = phi i64 [ 0, %for.ph ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds nuw i16, ptr %a, i64 %iv\n %load.a = load i16, ptr %gep.a, align 2\n %ext.a = zext i16 %load.a to i64\n %mul = mul nuw nsw i64 %ext.b, %ext.a\n %add = add i64 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %cmp.1 = icmp eq i64 %iv.next, %n\n br i1 %cmp.1, label %exit, label %for.body\n\nexit: ; preds = %for.body, %entry\n %result = phi i64 [ 0, %entry ], [ %add, %for.body ]\n ret i64 %result\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "dotp_unrolled",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp_unrolled(i32 %num_out, i64 %num_in, ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum3 = phi i32 [ 0, %entry ], [ %add.a3, %for.body ]\n %accum2 = phi i32 [ 0, %entry ], [ %add.a2, %for.body ]\n %accum1 = phi i32 [ 0, %entry ], [ %add.a1, %for.body ]\n %accum0 = phi i32 [ 0, %entry ], [ %add.a0, %for.body ]\n %gep.a0 = getelementptr inbounds i8, ptr %a, i64 %iv\n %gep.b0 = getelementptr inbounds i8, ptr %b, i64 %iv\n %offset.1 = or disjoint i64 %iv, 1\n %gep.a1 = getelementptr inbounds i8, ptr %a, i64 %offset.1\n %gep.b1 = getelementptr inbounds i8, ptr %b, i64 %offset.1\n %offset.2 = or disjoint i64 %iv, 2\n %gep.a2 = getelementptr inbounds i8, ptr %a, i64 %offset.2\n %gep.b2 = getelementptr inbounds i8, ptr %b, i64 %offset.2\n %offset.3 = or disjoint i64 %iv, 3\n %gep.a3 = getelementptr inbounds i8, ptr %a, i64 %offset.3\n %gep.b3 = getelementptr inbounds i8, ptr %b, i64 %offset.3\n %load.a0 = load i8, ptr %gep.a0, align 1\n %ext.a0 = sext i8 %load.a0 to i32\n %load.b0 = load i8, ptr %gep.b0, align 1\n %ext.b0 = sext i8 %load.b0 to i32\n %mul.a0 = mul nsw i32 %ext.b0, %ext.a0\n %add.a0 = add nsw i32 %mul.a0, %accum0\n %load.a1 = load i8, ptr %gep.a1, align 1\n %ext.a1 = sext i8 %load.a1 to i32\n %load.b1 = load i8, ptr %gep.b1, align 1\n %ext.b1 = sext i8 %load.b1 to i32\n %mul.a1 = mul nsw i32 %ext.a1, %ext.b1\n %add.a1 = add nsw i32 %mul.a1, %accum1\n %load.a2 = load i8, ptr %gep.a2, align 1\n %ext.a2 = sext i8 %load.a2 to i32\n %load.b2 = load i8, ptr %gep.b2, align 1\n %ext.b2 = sext i8 %load.b2 to i32\n %mul.a2 = mul nsw i32 %ext.a2, %ext.b2\n %add.a2 = add nsw i32 %mul.a2, %accum2\n %load.a3 = load i8, ptr %gep.a3, align 1\n %ext.a3 = sext i8 %load.a3 to i32\n %load.b3 = load i8, ptr %gep.b3, align 1\n %ext.b3 = sext i8 %load.b3 to i32\n %mul.a3 = mul nsw i32 %ext.a3, %ext.b3\n %add.a3 = add nsw i32 %mul.a3, %accum3\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %num_in\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n %result0 = add nsw i32 %add.a0, %add.a1\n %result1 = add nsw i32 %add.a2, %add.a3\n %result = add nsw i32 %result0, %result1\n ret i32 %result\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "dotp",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @dotp(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "not_dotp_predicated_pragma",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_predicated_pragma(i64 %N, ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds i8, ptr %b, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.a2 = getelementptr inbounds i8, ptr %a, i64 %iv\n %load.b = load i8, ptr %gep.a2, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul nsw i32 %ext.b, %ext.a\n %add = add nsw i32 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %N\n br i1 %exitcond.not, label %exit, label %for.body, !llvm.loop !0\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n\n!0 = distinct !{!0, !1, !2, !3}\n!1 = !{!\"llvm.loop.mustprogress\"}\n!2 = !{!\"llvm.loop.vectorize.predicate.enable\", i1 true}\n!3 = !{!\"llvm.loop.vectorize.enable\", i1 true}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "dotp_cost_disagreement",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i64 @dotp_cost_disagreement(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %i.iv = phi i64 [ 0, %entry ], [ %i.iv.next, %for.body ]\n %sum = phi i64 [ 0, %entry ], [ %add, %for.body ]\n %arrayidx = getelementptr inbounds nuw i8, ptr %a, i64 %i.iv\n %0 = load i8, ptr %arrayidx, align 1\n %conv = zext i8 %0 to i64\n %i.iv.next = add nuw nsw i64 %i.iv, 1\n %arrayidx2 = getelementptr inbounds nuw i8, ptr %b, i64 %i.iv.next\n %1 = load i8, ptr %arrayidx2, align 1\n %conv3 = zext i8 %1 to i64\n %mul = mul nuw nsw i64 %conv3, %conv\n %add = add i64 %sum, %mul\n %exitcond.not = icmp eq i64 %i.iv.next, 16\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n ret i64 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "not_dotp_not_loop_carried",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_not_loop_carried(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %mul, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "not_dotp_different_types",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_different_types(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i16, ptr %gep.b, align 2\n %ext.b = zext i16 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "not_dotp_not_phi",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_not_phi(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %ext.b\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "not_dotp_extend_user",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_extend_user(ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n %result = add i32 %add, %ext.b\n ret i32 %result\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "not_dotp_ext_outside_plan",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i64 @not_dotp_ext_outside_plan(ptr %a, i16 %b, i64 %n) #0 {\nentry:\n %cmp = icmp eq i64 %n, 0\n br i1 %cmp, label %exit, label %for.ph\n\nfor.ph: ; preds = %entry\n %ext.b = zext i16 %b to i64\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.ph\n %iv = phi i64 [ 0, %for.ph ], [ %iv.next, %for.body ]\n %accum = phi i64 [ 0, %for.ph ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds nuw i16, ptr %a, i64 %iv\n %load.a = load i16, ptr %gep.a, align 2\n %ext.a = zext i16 %load.a to i64\n %mul = mul nuw nsw i64 %ext.a, %ext.b\n %add = add i64 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %cmp.1 = icmp eq i64 %iv.next, %n\n br i1 %cmp.1, label %exit, label %for.body\n\nexit: ; preds = %for.body, %entry\n %result = phi i64 [ 0, %entry ], [ %add, %for.body ]\n ret i64 %result\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "not_dotp_predicated",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\n; Function Attrs: vscale_range(1,16)\ndefine i32 @not_dotp_predicated(i64 %N, ptr %a, ptr %b) #0 {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr inbounds i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = sext i8 %load.a to i32\n %gep.b = getelementptr inbounds i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = sext i8 %load.b to i32\n %mul = mul nsw i32 %ext.b, %ext.a\n %add = add nsw i32 %mul, %accum\n %iv.next = add nuw nsw i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, %N\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/AArch64/partial-reduce-no-dotprod.ll",
"commands": [
"opt -passes=loop-vectorize -enable-epilogue-vectorization=false -mattr=+neon -S < %s"
],
"tests": [
{
"test_name": "not_dotp",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @not_dotp(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1000\n br i1 %exitcond.not, label %for.exit, label %for.body\n\nfor.exit: ; preds = %for.body\n ret i32 %add\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/AArch64/store-costs-sve.ll",
"commands": [
"opt -p loop-vectorize -S %s",
"opt -p loop-vectorize -prefer-predicate-over-epilogue=predicate-else-scalar-epilogue -S %s"
],
"tests": [
{
"test_name": "trunc_store",
"test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"arm64-apple-macosx14.0.0\"\n\n; Function Attrs: vscale_range(1,16)\ndefine void @trunc_store(ptr %dst, ptr %src, i16 %x) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %x.ext = zext i16 %x to i64\n %l = load i64, ptr %src, align 8\n %and = and i64 %l, %x.ext\n %trunc = trunc i64 %and to i8\n %gep = getelementptr i8, ptr %dst, i64 %iv\n store i8 %trunc, ptr %gep, align 1\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1000\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { vscale_range(1,16) \"target-features\"=\"+sve\" }\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/AArch64/vplan-printing.ll",
"commands": [
"opt -mattr=+neon,+dotprod -passes=loop-vectorize -debug-only=loop-vectorize -force-vector-interleave=1 -disable-output %s 2>&1"
],
"tests": [
{
"test_name": "print_partial_reduction",
"test_body": "target datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-none-unknown-elf\"\n\ndefine i32 @print_partial_reduction(ptr %a, ptr %b) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]\n %accum = phi i32 [ 0, %entry ], [ %add, %for.body ]\n %gep.a = getelementptr i8, ptr %a, i64 %iv\n %load.a = load i8, ptr %gep.a, align 1\n %ext.a = zext i8 %load.a to i32\n %gep.b = getelementptr i8, ptr %b, i64 %iv\n %load.b = load i8, ptr %gep.b, align 1\n %ext.b = zext i8 %load.b to i32\n %mul = mul i32 %ext.b, %ext.a\n %add = add i32 %mul, %accum\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 1024\n br i1 %exitcond.not, label %exit, label %for.body\n\nexit: ; preds = %for.body\n ret i32 %add\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/Hexagon/maximum-vf-crash.ll",
"commands": [
"opt -mtriple=hexagon -hexagon-autohvx -passes=loop-vectorize -S < %s 2>&1"
],
"tests": [
{
"test_name": "f",
"test_body": "target datalayout = \"e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048\"\n\n; Function Attrs: optsize\ndefine i32 @f(ptr %src) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %g.016 = phi i32 [ 0, %entry ], [ %g.1.lcssa, %loop ]\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %0 = load i8, ptr %src, align 1\n %g.1.lcssa = add i32 %g.016, 1\n %iv.next = add nsw i32 %iv, 1\n %exitcond = icmp eq i32 %iv.next, 1000\n br i1 %exitcond, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 %g.1.lcssa\n}\n\nattributes #0 = { optsize \"target-features\"=\"+hvx-length128b\" }\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/X86/cost-constant-known-via-scev.ll",
"commands": [
"opt -p loop-vectorize -S %s"
],
"tests": [
{
"test_name": "second_lshr_operand_zero_via_scev",
"test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i64 @second_lshr_operand_zero_via_scev() {\nentry:\n %ext.0 = sext i8 0 to i32\n br label %loops\n\nloops: ; preds = %loops, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loops ]\n %red = phi i64 [ 0, %entry ], [ %red.next, %loops ]\n %c = icmp eq i64 %iv, 0\n %and = and i64 %iv, 0\n %0 = trunc i64 %iv to i32\n %shr = lshr i32 %0, %ext.0\n %conv.1 = zext i32 %shr to i64\n %red.next.v = select i1 %c, i64 %and, i64 %conv.1\n %red.next = or i64 %red.next.v, %red\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1000\n br i1 %ec, label %exit, label %loops\n\nexit: ; preds = %loops\n %res = phi i64 [ %red.next, %loops ]\n ret i64 %res\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/X86/cost-model.ll",
"commands": [
"opt < %s -passes=loop-vectorize -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx -S"
],
"tests": [
{
"test_name": "narrowed_reduction",
"test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine i32 @narrowed_reduction(ptr %a, i1 %cmp) #0 {\nentry:\n %conv = zext i1 %cmp to i32\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 1, %entry ], [ %inc, %loop ]\n %or13 = phi i32 [ 0, %entry ], [ %or, %loop ]\n %and = and i32 %or13, 1\n %or = or i32 %and, %conv\n %inc = add i32 %iv, 1\n %ec = icmp eq i32 %iv, 16\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 %or\n}\n\nattributes #0 = { \"target-cpu\"=\"penryn\" }\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/X86/drop-poison-generating-flags.ll",
"commands": [
"opt %s -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S"
],
"tests": [
{
"test_name": "drop_zext_nneg",
"test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-pc-linux-gnu\"\n\n; Function Attrs: noinline nounwind uwtable\ndefine void @drop_zext_nneg(ptr noalias %p, ptr noalias %p1) #0 {\nentry:\n br label %body\n\nbody: ; preds = %else, %entry\n %iv = phi i64 [ %next, %else ], [ 0, %entry ]\n %0 = trunc i64 %iv to i32\n %c = icmp eq i32 %0, 0\n br i1 %c, label %then, label %else\n\nthen: ; preds = %body\n %zext = zext nneg i32 %0 to i64\n %idx1 = getelementptr double, ptr %p, i64 %zext\n %idx2 = getelementptr double, ptr %p, i64 %zext\n %1 = load double, ptr %idx2, align 8\n br label %else\n\nelse: ; preds = %then, %body\n %phi = phi double [ %1, %then ], [ 0.000000e+00, %body ]\n store double %phi, ptr %p1, align 8\n %next = add i64 %iv, 1\n %cmp = icmp eq i64 %next, 1024\n br i1 %cmp, label %exit, label %body\n\nexit: ; preds = %else\n ret void\n}\n\nattributes #0 = { noinline nounwind uwtable \"target-features\"=\"+avx512bw,+avx512cd,+avx512dq,+avx512f,+avx512vl\" }\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/X86/interleave-cost.ll",
"commands": [
"opt -p loop-vectorize -S %s"
],
"tests": [
{
"test_name": "test_free_instructions_feeding_geps_for_interleave_groups",
"test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.15.0\"\n\ndefine void @test_free_instructions_feeding_geps_for_interleave_groups(ptr noalias %p.invar, ptr noalias %dst.1, ptr noalias %dst.2) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %l.0 = load float, ptr %p.invar, align 4\n %iv.mul = shl i64 %iv, 2\n %gep.dst.19 = getelementptr float, ptr %dst.1, i64 %iv.mul\n store float %l.0, ptr %gep.dst.19, align 4\n %l.1 = load float, ptr %p.invar, align 4\n %add.1 = or disjoint i64 %iv.mul, 1\n %gep.dst.119 = getelementptr float, ptr %dst.1, i64 %add.1\n store float %l.1, ptr %gep.dst.119, align 4\n %add.2 = or disjoint i64 %iv.mul, 2\n %gep.dst.129 = getelementptr float, ptr %dst.1, i64 %add.2\n store float 0.000000e+00, ptr %gep.dst.129, align 4\n %add.3 = or disjoint i64 %iv.mul, 3\n %gep.dst.140 = getelementptr float, ptr %dst.1, i64 %add.3\n store float 0.000000e+00, ptr %gep.dst.140, align 4\n %l.2 = load float, ptr %p.invar, align 4\n %gep.dst.247 = getelementptr float, ptr %dst.2, i64 %iv.mul\n store float %l.2, ptr %gep.dst.247, align 4\n %gep.dst.255 = getelementptr float, ptr %dst.2, i64 %add.1\n store float 0.000000e+00, ptr %gep.dst.255, align 4\n %gep.dst.265 = getelementptr float, ptr %dst.2, i64 %add.2\n store float 0.000000e+00, ptr %gep.dst.265, align 4\n %gep.dst.276 = getelementptr float, ptr %dst.2, i64 %add.3\n store float 0.000000e+00, ptr %gep.dst.276, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1024\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/X86/replicate-uniform-call.ll",
"commands": [
"opt -p loop-vectorize -S %s"
],
"tests": [
{
"test_name": "smax_call_uniform",
"test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @smax_call_uniform(ptr %dst, i64 %x) {\nentry:\n %c = icmp ult i8 -68, -69\n %mul = mul nuw nsw i64 %x, 0\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 %c, label %loop.latch, label %else\n\nelse: ; preds = %loop.header\n %rem = urem i64 %mul, %x\n %smax = tail call i64 @llvm.smax.i64(i64 %rem, i64 0)\n br label %loop.latch\n\nloop.latch: ; preds = %else, %loop.header\n %p = phi i64 [ 1, %loop.header ], [ %smax, %else ]\n %add = add i64 %p, 1\n %gep = getelementptr i64, ptr %dst, i64 %add\n store i64 0, ptr %gep, align 8\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1024\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i64 @llvm.smax.i64(i64, i64) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/epilog-vectorization-vector-trip-count-zero.ll",
"commands": [
"opt -p loop-vectorize -force-vector-width=2 -epilogue-vectorization-force-VF=2 -S %s"
],
"tests": [
{
"test_name": "vector_trip_count_0_as_btc_is_all_1",
"test_body": "target datalayout = \"E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64\"\n\ndefine void @vector_trip_count_0_as_btc_is_all_1(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.next = add i32 %iv, -1\n %gep = getelementptr inbounds i32, ptr %dst, i32 %iv\n store i32 %iv.next, ptr %gep, align 4\n %ec = icmp eq i32 %iv.next, 0\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/first-order-recurrence-chains.ll",
"commands": [
"opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s"
],
"tests": [
{
"test_name": "test_resinking_required",
"test_body": "define double @test_resinking_required(ptr %p, ptr noalias %a, ptr noalias %b) {\nEntry:\n br label %Loop\n\nLoop: ; preds = %Loop, %Entry\n %for.1 = phi double [ %l1, %Loop ], [ 0.000000e+00, %Entry ]\n %for.2 = phi double [ %l2, %Loop ], [ 0.000000e+00, %Entry ]\n %for.3 = phi double [ %for.2, %Loop ], [ 0.000000e+00, %Entry ]\n %iv = phi i64 [ %iv.next, %Loop ], [ 0, %Entry ]\n %USE_2_FORS = fdiv double %for.3, %for.1\n %div = fdiv double 0.000000e+00, %for.1\n %l1 = load double, ptr %a, align 8\n %iv.next = add nuw nsw i64 %iv, 1\n %l2 = load double, ptr %b, align 8\n store double %div, ptr %p, align 8\n %cond = icmp eq i64 %iv.next, 1000\n br i1 %cond, label %End, label %Loop\n\nEnd: ; preds = %Loop\n %res.1 = fadd double %for.1, %for.2\n %res.2 = fadd double %res.1, %for.3\n ret double %res.2\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/if-pred-stores.ll",
"commands": [
"opt -S -vectorize-num-stores-pred=1 -force-vector-width=1 -force-vector-interleave=2 -passes=loop-vectorize,simplifycfg -verify-loop-info -simplifycfg-require-and-preserve-domtree=1 < %s",
"opt -S -vectorize-num-stores-pred=1 -force-vector-width=1 -force-vector-interleave=2 -passes=loop-vectorize -verify-loop-info < %s",
"opt -S -vectorize-num-stores-pred=1 -force-vector-width=2 -force-vector-interleave=1 -passes=loop-vectorize,simplifycfg -verify-loop-info -simplifycfg-require-and-preserve-domtree=1 < %s"
],
"tests": [
{
"test_name": "minimal_bit_widths_with_aliasing_store",
"test_body": "target datalayout = \"e-m:o-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @minimal_bit_widths_with_aliasing_store(i1 %c, ptr %ptr) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.inc, %entry\n %tmp0 = phi i64 [ %tmp6, %for.inc ], [ 0, %entry ]\n %tmp1 = phi i64 [ %tmp7, %for.inc ], [ 1000, %entry ]\n %tmp2 = getelementptr i8, ptr %ptr, i64 %tmp0\n %tmp3 = load i8, ptr %tmp2, align 1\n store i8 0, ptr %tmp2, align 1\n br i1 %c, label %if.then, label %for.inc\n\nif.then: ; preds = %for.body\n %tmp4 = zext i8 %tmp3 to i32\n %tmp5 = trunc i32 %tmp4 to i8\n store i8 %tmp5, ptr %tmp2, align 1\n br label %for.inc\n\nfor.inc: ; preds = %if.then, %for.body\n %tmp6 = add nuw nsw i64 %tmp0, 1\n %tmp7 = add i64 %tmp1, -1\n %tmp8 = icmp eq i64 %tmp7, 0\n br i1 %tmp8, label %for.end, label %for.body\n\nfor.end: ; preds = %for.inc\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/induction.ll",
"commands": [
"opt < %s -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S",
"opt < %s -passes=loop-vectorize,instcombine -force-vector-interleave=1 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S",
"opt < %s -passes=loop-vectorize,instcombine -force-vector-interleave=2 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S",
"opt < %s -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S",
"opt < %s -passes=loop-vectorize,instcombine -force-vector-interleave=2 -force-vector-width=4 -force-widen-divrem-via-safe-divisor=0 -enable-interleaved-mem-accesses -S"
],
"tests": [
{
"test_name": "max_i32_backedgetaken",
"test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine i32 @max_i32_backedgetaken() {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %a.0 = phi i32 [ 1, %entry ], [ %a.0.and, %loop ]\n %b.0 = phi i32 [ 0, %entry ], [ %b.next, %loop ]\n %a.0.and = and i32 %a.0, 4\n %b.next = add i32 %b.0, -1\n %ec = icmp eq i32 %b.next, 0\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 %a.0.and\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/interleave-and-scalarize-only.ll",
"commands": [
"opt -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 -debug -disable-output %s 2>&1",
"opt -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 -S %s"
],
"tests": [
{
"test_name": "scalarize_ptrtoint",
"test_body": "define void @scalarize_ptrtoint(ptr %src, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr ptr, ptr %src, i64 %iv\n %l = load ptr, ptr %gep, align 8\n %cast = ptrtoint ptr %l to i64\n %add = add i64 %cast, 10\n %cast.2 = inttoptr i64 %add to ptr\n store ptr %cast.2, ptr %dst, align 8\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 1024\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/is_fpclass.ll",
"commands": [
"opt < %s -passes=loop-vectorize -force-vector-width=2 -S"
],
"tests": [
{
"test_name": "d",
"test_body": "define void @d() {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %i = phi i64 [ 0, %entry ], [ %i7, %loop ]\n %i3 = load float, ptr null, align 4\n %i4 = getelementptr float, ptr @d, i64 %i\n %i5 = tail call i1 @llvm.is.fpclass.f32(float %i3, i32 0)\n %i6 = select i1 %i5, float 0.000000e+00, float 0.000000e+00\n store float %i6, ptr %i4, align 4\n %i7 = add i64 %i, 1\n %i8 = icmp eq i64 %i7, 128\n br i1 %i8, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i1 @llvm.is.fpclass.f32(float, i32 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/optimal-epilog-vectorization.ll",
"commands": [
"opt -passes='loop-vectorize' -force-vector-width=4 -enable-epilogue-vectorization -epilogue-vectorization-force-VF=4 -S %s",
"opt -passes='loop-vectorize' -enable-epilogue-vectorization -epilogue-vectorization-force-VF=2 -S %s"
],
"tests": [
{
"test_name": "multiple_ivs_wide",
"test_body": "target datalayout = \"e-m:e-i64:64-n32:64-v128:128:128\"\n\ndefine void @multiple_ivs_wide(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.2 = phi i32 [ -64, %entry ], [ %iv.2.next, %loop ]\n %iv.next = add i32 %iv, 2\n %iv.2.next = add i32 %iv.2, 2\n %gep = getelementptr inbounds i32, ptr %dst, i32 %iv\n store i32 %iv.2.next, ptr %gep, align 4\n %ec = icmp eq i32 %iv.next, 128\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/runtime-checks-hoist.ll",
"commands": [
"opt < %s -passes='loop-vectorize' -force-vector-interleave=1 -S -force-vector-width=4 -debug-only=loop-accesses,loop-vectorize,loop-utils"
],
"tests": [
{
"test_name": "stride_check_known_via_loop_guard",
"test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\n\ndefine void @stride_check_known_via_loop_guard(ptr %C, ptr %A, i32 %Acols) {\nentry:\n %pre.c = icmp ugt i32 %Acols, 0\n br i1 %pre.c, label %exit, label %outer.header\n\nouter.header: ; preds = %outer.latch, %entry\n %outer.iv = phi i32 [ 0, %entry ], [ %outer.iv.next, %outer.latch ]\n %mul.us = mul i32 %outer.iv, %Acols\n %arrayidx.us = getelementptr double, ptr %A, i32 %mul.us\n br label %inner\n\ninner: ; preds = %inner, %outer.header\n %inner.iv = phi i32 [ 0, %outer.header ], [ %inner.iv.next, %inner ]\n %gep.C = getelementptr inbounds double, ptr %C, i32 %inner.iv\n %l = load double, ptr %arrayidx.us, align 8\n store double %l, ptr %gep.C, align 8\n %inner.iv.next = add i32 %inner.iv, 1\n %inner.c = icmp eq i32 %inner.iv.next, 1000\n br i1 %inner.c, label %outer.latch, label %inner\n\nouter.latch: ; preds = %inner\n %outer.iv.next = add i32 %outer.iv, 1\n %outer.c = icmp ult i32 %outer.iv, 128\n br i1 %outer.c, label %exit, label %outer.header\n\nexit: ; preds = %outer.latch, %entry\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/scev-predicate-reasoning.ll",
"commands": [
"opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -lv-strided-pointer-ivs=true -S %s"
],
"tests": [
{
"test_name": "step_direction_unknown",
"test_body": "define void @step_direction_unknown(i32 %arg, ptr %dst) {\nentry:\n %add = add i32 %arg, 1\n br label %loop\n\nloop: ; preds = %loop, %entry\n %phi = phi i64 [ 0, %entry ], [ %add2, %loop ]\n %trunc = trunc i64 %phi to i32\n %mul = mul i32 %add, %trunc\n %zext = zext i32 %mul to i64\n %getelementptr = getelementptr double, ptr %dst, i64 %zext\n store double 0.000000e+00, ptr %getelementptr, align 8\n %add2 = add i64 %phi, 1\n %icmp = icmp eq i64 %add2, 1024\n br i1 %icmp, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "integer_induction_wraps_scev_predicate_known",
"test_body": "define void @integer_induction_wraps_scev_predicate_known(i32 %x, ptr %call, ptr %start) {\nentry:\n %mul = shl i32 %x, 1\n br label %for.cond\n\nfor.cond: ; preds = %for.cond, %entry\n %iv = phi i32 [ 30, %entry ], [ %inc, %for.cond ]\n %p.0 = phi ptr [ %start, %entry ], [ %add.ptr, %for.cond ]\n %add.ptr = getelementptr i8, ptr %p.0, i32 %mul\n %arrayidx = getelementptr ptr, ptr %call, i32 %iv\n store ptr %p.0, ptr %arrayidx, align 4\n %inc = add i32 %iv, 1\n %tobool.not = icmp eq i32 %iv, 1024\n br i1 %tobool.not, label %for.end, label %for.cond\n\nfor.end: ; preds = %for.cond\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/vplan-sink-scalars-and-merge-vf1.ll",
"commands": [
"opt -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=1 -debug -disable-output %s 2>&1"
],
"tests": [
{
"test_name": "sink_with_sideeffects",
"test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @sink_with_sideeffects(i1 %c, ptr %ptr) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.inc, %entry\n %tmp0 = phi i64 [ %tmp6, %for.inc ], [ 0, %entry ]\n %tmp1 = phi i64 [ %tmp7, %for.inc ], [ 1024, %entry ]\n %tmp2 = getelementptr i8, ptr %ptr, i64 %tmp0\n %tmp3 = load i8, ptr %tmp2, align 1\n store i8 0, ptr %tmp2, align 1\n %tmp4 = zext i8 %tmp3 to i32\n %tmp5 = trunc i32 %tmp4 to i8\n br i1 %c, label %if.then, label %for.inc\n\nif.then: ; preds = %for.body\n store i8 %tmp5, ptr %tmp2, align 1\n br label %for.inc\n\nfor.inc: ; preds = %if.then, %for.body\n %tmp6 = add nuw nsw i64 %tmp0, 1\n %tmp7 = add i64 %tmp1, -1\n %tmp8 = icmp eq i64 %tmp7, 0\n br i1 %tmp8, label %for.end, label %for.body\n\nfor.end: ; preds = %for.inc\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[LoopVectorizer] Assertion `EPResumeVal && \"must have a resume value for the canonical IV\"' failed.",
"body": "clang -Wno-incompatible-pointer-types -O3 -march=z13 -S -c crash19.i -o a.out -w -mllvm -disable-licm-promotion -mllvm -epilogue-vectorization-force-VF=2 \n\n[crash19.tar.gz](https://github.com/user-attachments/files/18383534/crash19.tar.gz)\n\n#9 0x000002aa3ff5e440 preparePlanForEpilogueVectorLoop\n#12 0x000002aa3ffa098a llvm::LoopVectorizePass::run\n\n@bmahjour \n@fhahn ",
"author": "JonPsson1",
"labels": [
"vectorizers",
"crash"
],
"comments": [
{
"author": "fhahn",
"body": "@JonPsson1 Was the test case fuzzer generated? Just curious, because it had a loop with unsigned max as iteration count."
},
{
"author": "JonPsson1",
"body": "> [@JonPsson1](https://github.com/JonPsson1) Was the test case fuzzer generated? Just curious, because it had a loop with unsigned max as iteration count.\n\nNo, it was a CSmith test case."
},
{
"author": "fhahn",
"body": "@JonPsson1 Could you check if it fixes the full reproducer? If not, it would be great if you could share the full reproducer?"
}
]
} | true | null |
109333 | https://github.com/llvm/llvm-project/issues/109333 | crash | c498af71d73e96e95730f3b3caaea08d3edbe62c | 2024-09-19T20:50:34 | [
"llvm/test/Transforms/LoopUnroll"
] | {
"fix_commit": "5bcc82d43388bb0daa122d5fe7ecda5eca27fc16",
"components": [
"LoopPeel"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": [
[
859,
865
]
],
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": [
"cloneLoopBlocks"
],
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 5bcc82d43388bb0daa122d5fe7ecda5eca27fc16
Author: Nikita Popov <[email protected]>
Date: Fri Sep 20 16:57:46 2024 +0200
[LoopPeel] Fix LCSSA phi node invalidation
In the test case, the BECount of the second loop uses %load,
but we only have an LCSSA phi node for %add, so that is what
gets invalidated. Use the forgetLcssaPhiWithNewPredecessor()
API instead, which will invalidate the roots of the expression
instead.
Fixes https://github.com/llvm/llvm-project/issues/109333.
diff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp
index 5d7c0d947fac..760f1619e030 100644
--- a/llvm/lib/Transforms/Utils/LoopPeel.cpp
+++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp
@@ -859,7 +859,7 @@ static void cloneLoopBlocks(
if (LatchInst && L->contains(LatchInst))
LatchVal = VMap[LatchVal];
PHI.addIncoming(LatchVal, cast<BasicBlock>(VMap[Edge.first]));
- SE.forgetValue(&PHI);
+ SE.forgetLcssaPhiWithNewPredecessor(L, &PHI);
}
// LastValueMap is updated with the values for the current loop
| [
{
"file": "llvm/test/Transforms/LoopUnroll/pr109333.ll",
"commands": [
"opt -S -passes=\"print<scalar-evolution>,loop-unroll\" -unroll-runtime < %s 2>&1"
],
"tests": [
{
"test_name": "test",
"test_body": "define void @test(i1 %c, ptr %p) {\nentry:\n br label %loop.1\n\nloop.1: ; preds = %loop.1, %entry\n %phi = phi ptr [ null, %entry ], [ %p, %loop.1 ]\n %load = load i64, ptr %p, align 8\n %add = add i64 %load, 1\n br i1 %c, label %if, label %loop.1\n\nif: ; preds = %loop.1\n %add.lcssa = phi i64 [ %add, %loop.1 ]\n %gep = getelementptr i64, ptr %p, i64 %add.lcssa\n br label %loop.2\n\nloop.2: ; preds = %loop.2, %if\n %iv = phi ptr [ %p, %if ], [ %iv.next, %loop.2 ]\n %iv.next = getelementptr i8, ptr %iv, i64 8\n %icmp = icmp eq ptr %iv, %gep\n br i1 %icmp, label %exit, label %loop.2\n\nexit: ; preds = %loop.2\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "LTO error: Instruction does not dominate all uses",
"body": "clang crashes while linking\r\n```\r\nclang: error: unable to execute command: Aborted (core dumped)\r\nclang: error: linker command failed due to signal (use -v to see invocation)\r\n```\r\nI followed the instructions [here](https://llvm.org/docs/HowToSubmitABug.html) and narrowed it down to an LTO bug. File to reproduce is attached. [a.out.0.2.internalize-reduced.bc.tar.gz](https://github.com/user-attachments/files/17066318/a.out.0.2.internalize-reduced.bc.tar.gz)\r\n```\r\n$ opt \"-passes=lto<O3>\" a.out.0.2.internalize-reduced.bc\r\nWARNING: You're attempting to print out a bitcode file.\r\nThis is inadvisable as it may cause display problems. If\r\nyou REALLY want to taste LLVM bitcode first-hand, you\r\ncan force output with the `-f' option.\r\n\r\nInstruction does not dominate all uses!\r\n %.lcssa16 = phi i64 [ %12, %9 ]\r\n %27 = add i64 %.lcssa16, 2\r\nLLVM ERROR: Broken module found, compilation aborted!\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: opt -passes=lto<O3> reduced-redacted.bc #0 0x00007e899efc4d90 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /usr/src/debug/llvm/llvm-18.1.8.src/lib/Support/Unix/Signals.inc:723:22\r\n #1 0x00007e899efc1d4d llvm::sys::RunSignalHandlers() /usr/src/debug/llvm/llvm-18.1.8.src/lib/Support/Signals.cpp:105:20\r\n #2 0x00007e899efc1d4d SignalHandler /usr/src/debug/llvm/llvm-18.1.8.src/lib/Support/Unix/Signals.inc:403:31\r\n #3 0x00007e899e24c1d0 (/usr/lib/libc.so.6+0x3d1d0)\r\n #4 0x00007e899e2a53f4 __pthread_kill_implementation /usr/src/debug/glibc/glibc/nptl/pthread_kill.c:44:76\r\n #5 0x00007e899e24c120 raise /usr/src/debug/glibc/glibc/signal/../sysdeps/posix/raise.c:27:6\r\n #6 0x00007e899e2334c3 abort /usr/src/debug/glibc/glibc/stdlib/abort.c:81:7\r\n #7 0x00007e899ecaba1b std::mutex::lock() /usr/include/c++/14.1.1/bits/std_mutex.h:117:22\r\n #8 0x00007e899ecaba1b std::lock_guard<std::mutex>::lock_guard(std::mutex&) /usr/include/c++/14.1.1/bits/std_mutex.h:250:23\r\n #9 0x00007e899ecaba1b llvm::install_bad_alloc_error_handler(void (*)(void*, char const*, bool), void*) /usr/src/debug/llvm/llvm-18.1.8.src/lib/Support/ErrorHandling.cpp:131:61\r\n#10 0x00007e899eec070e (/usr/lib/libLLVM.so.18.1+0x6c070e)\r\n#11 0x00007e899f21aa1b (/usr/lib/libLLVM.so.18.1+0xa1aa1b)\r\n#12 0x000055a86e4acf57 llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm:\r\n:Module>&) /usr/src/debug/llvm/llvm-18.1.8.src/include/llvm/IR/PassManagerInternal.h:90:3\r\n#13 0x00007e899f1d767e llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /usr/src/debug/llvm/llvm-18.1.8.src/incl\r\nude/llvm/IR/PassManager.h:547:20\r\n#14 0x000055a86e4b7052 llvm::SmallPtrSetImplBase::isSmall() const /usr/src/debug/llvm/llvm-18.1.8.src/include/llvm/ADT/SmallPtrSet.h:195:33\r\n#15 0x000055a86e4b7052 llvm::SmallPtrSetImplBase::~SmallPtrSetImplBase() /usr/src/debug/llvm/llvm-18.1.8.src/include/llvm/ADT/SmallPtrSet.h:83:17\r\n#16 0x000055a86e4b7052 llvm::SmallPtrSetImpl<llvm::AnalysisKey*>::~SmallPtrSetImpl() /usr/src/debug/llvm/llvm-18.1.8.src/include/llvm/ADT/SmallPtrSet.h:345:7\r\n#17 0x000055a86e4b7052 llvm::SmallPtrSet<llvm::AnalysisKey*, 2u>::~SmallPtrSet() /usr/src/debug/llvm/llvm-18.1.8.src/include/llvm/ADT/SmallPtrSet.h:451:7\r\n#18 0x000055a86e4b7052 llvm::PreservedAnalyses::~PreservedAnalyses() /usr/src/debug/llvm/llvm-18.1.8.src/include/llvm/IR/PassManager.h:172:7\r\n#19 0x000055a86e4b7052 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutpu\r\ntFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) /usr/src/debug/llvm/llvm-18.1.8\r\n.src/tools/opt/NewPMDriver.cpp:527:10\r\n#20 0x000055a86e4ab1ed std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::~basic_string() /usr/include/c++/14.1.1/bits/basic_string.h:809:19\r\n#21 0x000055a86e4ab1ed main /usr/src/debug/llvm/llvm-18.1.8.src/tools/opt/opt.cpp:747:3\r\n#22 0x00007e899e234e08 __libc_start_call_main /usr/src/debug/glibc/glibc/csu/../sysdeps/nptl/libc_start_call_main.h:74:3\r\n#23 0x00007e899e234ecc call_init /usr/src/debug/glibc/glibc/csu/../csu/libc-start.c:128:20\r\n#24 0x00007e899e234ecc __libc_start_main /usr/src/debug/glibc/glibc/csu/../csu/libc-start.c:347:5\r\n#25 0x000055a86e4abfd5 _start (/usr/bin/opt+0x1cfd5)\r\nAborted (core dumped)\r\n```\r\nThis happened after adding `-fsplit-lto-unit` to some parts of my code base.\r\n",
"author": "googlebleh",
"labels": [
"loopoptim",
"release:backport",
"llvm:crash"
],
"comments": [
{
"author": "googlebleh",
"body": "While bisecting using this reduced test case, I was able to reproduce this crash on several versions of LLVM between 15 and 18.1.8. I was also able to reproduce on the tip of `main` (e439fdf4ea0dbc6f001428f4d4956700bf26bb97). However, this crash did not reproduce on 15.0.7. The commit on 15.0.7 that \"fixed\" the issue is\r\n```\r\ncommit f3c5289e78462fb96015f79c954d95a0d527ba55 \r\nAuthor: Martin Storsjö <[email protected]> \r\nDate: Wed Oct 5 14:44:21 2022 +0300 \r\n \r\n Revert \"Recommit \"[SCEV] Look through single value PHIs.\" (take 3)\" \r\n \r\n This reverts commit 20d798bd47ec5191de1b2a8a031da06a04e612e1. \r\n \r\n This commit caused crashes in some cases, see github issue #58152. \r\n This is fixed on main, but backporting it requires multiple \r\n nontrivial cherrypicks. \r\n \r\n Updating llvm/test/Transforms/LoopVectorize/create-induction-resume.ll \r\n with update_test_checks.py, so this isn't an exact automatic revert, \r\n as that test case was added after the reverted commit. \r\n \r\n This fixes #58152 for the release branch. \r\n \r\n llvm/lib/Analysis/ScalarEvolution.cpp | 7 ++-\r\n llvm/test/Analysis/DependenceAnalysis/lcssa.ll | 2 +- \r\n llvm/test/Analysis/ScalarEvolution/cycled_phis.ll | 4 +- \r\n .../ScalarEvolution/incorrect-exit-count.ll | 2 +- \r\n .../Analysis/ScalarEvolution/solve-quadratic-i1.ll | 4 +- \r\n .../ScalarEvolution/solve-quadratic-overflow.ll | 6 +-- \r\n llvm/test/Analysis/ScalarEvolution/trivial-phis.ll | 2 +- \r\n llvm/test/Transforms/LoopStrengthReduce/funclet.ll | 40 +++++++++-------\r\n .../LoopVectorize/create-induction-resume.ll | 24 ++++------\r\n llvm/test/Transforms/LoopVectorize/pr45259.ll | 55 +++++++++++-----------\r\n 10 files changed, 75 insertions(+), 71 deletions(-)\r\n```\r\nspecifically, this (almost) 1-line diff\r\n```diff\r\ndiff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp\r\nindex 4b2db80bc1ec..3b73f9511eca 100644\r\n--- a/llvm/lib/Analysis/ScalarEvolution.cpp\r\n+++ b/llvm/lib/Analysis/ScalarEvolution.cpp\r\n@@ -6023,8 +6023,13 @@ const SCEV *ScalarEvolution::createNodeForPHI(PHINode *PN) {\r\n if (const SCEV *S = createAddRecFromPHI(PN))\r\n return S;\r\n \r\n+ // If the PHI has a single incoming value, follow that value, unless the\r\n+ // PHI's incoming blocks are in a different loop, in which case doing so\r\n+ // risks breaking LCSSA form. Instcombine would normally zap these, but\r\n+ // it doesn't have DominatorTree information, so it may miss cases.\r\n if (Value *V = simplifyInstruction(PN, {getDataLayout(), &TLI, &DT, &AC}))\r\n- return getSCEV(V);\r\n+ if (LI.replacementPreservesLCSSAForm(PN, V))\r\n+ return getSCEV(V);\r\n \r\n if (const SCEV *S = createNodeFromSelectLikePHI(PN))\r\n return S;\r\n```\r\n"
},
{
"author": "nikic",
"body": "Reduced:\r\n```llvm\r\n; RUN: opt -passes=\"print<scalar-evolution>,loop-unroll\" -unroll-runtime\r\ndefine void @test(i1 %c, ptr %p) {\r\nentry:\r\n br label %loop\r\n\r\nloop:\r\n %phi = phi ptr [ null, %entry ], [ %p, %loop ]\r\n %load = load i64, ptr %p, align 8\r\n %add = add i64 %load, 1\r\n br i1 %c, label %bb2, label %loop\r\n\r\nbb2:\r\n %add.lcssa = phi i64 [ %add, %loop ]\r\n %gep = getelementptr i64, ptr %p, i64 %add.lcssa\r\n br label %loop2\r\n\r\nloop2:\r\n %iv = phi ptr [ %p, %bb2 ], [ %iv.next, %loop2 ]\r\n %iv.next = getelementptr i8, ptr %iv, i64 8\r\n %icmp = icmp eq ptr %iv, %gep\r\n br i1 %icmp, label %exit, label %loop2\r\n\r\nexit:\r\n ret void\r\n}\r\n```"
},
{
"author": "nikic",
"body": "From a cursory look, the problem here is that the BECount of `loop2` depends on `%load`, and after peeling it should instead depend on a phi node, but instead still depends on `%load`. As the BECount does not dominate the loop, SCEV is invalid.\r\n\r\nThis issue sounds very familiar, we've fixed variants of this in the past."
}
]
} | true | null |
102279 | https://github.com/llvm/llvm-project/issues/102279 | crash | f7e1efe8bcea14686d1c303e058f687b6ca1c79f | 2024-08-07T07:28:15 | [
"llvm/test/Transforms/SLPVectorizer"
] | {
"fix_commit": "441f94f4bdf6e2b9747ec12194c595098d9c3a5b",
"components": [
"SLPVectorizer"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
[
17336,
17362
]
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
"tryToReduce"
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 441f94f4bdf6e2b9747ec12194c595098d9c3a5b
Author: Alexey Bataev <[email protected]>
Date: Wed Aug 7 04:09:55 2024 -0700
[SLP]Fix PR102279: check the tracked values for extractelements, not the original values
If the reduced value was replaced by the extractelement instruction
during vectorization and we attempt to check if this is so, need to
check the tracked value, not the original (deleted) instruction.
Otherwise, the compiler may crash
Fixes https://github.com/llvm/llvm-project/issues/102279
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index c9335b7a89e1..1fee06d145b9 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -17336,27 +17336,23 @@ public:
// Try to handle shuffled extractelements.
if (S.getOpcode() == Instruction::ExtractElement && !S.isAltShuffle() &&
I + 1 < E) {
- InstructionsState NextS = getSameOpcode(ReducedVals[I + 1], TLI);
- if (NextS.getOpcode() == Instruction::ExtractElement &&
- !NextS.isAltShuffle()) {
- SmallVector<Value *> CommonCandidates(Candidates);
- for (Value *RV : ReducedVals[I + 1]) {
- Value *RdxVal = TrackedVals.find(RV)->second;
- // Check if the reduction value was not overriden by the
- // extractelement instruction because of the vectorization and
- // exclude it, if it is not compatible with other values.
- if (auto *Inst = dyn_cast<Instruction>(RdxVal))
- if (!NextS.getOpcode() || !NextS.isOpcodeOrAlt(Inst))
- continue;
- CommonCandidates.push_back(RdxVal);
- TrackedToOrig.try_emplace(RdxVal, RV);
- }
- SmallVector<int> Mask;
- if (isFixedVectorShuffle(CommonCandidates, Mask)) {
- ++I;
- Candidates.swap(CommonCandidates);
- ShuffledExtracts = true;
- }
+ SmallVector<Value *> CommonCandidates(Candidates);
+ for (Value *RV : ReducedVals[I + 1]) {
+ Value *RdxVal = TrackedVals.find(RV)->second;
+ // Check if the reduction value was not overriden by the
+ // extractelement instruction because of the vectorization and
+ // exclude it, if it is not compatible with other values.
+ auto *Inst = dyn_cast<ExtractElementInst>(RdxVal);
+ if (!Inst)
+ continue;
+ CommonCandidates.push_back(RdxVal);
+ TrackedToOrig.try_emplace(RdxVal, RV);
+ }
+ SmallVector<int> Mask;
+ if (isFixedVectorShuffle(CommonCandidates, Mask)) {
+ ++I;
+ Candidates.swap(CommonCandidates);
+ ShuffledExtracts = true;
}
}
| [
{
"file": "llvm/test/Transforms/SLPVectorizer/X86/reduced-value-replace-extractelement.ll",
"commands": [
"opt -S --passes=slp-vectorizer -slp-threshold=-99999 < %s -mtriple=x86_64-unknown-linux-gnu"
],
"tests": [
{
"test_name": "test",
"test_body": "define void @test() {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb1, %bb\n %phi = phi i32 [ 0, %bb ], [ %mul9, %bb1 ]\n %phi2 = phi i32 [ 0, %bb ], [ 0, %bb1 ]\n %trunc = trunc i64 0 to i32\n %mul = mul i32 0, %trunc\n %mul3 = mul i32 %trunc, %phi\n %mul4 = mul i32 %mul3, %mul\n %mul5 = mul i32 %mul4, %mul\n %trunc6 = trunc i64 0 to i32\n %mul7 = mul i32 0, %trunc6\n %mul8 = mul i32 %mul5, %mul7\n %mul9 = mul i32 %mul8, %mul7\n br label %bb1\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/SLPVectorizer/X86/reduction-gather-non-scheduled-extracts.ll",
"commands": [
"opt -S --passes=slp-vectorizer -mtriple=x86_64-sie-ps5 < %s"
],
"tests": [
{
"test_name": "tes",
"test_body": "define void @tes() {\nentry:\n %0 = extractelement <2 x i1> zeroinitializer, i64 0\n %1 = extractelement <2 x i1> zeroinitializer, i64 0\n %2 = fcmp ole <2 x double> zeroinitializer, zeroinitializer\n %3 = extractelement <2 x i1> %2, i64 0\n %4 = extractelement <2 x i1> zeroinitializer, i64 0\n br label %5\n\n5: ; preds = %entry\n %6 = select i1 false, i1 false, i1 false\n %7 = select i1 %6, i1 %0, i1 false\n %8 = select i1 %7, i1 %1, i1 false\n %9 = select i1 %8, i1 false, i1 false\n %10 = select i1 %9, i1 %3, i1 false\n %11 = select i1 %10, i1 %4, i1 false\n br i1 %11, label %12, label %13\n\n12: ; preds = %5\n ret void\n\n13: ; preds = %5\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "Crash in getSameOpcode(llvm::ArrayRef<llvm::Value*>, llvm::TargetLibraryInfo const&, unsigned int)",
"body": " To reproduce run the test below with `-passes slp-vectorizer -slp-threshold=-99999`\r\n```\r\n; ModuleID = './reduced.ll'\r\nsource_filename = \"./reduced.ll\"\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @wombat() #0 gc \"statepoint-example\" {\r\nbb:\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb1, %bb\r\n %phi = phi i32 [ 0, %bb ], [ %mul9, %bb1 ]\r\n %phi2 = phi i32 [ 0, %bb ], [ 0, %bb1 ]\r\n %trunc = trunc i64 0 to i32\r\n %mul = mul i32 0, %trunc\r\n %mul3 = mul i32 %trunc, %phi\r\n %mul4 = mul i32 %mul3, %mul\r\n %mul5 = mul i32 %mul4, %mul\r\n %trunc6 = trunc i64 0 to i32\r\n %mul7 = mul i32 0, %trunc6\r\n %mul8 = mul i32 %mul5, %mul7\r\n %mul9 = mul i32 %mul8, %mul7\r\n br label %bb1\r\n}\r\n\r\n```\r\nReproducer: https://godbolt.org/z/sqEov8n9h\r\n\r\nStack dump:\r\n```\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes slp-vectorizer -slp-threshold=-99999 <source>\r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"wombat\"\r\n #0 0x0000000004f2ff18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f2ff18)\r\n #1 0x0000000004f2d68c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007a3cdfe42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000000000403fb8a getSameOpcode(llvm::ArrayRef<llvm::Value*>, llvm::TargetLibraryInfo const&, unsigned int) (.constprop.1) SLPVectorizer.cpp:0:0\r\n #4 0x000000000406b0a4 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n #5 0x000000000406dab4 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x406dab4)\r\n #6 0x00000000040720f8 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40720f8)\r\n #7 0x00000000040763be llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40763be)\r\n #8 0x000000000407c648 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\r\n #9 0x000000000407d11b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x407d11b)\r\n#10 0x0000000002e7f61e llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2e7f61e)\r\n#11 0x0000000004d2d348 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d2d348)\r\n#12 0x0000000000de6cce llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xde6cce)\r\n#13 0x0000000004d2bd3e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d2bd3e)\r\n#14 0x0000000000de731e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xde731e)\r\n#15 0x0000000004d29ea0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d29ea0)\r\n#16 0x00000000008e4312 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8e4312)\r\n#17 0x00000000008d723c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d723c)\r\n#18 0x00007a3cdfe29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#19 0x00007a3cdfe29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#20 0x00000000008ce6ae _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8ce6ae)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```",
"author": "TatyanaDoubts",
"labels": [
"llvm:SLPVectorizer",
"crash"
],
"comments": [
{
"author": "RKSimon",
"body": "CC @alexey-bataev "
}
]
} | true | null |
128401 | https://github.com/llvm/llvm-project/issues/128401 | crash | 22a5bb32b787443b70476cc1359709b6c888b591 | 2025-02-23T05:19:16 | [
"llvm/test/Transforms/SLPVectorizer"
] | {
"fix_commit": "eb14d2a1d48fe76c5faed71a08547135a35ee742",
"components": [
"SLPVectorizer"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
[
13320,
13328
],
[
13874,
13888
]
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
"BoUpSLP::isGatherShuffledEntry",
"BoUpSLP::isGatherShuffledSingleRegisterEntry"
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit eb14d2a1d48fe76c5faed71a08547135a35ee742
Author: Alexey Bataev <[email protected]>
Date: Mon Feb 24 06:02:56 2025 -0800
[SLP]Fix check for matched gather node, if it is a subvector node
If the gather node is a subvector node, it may match the existing
vector/gather node in the graph, but still may require reordering. in
this case need to fully check its dependencies to prevent a compiler
crash.
Fixes #128401
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index bf256d82ae17..5fc5fb10fad5 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -13320,9 +13320,16 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(
Entries.clear();
// TODO: currently checking only for Scalars in the tree entry, need to count
// reused elements too for better cost estimation.
- const EdgeInfo &TEUseEI = TE == VectorizableTree.front().get()
- ? EdgeInfo(const_cast<TreeEntry *>(TE), 0)
- : TE->UserTreeIndex;
+ auto GetUserEntry = [&](const TreeEntry *TE) {
+ while (TE->UserTreeIndex && TE->UserTreeIndex.EdgeIdx == UINT_MAX)
+ TE = TE->UserTreeIndex.UserTE;
+ if (TE == VectorizableTree.front().get())
+ return EdgeInfo(const_cast<TreeEntry *>(TE), 0);
+ return TE->UserTreeIndex;
+ };
+ const EdgeInfo TEUseEI = GetUserEntry(TE);
+ if (!TEUseEI)
+ return std::nullopt;
const Instruction *TEInsertPt = &getLastInstructionInBundle(TEUseEI.UserTE);
const BasicBlock *TEInsertBlock = nullptr;
// Main node of PHI entries keeps the correct order of operands/incoming
@@ -13874,15 +13881,13 @@ BoUpSLP::isGatherShuffledEntry(
assert(VL.size() % NumParts == 0 &&
"Number of scalars must be divisible by NumParts.");
if (TE->UserTreeIndex && TE->UserTreeIndex.UserTE->isGather() &&
- TE->UserTreeIndex.EdgeIdx == UINT_MAX) {
- assert(
- (TE->Idx == 0 ||
- (TE->hasState() && TE->getOpcode() == Instruction::ExtractElement) ||
- isSplat(TE->Scalars) ||
- getSameValuesTreeEntry(TE->getMainOp(), TE->Scalars)) &&
- "Expected splat or extractelements only node.");
+ TE->UserTreeIndex.EdgeIdx == UINT_MAX &&
+ (TE->Idx == 0 ||
+ (TE->hasState() && TE->getOpcode() == Instruction::ExtractElement) ||
+ isSplat(TE->Scalars) ||
+ (TE->hasState() &&
+ getSameValuesTreeEntry(TE->getMainOp(), TE->Scalars))))
return {};
- }
unsigned SliceSize = getPartNumElems(VL.size(), NumParts);
SmallVector<std::optional<TTI::ShuffleKind>> Res;
for (unsigned Part : seq<unsigned>(NumParts)) {
| [
{
"file": "llvm/test/Transforms/SLPVectorizer/X86/bv-matched-node-reorder.ll",
"commands": [
"opt -passes=slp-vectorizer -S -mtriple=x86_64-unknown-linux-gnu < %s"
],
"tests": [
{
"test_name": "<module>",
"test_body": "\n@g = global [8 x i8] zeroinitializer\n\ndefine i32 @main() {\n;\nentry:\n %l2.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 5), align 1\n %li.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 4), align 1\n %l1.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 7), align 1\n %l6.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 6), align 1\n br i1 false, label %if.end151.1.i.i.1.i.i.i, label %end\n\npre:\n br label %end\n\nend:\n %0 = phi i8 [ 0, %pre ], [ %li.i.i.i, %entry ]\n %1 = phi i8 [ 0, %pre ], [ %l2.i.i.i.i, %entry ]\n %2 = phi i8 [ 0, %pre ], [ %l6.i.i.i.i, %entry ]\n %3 = phi i8 [ 0, %pre ], [ %l1.i.i.i.i, %entry ]\n %4 = phi i8 [ 0, %pre ], [ %l1.i.i.i.i, %entry ]\n %5 = phi i8 [ 0, %pre ], [ %l6.i.i.i.i, %entry ]\n %6 = phi i8 [ 0, %pre ], [ %l2.i.i.i.i, %entry ]\n %7 = phi i8 [ 0, %pre ], [ %li.i.i.i, %entry ]\n br label %if.end151.1.i.i.1.i.i.i\n\nif.end151.1.i.i.1.i.i.i:\n %8 = phi i8 [ %li.i.i.i, %entry ], [ %7, %end ]\n %9 = phi i8 [ %l2.i.i.i.i, %entry ], [ %6, %end ]\n %10 = phi i8 [ %l6.i.i.i.i, %entry ], [ %5, %end ]\n %11 = phi i8 [ %l1.i.i.i.i, %entry ], [ %4, %end ]\n %12 = phi i8 [ %l1.i.i.i.i, %entry ], [ %3, %end ]\n %13 = phi i8 [ 0, %entry ], [ %2, %end ]\n %14 = phi i8 [ %l2.i.i.i.i, %entry ], [ %1, %end ]\n %15 = phi i8 [ %li.i.i.i, %entry ], [ %0, %end ]\n %16 = phi i8 [ 0, %entry ], [ %6, %end ]\n %17 = phi i8 [ %l1.i.i.i.i, %entry ], [ %4, %end ]\n %18 = phi i8 [ %l6.i.i.i.i, %entry ], [ %5, %end ]\n %19 = phi i8 [ %l1.i.i.i.i, %entry ], [ %4, %end ]\n %20 = phi i8 [ %l6.i.i.i.i, %entry ], [ %5, %end ]\n %21 = phi i8 [ %l2.i.i.i.i, %entry ], [ %6, %end ]\n %22 = phi i8 [ %li.i.i.i, %entry ], [ %7, %end ]\n %tobool.not.i.1121.i.1.i.i.i = icmp ne i8 %18, 0\n %c1.1.1117.i.1.i9.i.i = icmp eq i8 %17, 0\n %c1.i.1.i.i.i = icmp eq i8 %16, 0\n %c1.1.i.i.i.i = icmp eq i8 %12, 0\n %cmp258.i.1.i.i.i.i = icmp eq i8 %13, 0\n %c1.i.i.i.i = icmp eq i8 %14, 0\n %cmp258.i.i.i.i.i = icmp eq i8 %15, 0\n %c1.1.1.i.i.i.i = icmp eq i8 %11, 0\n %cmp258.i.1.1.i.i.i.i = icmp eq i8 %10, 0\n %c1.187.i.i.i.i = icmp eq i8 %9, 0\n %cmp258.i.185.i.i.i.i = icmp eq i8 %8, 0\n %c1.1.1117.i.i.i.i = icmp eq i8 %19, 0\n %cmp258.i.1.1115.i.i.i.i = icmp eq i8 %20, 0\n %c1.1113.i.i.i.i = icmp eq i8 %21, 0\n %cmp258.i.1111.i.i.i.i = icmp eq i8 %22, 0\n %c1.187.1.i.i.i.i = icmp eq i8 %16, 0\n ret i32 0\n}",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[SLPVectorizer] Assertion `\"Expected splat or extractelements only node.\"' failed.",
"body": "Reproducer: https://godbolt.org/z/9jx1xejoe\n```\n; bin/opt -passes=slp-vectorizer test.ll -S\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@g = global [8 x i8] zeroinitializer\n\ndefine i32 @main() {\nentry:\n %.promoted42.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 5), align 1\n %.promoted.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 4), align 1\n %.promoted51.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 7), align 1\n %.promoted56.i.i.i.i = load i8, ptr getelementptr inbounds nuw (i8, ptr @g, i64 6), align 1\n br i1 false, label %if.end151.1.i.i.1.i.i.i, label %if.end151.1.i.1.i.i.i.i\n\nfor.cond79.preheader.us.preheader.1.i.1.i.i.i.i:\n br label %if.end151.1.i.1.i.i.i.i\n\nif.end151.1.i.1.i.i.i.i:\n %0 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted.i.i.i.i, %entry ]\n %1 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted42.i.i.i.i, %entry ]\n %2 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted56.i.i.i.i, %entry ]\n %3 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted51.i.i.i.i, %entry ]\n %4 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted51.i.i.i.i, %entry ]\n %5 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted56.i.i.i.i, %entry ]\n %6 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted42.i.i.i.i, %entry ]\n %7 = phi i8 [ 0, %for.cond79.preheader.us.preheader.1.i.1.i.i.i.i ], [ %.promoted.i.i.i.i, %entry ]\n br label %if.end151.1.i.i.1.i.i.i\n\nif.end151.1.i.i.1.i.i.i:\n %8 = phi i8 [ %.promoted.i.i.i.i, %entry ], [ %7, %if.end151.1.i.1.i.i.i.i ]\n %9 = phi i8 [ %.promoted42.i.i.i.i, %entry ], [ %6, %if.end151.1.i.1.i.i.i.i ]\n %10 = phi i8 [ %.promoted56.i.i.i.i, %entry ], [ %5, %if.end151.1.i.1.i.i.i.i ]\n %11 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %4, %if.end151.1.i.1.i.i.i.i ]\n %12 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %3, %if.end151.1.i.1.i.i.i.i ]\n %13 = phi i8 [ 0, %entry ], [ %2, %if.end151.1.i.1.i.i.i.i ]\n %14 = phi i8 [ %.promoted42.i.i.i.i, %entry ], [ %1, %if.end151.1.i.1.i.i.i.i ]\n %15 = phi i8 [ %.promoted.i.i.i.i, %entry ], [ %0, %if.end151.1.i.1.i.i.i.i ]\n %16 = phi i8 [ 0, %entry ], [ %6, %if.end151.1.i.1.i.i.i.i ]\n %17 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %4, %if.end151.1.i.1.i.i.i.i ]\n %18 = phi i8 [ %.promoted56.i.i.i.i, %entry ], [ %5, %if.end151.1.i.1.i.i.i.i ]\n %19 = phi i8 [ %.promoted51.i.i.i.i, %entry ], [ %4, %if.end151.1.i.1.i.i.i.i ]\n %20 = phi i8 [ %.promoted56.i.i.i.i, %entry ], [ %5, %if.end151.1.i.1.i.i.i.i ]\n %21 = phi i8 [ %.promoted42.i.i.i.i, %entry ], [ %6, %if.end151.1.i.1.i.i.i.i ]\n %22 = phi i8 [ %.promoted.i.i.i.i, %entry ], [ %7, %if.end151.1.i.1.i.i.i.i ]\n %tobool.not.i.1121.i.1.i.i.i = icmp ne i8 %18, 0\n %cmp258.1.i.1.1117.i.1.i9.i.i = icmp eq i8 %17, 0\n %cmp258.1.i.i.1.i.i.i = icmp eq i8 %16, 0\n %cmp258.1.i.1.i.i.i.i = icmp eq i8 %12, 0\n %cmp258.i.1.i.i.i.i = icmp eq i8 %13, 0\n %cmp258.1.i.i.i.i.i = icmp eq i8 %14, 0\n %cmp258.i.i.i.i.i = icmp eq i8 %15, 0\n %cmp258.1.i.1.1.i.i.i.i = icmp eq i8 %11, 0\n %cmp258.i.1.1.i.i.i.i = icmp eq i8 %10, 0\n %cmp258.1.i.187.i.i.i.i = icmp eq i8 %9, 0\n %cmp258.i.185.i.i.i.i = icmp eq i8 %8, 0\n %cmp258.1.i.1.1117.i.i.i.i = icmp eq i8 %19, 0\n %cmp258.i.1.1115.i.i.i.i = icmp eq i8 %20, 0\n %cmp258.1.i.1113.i.i.i.i = icmp eq i8 %21, 0\n %cmp258.i.1111.i.i.i.i = icmp eq i8 %22, 0\n %cmp258.1.i.187.1.i.i.i.i = icmp eq i8 %16, 0\n ret i32 0\n}\n```\n```\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:13878: llvm::SmallVector<std::optional<llvm::TargetTransformInfo::ShuffleKind> > llvm::slpvectorizer::BoUpSLP::isGatherShuffledEntry(const llvm::slpvectorizer::BoUpSLP::TreeEntry*, llvm::ArrayRef<llvm::Value*>, llvm::SmallVectorImpl<int>&, llvm::SmallVectorImpl<llvm::SmallVector<const llvm::slpvectorizer::BoUpSLP::TreeEntry*> >&, unsigned int, bool): Assertion `(TE->Idx == 0 || (TE->hasState() && TE->getOpcode() == Instruction::ExtractElement) || isSplat(TE->Scalars) || getSameValuesTreeEntry(TE->getMainOp(), TE->Scalars)) && \"Expected splat or extractelements only node.\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer <source>\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\n2.\tRunning pass \"slp-vectorizer\" on function \"main\"\n #0 0x0000000005447b18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5447b18)\n #1 0x00000000054454d4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x000072c4b8a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x000072c4b8a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x000072c4b8a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x000072c4b8a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x000072c4b8a2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x000072c4b8a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x000000000447b405 llvm::slpvectorizer::BoUpSLP::isGatherShuffledEntry(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallVectorImpl<int>&, llvm::SmallVectorImpl<llvm::SmallVector<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, 6u>>&, unsigned int, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x447b405)\n #9 0x000000000447c786 llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator, llvm::InstructionCost, llvm::TargetTransformInfo, llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl<llvm::Value*>>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x447c786)\n#10 0x000000000447ec37 llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x447ec37)\n#11 0x00000000044b3879 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44b3879)\n#12 0x00000000044bd45d llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44bd45d)\n#13 0x00000000044c1701 bool llvm::SLPVectorizerPass::vectorizeCmpInsts<std::reverse_iterator<llvm::CmpInst* const*>>(llvm::iterator_range<std::reverse_iterator<llvm::CmpInst* const*>>, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44c1701)\n#14 0x00000000044c1fab llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&)::'lambda3'(bool)::operator()(bool) const SLPVectorizer.cpp:0:0\n#15 0x00000000044c575f llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44c575f)\n#16 0x00000000044cbef6 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\n#17 0x00000000044cca4b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44cca4b)\n#18 0x0000000003182e1e llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3182e1e)\n#19 0x00000000052431d0 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x52431d0)\n#20 0x0000000000e6e03e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6e03e)\n#21 0x0000000005241aeb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5241aeb)\n#22 0x0000000000e6d34e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6d34e)\n#23 0x00000000052414f0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x52414f0)\n#24 0x0000000000935a5a llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x935a5a)\n#25 0x00000000009290cc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9290cc)\n#26 0x000072c4b8a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#27 0x000072c4b8a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#28 0x00000000009209a5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9209a5)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```\nllvm version: dbd219aef4be56754c793589c60bd787b7de60c2\n",
"author": "dtcxzyw",
"labels": [
"llvm:SLPVectorizer",
"crash-on-valid",
"generated by fuzzer"
],
"comments": []
} | true | null |
106248 | https://github.com/llvm/llvm-project/issues/106248 | crash | 616f7d3d4f6d9bea6f776e357c938847e522a681 | 2024-08-27T17:02:16 | [
"llvm/test/Transforms/LoopVectorize"
] | {
"fix_commit": "0a272d3a1703415abca42dc2e2cc2b57cb30734e",
"components": [
"LoopVectorize"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
[
6529,
6534
]
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
"LoopVectorizationCostModel::getInstructionCost"
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 0a272d3a1703415abca42dc2e2cc2b57cb30734e
Author: Florian Hahn <[email protected]>
Date: Thu Aug 29 12:08:27 2024 +0100
[LV] Use SCEV to analyze second operand for cost query.
Improve operand analysis using SCEV for cost purposes. This fixes a
divergence between legacy and VPlan-based cost-modeling after
533e6bbd0d34.
Fixes https://github.com/llvm/llvm-project/issues/106248.
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 56f51e14a6eb..4cc75e2e7546 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -6529,6 +6529,10 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I,
// Certain instructions can be cheaper to vectorize if they have a constant
// second vector operand. One example of this are shifts on x86.
Value *Op2 = I->getOperand(1);
+ if (!isa<Constant>(Op2) && PSE.getSE()->isSCEVable(Op2->getType()) &&
+ isa<SCEVConstant>(PSE.getSCEV(Op2))) {
+ Op2 = cast<SCEVConstant>(PSE.getSCEV(Op2))->getValue();
+ }
auto Op2Info = TTI.getOperandInfo(Op2);
if (Op2Info.Kind == TargetTransformInfo::OK_AnyValue &&
Legal->isInvariant(Op2))
| [
{
"file": "llvm/test/Transforms/LoopVectorize/X86/cost-constant-known-via-scev.ll",
"commands": [
"opt -p loop-vectorize -S %s"
],
"tests": [
{
"test_name": "test_foldable_live_in_via_scev",
"test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i64 @test_foldable_live_in_via_scev() {\nentry:\n %conv = zext i16 -6 to i64\n %add = add nsw i64 %conv, -65528\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop ]\n %red = phi i64 [ 1, %entry ], [ %mul, %loop ]\n %mul = mul nsw i64 %red, %add\n %iv.next = add nsw i32 %iv, 1\n %ec = icmp eq i32 %iv.next, 100\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n %ret = phi i64 [ %mul, %loop ]\n ret i64 %ret\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[clang] Assertion failed in Vectorize",
"body": "In #105722 , we resolved the assertion failure in vectorization. However, I met this crash again with the following case:\r\n\r\n```c\r\n#include <stdint.h>\r\nint a;\r\nlong b;\r\nstruct e {\r\n uint16_t f;\r\n uint64_t g;\r\n int32_t h\r\n} static i = {65530};\r\nvoid c(int d) {\r\n for (; a; a++)\r\n b *= d;\r\n}\r\nuint32_t j(struct e, uint16_t);\r\nuint64_t k() { j(i, 0); }\r\nuint32_t j(struct e, uint16_t) { c(i.f - 65528); }\r\n```\r\nI compiled it with -O2 flag and it crashed. But when I compiled with -O1/-O0, it worked.\r\n\r\nThe crash is: clang++: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7359: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), BestFactor.Width, CostCtx, OrigLoop, CM)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\n\r\nThe details can be found here: https://godbolt.org/z/8x48xsKs6",
"author": "cardigan1008",
"labels": [
"vectorizers",
"crash"
],
"comments": [
{
"author": "fhahn",
"body": "Thanks for the report @cardigan1008, should be fixed now"
}
]
} | true | null |
104761 | https://github.com/llvm/llvm-project/issues/104761 | crash | 5cfa8baef33636827e5aa8dd76888c724433b53e | 2024-08-19T11:00:31 | [
"llvm/test/Analysis/LoopCacheAnalysis"
] | {
"fix_commit": "2e6deb1dd3a4422807633ba08773e8d786e43d4c",
"components": [
"LoopCacheAnalysis"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": [
[
16,
21
],
[
31,
37
],
[
192,
199
]
],
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": [
[
328,
333
],
[
338,
351
],
[
696,
702
]
],
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": [
"CacheCost::computeLoopCacheCost",
"IndexedReference::computeRefCost",
"IndexedReference::tryDelinearizeFixedSize"
],
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 2e6deb1dd3a4422807633ba08773e8d786e43d4c
Author: Sjoerd Meijer <[email protected]>
Date: Thu Nov 14 08:40:45 2024 +0000
[LoopInterchange] Fix overflow in cost calculation (#111807)
If the iteration count is really large, e.g. UINT_MAX, then the cost
calculation can overflows and trigger an assert. So saturate the cost to
INT_MAX if this is the case by using InstructionCost as a type which
already supports this kind of overflow handling.
This fixes #104761
diff --git a/llvm/include/llvm/Analysis/LoopCacheAnalysis.h b/llvm/include/llvm/Analysis/LoopCacheAnalysis.h
index 4fd2485e39d6..3e22487e5e34 100644
--- a/llvm/include/llvm/Analysis/LoopCacheAnalysis.h
+++ b/llvm/include/llvm/Analysis/LoopCacheAnalysis.h
@@ -16,6 +16,7 @@
#include "llvm/Analysis/LoopAnalysisManager.h"
#include "llvm/IR/PassManager.h"
+#include "llvm/Support/InstructionCost.h"
#include <optional>
namespace llvm {
@@ -31,7 +32,7 @@ class ScalarEvolution;
class SCEV;
class TargetTransformInfo;
-using CacheCostTy = int64_t;
+using CacheCostTy = InstructionCost;
using LoopVectorTy = SmallVector<Loop *, 8>;
/// Represents a memory reference as a base pointer and a set of indexing
@@ -192,8 +193,6 @@ class CacheCost {
using LoopCacheCostTy = std::pair<const Loop *, CacheCostTy>;
public:
- static CacheCostTy constexpr InvalidCost = -1;
-
/// Construct a CacheCost object for the loop nest described by \p Loops.
/// The optional parameter \p TRT can be used to specify the max. distance
/// between array elements accessed in a loop so that the elements are
diff --git a/llvm/lib/Analysis/LoopCacheAnalysis.cpp b/llvm/lib/Analysis/LoopCacheAnalysis.cpp
index 7ca9f15ad5fc..2897b922f61e 100644
--- a/llvm/lib/Analysis/LoopCacheAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopCacheAnalysis.cpp
@@ -328,6 +328,8 @@ CacheCostTy IndexedReference::computeRefCost(const Loop &L,
const SCEV *TripCount =
computeTripCount(*AR->getLoop(), *Sizes.back(), SE);
Type *WiderType = SE.getWiderType(RefCost->getType(), TripCount->getType());
+ // For the multiplication result to fit, request a type twice as wide.
+ WiderType = WiderType->getExtendedType();
RefCost = SE.getMulExpr(SE.getNoopOrZeroExtend(RefCost, WiderType),
SE.getNoopOrZeroExtend(TripCount, WiderType));
}
@@ -338,14 +340,18 @@ CacheCostTy IndexedReference::computeRefCost(const Loop &L,
assert(RefCost && "Expecting a valid RefCost");
// Attempt to fold RefCost into a constant.
+ // CacheCostTy is a signed integer, but the tripcount value can be large
+ // and may not fit, so saturate/limit the value to the maximum signed
+ // integer value.
if (auto ConstantCost = dyn_cast<SCEVConstant>(RefCost))
- return ConstantCost->getValue()->getZExtValue();
+ return ConstantCost->getValue()->getLimitedValue(
+ std::numeric_limits<int64_t>::max());
LLVM_DEBUG(dbgs().indent(4)
<< "RefCost is not a constant! Setting to RefCost=InvalidCost "
"(invalid value).\n");
- return CacheCost::InvalidCost;
+ return CacheCostTy::getInvalid();
}
bool IndexedReference::tryDelinearizeFixedSize(
@@ -696,7 +702,7 @@ CacheCostTy
CacheCost::computeLoopCacheCost(const Loop &L,
const ReferenceGroupsTy &RefGroups) const {
if (!L.isLoopSimplifyForm())
- return InvalidCost;
+ return CacheCostTy::getInvalid();
LLVM_DEBUG(dbgs() << "Considering loop '" << L.getName()
<< "' as innermost loop.\n");
| [
{
"file": "llvm/test/Analysis/LoopCacheAnalysis/interchange-refcost-overflow.ll",
"commands": [
"opt < %s -passes='print<loop-cache-cost>' -disable-output 2>&1"
],
"tests": [
{
"test_name": "foo",
"test_body": "@A = external local_unnamed_addr global [11 x [11 x [11 x i32]]], align 16\n\ndefine void @foo(i32 noundef %b) {\nentry:\n %0 = sext i32 %b to i64\n br label %outer.loop\n\nouter.loop: ; preds = %outer.loop.cleanup, %entry\n %indvars.iv = phi i64 [ %indvars.iv.next, %outer.loop.cleanup ], [ 0, %entry ]\n br label %inner.loop\n\nouter.loop.cleanup: ; preds = %inner.loop\n %indvars.iv.next = add nsw i64 %indvars.iv, %0\n br label %outer.loop\n\ninner.loop: ; preds = %inner.loop, %outer.loop\n %inner.iv = phi i64 [ 0, %outer.loop ], [ %add, %inner.loop ]\n %arrayidx3 = getelementptr inbounds [11 x [11 x [11 x i32]]], ptr @A, i64 0, i64 %indvars.iv, i64 %inner.iv, i64 %inner.iv\n store i32 0, ptr %arrayidx3, align 4\n %add = add nuw i64 %inner.iv, 2\n %cmp = icmp ult i64 %inner.iv, -5\n br i1 %cmp, label %inner.loop, label %outer.loop.cleanup\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[LoopInterchange] Assertion `getActiveBits() <= 64 && \"Too many bits for uint64_t\"",
"body": "With options \"-O3 --target=aarch64 func.cpp -mllvm -enable-loopinterchange\" and this input:\r\n```\r\nunsigned int A[11][11][11] __attribute__((aligned(16)));\r\nvoid a(int b) {\r\n for (int c;; c += b)\r\n for (long d = 0; d < -3ULL; d += 2ULL)\r\n A[c][d][d] = 0;\r\n}\r\n```\r\n\r\nLoop-interchange runs in an assert:\r\n\r\n```\r\nllvm-project/llvm/include/llvm/ADT/APInt.h:1501: uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits() <= 64 && \"Too many bits for uint64_t\"' failed.\r\n```\r\n\r\nIR reproducer, compile this with \"opt -passes=loop-interchange -S\":\r\n\r\n```\r\ntarget datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32\"\r\ntarget triple = \"aarch64-unknown-linux-gnu\"\r\n\r\n@A = local_unnamed_addr global [11 x [11 x [11 x i32]]] zeroinitializer, align 16\r\n\r\ndefine void @_Z1ai(i32 noundef %b) local_unnamed_addr #0 {\r\nentry:\r\n %0 = sext i32 %b to i64\r\n br label %for.cond\r\n\r\n; Loop:\r\nfor.cond: ; preds = %for.cond.cleanup, %entry\r\n %indvars.iv = phi i64 [ %indvars.iv.next, %for.cond.cleanup ], [ 0, %entry ]\r\n br label %for.body\r\n\r\nfor.cond.cleanup: ; preds = %for.body\r\n %indvars.iv.next = add nsw i64 %indvars.iv, %0\r\n br label %for.cond\r\n\r\nfor.body: ; preds = %for.cond, %for.body\r\n %d.010 = phi i64 [ 0, %for.cond ], [ %add, %for.body ]\r\n %arrayidx3 = getelementptr inbounds [11 x [11 x [11 x i32]]], ptr @A, i64 0, i64 %indvars.iv, i64 %d.010, i64 %d.010\r\n store i32 0, ptr %arrayidx3, align 4\r\n %add = add nuw i64 %d.010, 2\r\n %cmp = icmp ult i64 %d.010, -5\r\n br i1 %cmp, label %for.body, label %for.cond.cleanup\r\n}\r\n```",
"author": "sjoerdmeijer",
"labels": [
"crash-on-valid",
"llvm:analysis"
],
"comments": [
{
"author": "RKSimon",
"body": "```\r\nopt: /root/llvm-project/llvm/include/llvm/ADT/APInt.h:1501: uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits() <= 64 && \"Too many bits for uint64_t\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=loop-interchange -debug <source>\r\n1.\tRunning pass \"function(loop(loop-interchange))\" on module \"<source>\"\r\n2.\tRunning pass \"loop(loop-interchange)\" on function \"_Z1ai\"\r\n #0 0x0000000004f7f528 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4f7f528)\r\n #1 0x0000000004f7cc9c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f497b842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007f497b8969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007f497b842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007f497b8287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007f497b82871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007f497b839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x00000000045677cc llvm::IndexedReference::computeRefCost(llvm::Loop const&, unsigned int) const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x45677cc)\r\n #9 0x000000000456995f llvm::CacheCost::computeLoopCacheCost(llvm::Loop const&, llvm::SmallVector<llvm::SmallVector<std::unique_ptr<llvm::IndexedReference, std::default_delete<llvm::IndexedReference>>, 8u>, 8u> const&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x456995f)\r\n#10 0x000000000456c137 llvm::CacheCost::calculateCacheFootprint() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x456c137)\r\n#11 0x0000000004573d5c llvm::CacheCost::getCacheCost(llvm::Loop&, llvm::LoopStandardAnalysisResults&, llvm::DependenceInfo&, std::optional<unsigned int>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4573d5c)\r\n#12 0x0000000003c71d66 llvm::LoopInterchangePass::run(llvm::LoopNest&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3c71d66)\r\n#13 0x0000000002eb0a6e llvm::detail::PassModel<llvm::LoopNest, llvm::LoopInterchangePass, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::LoopNest&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2eb0a6e)\r\n#14 0x0000000003c85255 llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runWithLoopNestPasses(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3c85255)\r\n#15 0x0000000003c85ce3 llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3c85ce3)\r\n#16 0x0000000003c868b8 llvm::FunctionToLoopPassAdaptor::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3c868b8)\r\n#17 0x0000000000df128e llvm::detail::PassModel<llvm::Function, llvm::FunctionToLoopPassAdaptor, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xdf128e)\r\n#18 0x0000000004d7c368 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d7c368)\r\n#19 0x0000000000df14be llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xdf14be)\r\n#20 0x0000000004d7ad5e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d7ad5e)\r\n#21 0x0000000000df0f8e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xdf0f8e)\r\n#22 0x0000000004d78ec0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4d78ec0)\r\n#23 0x00000000008e7582 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8e7582)\r\n#24 0x00000000008da45c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8da45c)\r\n#25 0x00007f497b829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#26 0x00007f497b829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#27 0x00000000008d1eee _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d1eee)\r\n```\r\nWhich seems to be due to the getZExtValue() call inside IndexedReference::computeRefCost\r\nhttps://github.com/llvm/llvm-project/blob/b05c55472bf7cadcd0e4cb1a669b3474695b0524/llvm/lib/Analysis/LoopCacheAnalysis.cpp#L340:L343"
},
{
"author": "svs-quic",
"body": "cc: @caojoshua "
},
{
"author": "sjoerdmeijer",
"body": "I have a fix, will put it up for review tomorrow. "
}
]
} | true | null |
114738 | https://github.com/llvm/llvm-project/issues/114738 | miscompilation | 2588b8be5624f721c56f44fd2a69f7327de8c0c1 | 2024-11-04T05:50:07 | [
"llvm/test/Transforms/SLPVectorizer"
] | {
"fix_commit": "899336735aeb2b41a48b6ac2c895da5e0f22dbf0",
"components": [
"SLPVectorizer"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
[
19490,
19498
]
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
"tryToReduce"
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 899336735aeb2b41a48b6ac2c895da5e0f22dbf0
Author: Alexey Bataev <[email protected]>
Date: Mon Nov 4 06:02:06 2024 -0800
[SLP]Be more pessimistic about poisonous reductions
Consider all possible reductions ops as being non-poisoning boolean
logical operations, which require freeze to be fully correct.
https://alive2.llvm.org/ce/z/TKWDMP
Fixes #114738
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 427b8bd0e75a..3c6daf7b9fbb 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -19490,9 +19490,7 @@ public:
// To prevent poison from leaking across what used to be sequential,
// safe, scalar boolean logic operations, the reduction operand must be
// frozen.
- if ((isBoolLogicOp(RdxRootInst) ||
- (AnyBoolLogicOp && VL.size() != TrackedVals.size())) &&
- !isGuaranteedNotToBePoison(VectorizedRoot))
+ if (AnyBoolLogicOp && !isGuaranteedNotToBePoison(VectorizedRoot))
VectorizedRoot = Builder.CreateFreeze(VectorizedRoot);
// Emit code to correctly handle reused reduced values, if required.
| [
{
"file": "llvm/test/Transforms/SLPVectorizer/reudction-or-non-poisoned.ll",
"commands": [
"opt -S --passes=slp-vectorizer < %s"
],
"tests": [
{
"test_name": "test",
"test_body": "define i1 @test(i32 %x, i32 %a, i32 %b, i32 %c, i32 %d) {\n %cmp = icmp sgt i32 %x, 1\n %cmp2 = icmp sgt i32 %b, 1\n %cmp3 = icmp sgt i32 %c, 1\n %cmp4 = icmp sgt i32 %d, 1\n %sel2 = select i1 %cmp4, i1 true, i1 %cmp2\n %sel3 = select i1 %sel2, i1 true, i1 %cmp3\n %sel4 = select i1 %cmp, i1 true, i1 %cmp4\n %ret = or i1 %sel3, %sel4\n ret i1 %ret\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[SLPVectorizer] wrong vectorization to `reduce_or` due to poisonous value",
"body": "Alive2 report: https://alive2.llvm.org/ce/z/f8PDZj\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine i1 @test1.2(i32 %x, i32 %a, i32 %b, i32 %c, i32 %d) {\r\n#0:\r\n %cmp = icmp sgt i32 %x, 1\r\n %cmp2 = icmp sgt i32 %b, 1\r\n %cmp3 = icmp sgt i32 %c, 1\r\n %cmp4 = icmp sgt i32 %d, 1\r\n %sel2 = select i1 %cmp4, i1 1, i1 %cmp2\r\n %sel3 = select i1 %sel2, i1 1, i1 %cmp3\r\n %sel4 = select i1 %cmp, i1 1, i1 %cmp4\r\n %ret = or i1 %sel3, %sel4\r\n ret i1 %ret\r\n}\r\n=>\r\ndefine i1 @test1.2(i32 %x, i32 %a, i32 %b, i32 %c, i32 %d) {\r\n#0:\r\n %#1 = insertelement <4 x i32> poison, i32 %d, i32 0\r\n %#2 = insertelement <4 x i32> %#1, i32 %b, i32 1\r\n %#3 = insertelement <4 x i32> %#2, i32 %c, i32 2\r\n %#4 = insertelement <4 x i32> %#3, i32 %x, i32 3\r\n %#5 = icmp sgt <4 x i32> %#4, { 1, 1, 1, 1 }\r\n %#6 = reduce_or <4 x i1> %#5\r\n ret i1 %#6\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\ni32 %x = #x00000000 (0)\r\ni32 %a = poison\r\ni32 %b = #x00000002 (2)\r\ni32 %c = poison\r\ni32 %d = #x00000000 (0)\r\n\r\nSource:\r\ni1 %cmp = #x0 (0)\r\ni1 %cmp2 = #x1 (1)\r\ni1 %cmp3 = poison\r\ni1 %cmp4 = #x0 (0)\r\ni1 %sel2 = #x1 (1)\r\ni1 %sel3 = #x1 (1)\r\ni1 %sel4 = #x0 (0)\r\ni1 %ret = #x1 (1)\r\n\r\nTarget:\r\n<4 x i32> %#1 = < #x00000000 (0), poison, poison, poison >\r\n<4 x i32> %#2 = < #x00000000 (0), #x00000002 (2), poison, poison >\r\n<4 x i32> %#3 = < #x00000000 (0), #x00000002 (2), poison, poison >\r\n<4 x i32> %#4 = < #x00000000 (0), #x00000002 (2), poison, #x00000000 (0) >\r\n<4 x i1> %#5 = < #x0 (0), #x1 (1), poison, #x0 (0) >\r\ni1 %#6 = poison\r\nSource value: #x1 (1)\r\nTarget value: poison\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```",
"author": "bongjunj",
"labels": [
"miscompilation",
"llvm:SLPVectorizer"
],
"comments": []
} | true | null |
118030 | https://github.com/llvm/llvm-project/issues/118030 | crash | 6f4b4f41ca41d7d0b44a32d9968aef7667c68184 | 2024-11-28T19:14:48 | [
"llvm/test/Transforms/SLPVectorizer"
] | {
"fix_commit": "f4974e09312afc9549fcfc0304b738d235da9eca",
"components": [
"SLPVectorizer"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
[
17799,
17804
]
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
"BoUpSLP::collectValuesToDemote"
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit f4974e09312afc9549fcfc0304b738d235da9eca
Author: Alexey Bataev <[email protected]>
Date: Fri Nov 29 06:20:19 2024 -0800
[SLP] Add a check for poison value in AShrChecker
Need to check if the value in AShrChecker is a poison before casting it
to instruction to avoid compiler crash
Fixes #118030
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 48a8520a966f..7723442bc0fb 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -17799,6 +17799,8 @@ bool BoUpSLP::collectValuesToDemote(
// original type and the sign bit of the truncate type are similar.
auto AShrChecker = [&](unsigned BitWidth, unsigned OrigBitWidth) {
return all_of(E.Scalars, [&](Value *V) {
+ if (isa<PoisonValue>(V))
+ return true;
auto *I = cast<Instruction>(V);
KnownBits AmtKnownBits = computeKnownBits(I->getOperand(1), *DL);
unsigned ShiftedBits = OrigBitWidth - BitWidth;
| [
{
"file": "llvm/test/Transforms/SLPVectorizer/X86/ashr-node-with-poison.ll",
"commands": [
"opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux < %s"
],
"tests": [
{
"test_name": "<module>",
"test_body": "\ndefine i32 @test(ptr %n, i32 %conv57, i1 %tobool5.not, i64 %bf.load14) {\n;\nentry:\n br i1 false, label %entry.if.end54_crit_edge, label %while.cond\n\nentry.if.end54_crit_edge:\n br label %if.end54\n\ntthread-pre-split:\n br label %t\n\nt:\n %w.2 = phi i32 [ 1, %tthread-pre-split ], [ 0, %if.end83 ]\n br label %if.end7\n\nt.u_crit_edge:\n br label %if.end7\n\nif.end7:\n %w.4 = phi i32 [ %w.2, %t ], [ %w.2, %t.u_crit_edge ], [ %bf.cast25, %while.body ]\n %a.4 = phi i32 [ 0, %t ], [ %conv57, %t.u_crit_edge ], [ %bf.cast2910, %while.body ]\n %b.4 = phi i32 [ 0, %t ], [ 0, %t.u_crit_edge ], [ %bf.cast2910, %while.body ]\n %c.4 = phi i32 [ 0, %t ], [ 1, %t.u_crit_edge ], [ poison, %while.body ]\n br label %v\n\nwhile.cond:\n %bf.load66.pre.pre1135 = phi i64 [ 0, %entry ], [ %spec.select, %if.end42 ]\n br i1 %tobool5.not, label %if.end54, label %while.body\n\nwhile.body:\n %bf.ashr24 = ashr i64 %bf.load14, 33\n %bf.cast25 = trunc nsw i64 %bf.ashr24 to i32\n %bf.ashr28 = lshr i64 %bf.load14, 1\n %bf.cast2910 = trunc i64 %bf.ashr28 to i32\n br label %if.end7\n\nif.end36:\n br label %v\n\nv:\n %c.7 = phi i32 [ %c.4, %if.end7 ], [ 0, %if.end36 ]\n br i1 true, label %if.end42, label %v.if.end83_crit_edge\n\nv.if.end83_crit_edge:\n br label %if.end83\n\nif.end42:\n %tobool43.not = icmp eq i32 %b.4, 0\n %narrow = select i1 %tobool43.not, i32 0, i32 %w.4\n %spec.select = zext i32 %narrow to i64\n %bf.value48 = zext i32 %a.4 to i64\n store i64 %bf.value48, ptr %n, align 8\n store i32 %c.7, ptr %n, align 4\n br label %while.cond\n\nif.end54:\n %bf.load66.pre.pre113125 = phi i64 [ %bf.load66.pre.pre1135, %while.cond ], [ poison, %entry.if.end54_crit_edge ]\n %0 = icmp eq i64 %bf.load66.pre.pre113125, 0\n br i1 %0, label %if.end83, label %ai.if.end76_crit_edge\n\nai.if.end76_crit_edge:\n br label %if.end83\n\nif.end83:\n br label %t\n}",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "clang crashes on valid code at -O{s,2,3} on x86_64-linux-gnu: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed",
"body": "It appears to be a recent regression as it doesn't reproduce with 19.1.0 and earlier.\n\nCompiler Explorer: https://godbolt.org/z/cb67rEodY\n\n```\n[516] % clangtk -v\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git 5208bc3694473f9378fc0d98eeee63e5ad5c5f04)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nCandidate multilib: .;@m64\nSelected multilib: .;@m64\nFound CUDA installation: /usr/local/cuda, version 11.8\n[517] % \n[517] % clangtk -O2 -w small.c\nclang-20: /local/suz-local/software/clangbuild/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::Instruction; From = llvm::Value]: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\nStack dump:\n0.\tProgram arguments: /local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/local/suz-local/software/emitesting/bugs/20241125-clangtk-m64-O3-fpointer-tbaa-build-014338/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20241125-clangtk-m64-O3-fpointer-tbaa-build-014338/delta -resource-dir /local/home/suz/suz-local/software/local/clang-trunk/lib/clang/20 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/home/suz/suz-local/software/local/clang-trunk/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -w -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-99895f.o -x c small.c\n1.\t<eof> parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"small.c\"\n4.\tRunning pass \"slp-vectorizer\" on function \"main\"\n #0 0x0000562e34749b50 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x455db50)\n #1 0x0000562e34746f5f llvm::sys::RunSignalHandlers() (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x455af5f)\n #2 0x0000562e347470b5 SignalHandler(int) Signals.cpp:0:0\n #3 0x00007f99ac5bf520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x00007f99ac613a7c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x96a7c)\n #5 0x00007f99ac5bf476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x00007f99ac5a57f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x00007f99ac5a571b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x00007f99ac5b6e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x0000562e31712868 (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x1526868)\n#10 0x0000562e3616cf4e llvm::slpvectorizer::BoUpSLP::collectValuesToDemote(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, unsigned int&, llvm::SmallVectorImpl<unsigned int>&, llvm::DenseSet<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::DenseMapInfo<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, void>>&, unsigned int&, bool&, bool) const::'lambda9'(unsigned int, unsigned int)::operator()(unsigned int, unsigned int) const::'lambda'(llvm::Value*)::operator()(llvm::Value*) const SLPVectorizer.cpp:0:0\n#11 0x0000562e3616d208 bool llvm::function_ref<bool (unsigned int, unsigned int)>::callback_fn<llvm::slpvectorizer::BoUpSLP::collectValuesToDemote(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, unsigned int&, llvm::SmallVectorImpl<unsigned int>&, llvm::DenseSet<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::DenseMapInfo<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, void>>&, unsigned int&, bool&, bool) const::'lambda9'(unsigned int, unsigned int)>(long, unsigned int, unsigned int) SLPVectorizer.cpp:0:0\n#12 0x0000562e361c72e9 llvm::slpvectorizer::BoUpSLP::collectValuesToDemote(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, unsigned int&, llvm::SmallVectorImpl<unsigned int>&, llvm::DenseSet<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::DenseMapInfo<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, void>>&, unsigned int&, bool&, bool) const::'lambda6'(unsigned int&, llvm::ArrayRef<llvm::slpvectorizer::BoUpSLP::TreeEntry const*>, llvm::function_ref<bool (unsigned int, unsigned int)>)::operator()(unsigned int&, llvm::ArrayRef<llvm::slpvectorizer::BoUpSLP::TreeEntry const*>, llvm::function_ref<bool (unsigned int, unsigned int)>) const SLPVectorizer.cpp:0:0\n#13 0x0000562e361c6065 llvm::slpvectorizer::BoUpSLP::collectValuesToDemote(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, unsigned int&, llvm::SmallVectorImpl<unsigned int>&, llvm::DenseSet<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::DenseMapInfo<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, void>>&, unsigned int&, bool&, bool) const (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5fda065)\n#14 0x0000562e361c6d09 llvm::slpvectorizer::BoUpSLP::computeMinimumValueSizes()::'lambda0'(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, bool, unsigned int, unsigned int, bool, bool)::operator()(llvm::slpvectorizer::BoUpSLP::TreeEntry const&, bool, bool, unsigned int, unsigned int, bool, bool) const SLPVectorizer.cpp:0:0\n#15 0x0000562e361db4e3 llvm::slpvectorizer::BoUpSLP::computeMinimumValueSizes() (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5fef4e3)\n#16 0x0000562e3623dc1e llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x6051c1e)\n#17 0x0000562e362427c0 bool tryToVectorizeSequence<llvm::Value>(llvm::SmallVectorImpl<llvm::Value*>&, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::ArrayRef<llvm::Value*>, bool)>, bool, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\n#18 0x0000562e36244162 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x6058162)\n#19 0x0000562e3624bc96 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\n#20 0x0000562e3624c802 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x6060802)\n#21 0x0000562e35c92cf6 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5aa6cf6)\n#22 0x0000562e340cd78f llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3ee178f)\n#23 0x0000562e31add026 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x18f1026)\n#24 0x0000562e340cbb1b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3edfb1b)\n#25 0x0000562e31adb986 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x18ef986)\n#26 0x0000562e340cc67d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3ee067d)\n#27 0x0000562e349f1d16 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#28 0x0000562e349f566c clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x480966c)\n#29 0x0000562e350be425 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x4ed2425)\n#30 0x0000562e36cf2c7c clang::ParseAST(clang::Sema&, bool, bool) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x6b06c7c)\n#31 0x0000562e3539f2c9 clang::FrontendAction::Execute() (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x51b32c9)\n#32 0x0000562e353190f5 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x512d0f5)\n#33 0x0000562e354836b3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x52976b3)\n#34 0x0000562e316862d1 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x149a2d1)\n#35 0x0000562e3167cc8a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#36 0x0000562e31681067 clang_main(int, char**, llvm::ToolContext const&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x1495067)\n#37 0x0000562e31579a7b main (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x138da7b)\n#38 0x00007f99ac5a6d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#39 0x00007f99ac5a6e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#40 0x0000562e3167c3b5 _start (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x14903b5)\nclangtk: error: unable to execute command: Aborted\nclangtk: error: clang frontend command failed due to signal (use -v to see invocation)\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git 5208bc3694473f9378fc0d98eeee63e5ad5c5f04)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nclangtk: note: diagnostic msg: \n********************\n\nPLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\nPreprocessed source(s) and associated run script(s) are located at:\nclangtk: note: diagnostic msg: /tmp/small-522eca.c\nclangtk: note: diagnostic msg: /tmp/small-522eca.sh\nclangtk: note: diagnostic msg: \n\n********************\n[518] % \n[518] % cat small.c\nstruct {\n int b : 31;\n int c : 6;\n} f, g, j;\nint d, e, h, i, k, l, m, n, o;\nint main() {\n if (m) {\n short q = d;\n if (d)\n r:\n d = q;\n if (0) {\n s:\n t:\n if (h)\n u:\n o = g.c;\n if (n)\n goto v;\n }\n if (n)\n while (g.c) {\n if (e)\n k;\n int w = j.b, a, b = g.c, c = ~b;\n a = f.b;\n if (l) {\n c = 0 % 0;\n goto u;\n }\n if (a)\n goto s;\n l;\n v:\n if (i)\n goto ae;\n if (b)\n j.b = w;\n f.b = a;\n l = c;\n }\n short p = n;\n if (0) {\n ag:\n h = p;\n if (f.b)\n goto t;\n }\n if (j.b) {\n ae:\n e = 0;\n ai:\n if (q)\n goto r;\n }\n }\n if (j.b)\n goto ai;\n if (d)\n goto ag;\n return 0;\n}\n```",
"author": "zhendongsu",
"labels": [
"llvm:SLPVectorizer",
"crash"
],
"comments": []
} | true | null |
106626 | https://github.com/llvm/llvm-project/issues/106626 | crash | e51fc36c385d756ccbc2be8c47c52af207c3aead | 2024-08-29T20:51:42 | [
"llvm/test/Transforms/SLPVectorizer"
] | {
"fix_commit": "cc943a67d114e28c28f561c3b1a48ff2003264ce",
"components": [
"SLPVectorizer"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
[
3237,
3251
]
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
"findLaneForValue"
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit cc943a67d114e28c28f561c3b1a48ff2003264ce
Author: Alexey Bataev <[email protected]>
Date: Thu Aug 29 15:05:09 2024 -0700
[SLP]Fix PR106626: trye several attempts for lookup values, if not found.
If the value is used in Scalar several times, the first attempt to find
its position in the node (if ReuseShuffleIndices and ReorderIndices not
empty) may fail. In this case need to find another copy of the same
value and try again.
Fixes https://github.com/llvm/llvm-project/issues/106626
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 775fa9ba75cf..edb2567fa057 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -3237,15 +3237,25 @@ private:
/// When ReuseReorderShuffleIndices is empty it just returns position of \p
/// V within vector of Scalars. Otherwise, try to remap on its reuse index.
int findLaneForValue(Value *V) const {
- unsigned FoundLane = std::distance(Scalars.begin(), find(Scalars, V));
- assert(FoundLane < Scalars.size() && "Couldn't find extract lane");
- if (!ReorderIndices.empty())
- FoundLane = ReorderIndices[FoundLane];
- assert(FoundLane < Scalars.size() && "Couldn't find extract lane");
- if (!ReuseShuffleIndices.empty()) {
- FoundLane = std::distance(ReuseShuffleIndices.begin(),
- find(ReuseShuffleIndices, FoundLane));
+ unsigned FoundLane = getVectorFactor();
+ for (auto *It = find(Scalars, V), *End = Scalars.end(); It != End;
+ std::advance(It, 1)) {
+ if (*It != V)
+ continue;
+ FoundLane = std::distance(Scalars.begin(), It);
+ assert(FoundLane < Scalars.size() && "Couldn't find extract lane");
+ if (!ReorderIndices.empty())
+ FoundLane = ReorderIndices[FoundLane];
+ assert(FoundLane < Scalars.size() && "Couldn't find extract lane");
+ if (ReuseShuffleIndices.empty())
+ break;
+ if (auto *RIt = find(ReuseShuffleIndices, FoundLane);
+ RIt != ReuseShuffleIndices.end()) {
+ FoundLane = std::distance(ReuseShuffleIndices.begin(), RIt);
+ break;
+ }
}
+ assert(FoundLane < getVectorFactor() && "Unable to find given value.");
return FoundLane;
}
| [
{
"file": "llvm/test/Transforms/SLPVectorizer/AArch64/reused-scalar-repeated-in-node.ll",
"commands": [
"opt -S --passes=slp-vectorizer -mtriple=aarch64-unknown-linux-gnu < %s"
],
"tests": [
{
"test_name": "test",
"test_body": "define void @test() {\nentry:\n br label %bb61\n\nbb61: ; preds = %entry\n br label %bb64\n\nbb62: ; No predecessors!\n br i1 poison, label %bb63, label %bb64\n\nbb63: ; preds = %bb62\n br label %bb64\n\nbb64: ; preds = %bb63, %bb62, %bb61\n %i = phi nsz float [ poison, %bb61 ], [ poison, %bb63 ], [ poison, %bb62 ]\n %i65 = phi nsz float [ poison, %bb61 ], [ poison, %bb63 ], [ poison, %bb62 ]\n %i66 = load float, ptr poison, align 16\n %i67 = load float, ptr poison, align 4\n %i68 = load float, ptr poison, align 8\n %i69 = load float, ptr poison, align 4\n %i70 = load float, ptr poison, align 4\n %i71 = load float, ptr poison, align 16\n %i72 = load float, ptr poison, align 4\n %i73 = load float, ptr poison, align 8\n %i74 = load float, ptr poison, align 4\n %i75 = load float, ptr poison, align 16\n %i76 = load float, ptr poison, align 4\n br i1 poison, label %bb167, label %bb77\n\nbb77: ; preds = %bb64\n br label %bb78\n\nbb78: ; preds = %bb78, %bb77\n %i79 = phi nsz float [ %i66, %bb77 ], [ %i103, %bb78 ]\n %i80 = phi nsz float [ %i67, %bb77 ], [ %i104, %bb78 ]\n %i81 = phi nsz float [ %i68, %bb77 ], [ %i105, %bb78 ]\n %i82 = phi nsz float [ poison, %bb77 ], [ %i106, %bb78 ]\n %i83 = phi nsz float [ poison, %bb77 ], [ %i123, %bb78 ]\n %i84 = phi nsz float [ %i69, %bb77 ], [ %i124, %bb78 ]\n %i85 = phi nsz float [ poison, %bb77 ], [ %i125, %bb78 ]\n %i86 = phi nsz float [ %i70, %bb77 ], [ %i126, %bb78 ]\n %i87 = fmul fast float %i79, poison\n %i88 = fmul fast float %i80, poison\n %i89 = fmul fast float %i81, poison\n %i90 = fmul fast float %i82, poison\n %i91 = fmul fast float %i83, poison\n %i92 = fadd fast float %i91, %i87\n %i93 = fmul fast float %i84, poison\n %i94 = fadd fast float %i93, %i88\n %i95 = fmul fast float %i85, poison\n %i96 = fadd fast float %i95, %i89\n %i97 = fmul fast float %i86, poison\n %i98 = fadd fast float %i97, %i90\n %i99 = fadd fast float %i92, poison\n %i100 = fadd fast float %i94, poison\n %i101 = fadd fast float %i96, poison\n %i102 = fadd fast float %i98, poison\n %i103 = fadd fast float %i99, poison\n %i104 = fadd fast float %i100, poison\n %i105 = fadd fast float %i101, poison\n %i106 = fadd fast float %i102, poison\n %i107 = fmul fast float %i79, poison\n %i108 = fmul fast float %i80, poison\n %i109 = fmul fast float %i81, poison\n %i110 = fmul fast float %i82, poison\n %i111 = fmul fast float %i83, poison\n %i112 = fadd fast float %i111, %i107\n %i113 = fmul fast float %i84, poison\n %i114 = fadd fast float %i113, %i108\n %i115 = fmul fast float %i85, poison\n %i116 = fadd fast float %i115, %i109\n %i117 = fmul fast float %i86, poison\n %i118 = fadd fast float %i117, %i110\n %i119 = fadd fast float %i112, poison\n %i120 = fadd fast float %i114, poison\n %i121 = fadd fast float %i116, poison\n %i122 = fadd fast float %i118, poison\n %i123 = fadd fast float %i119, poison\n %i124 = fadd fast float %i120, poison\n %i125 = fadd fast float %i121, poison\n %i126 = fadd fast float %i122, poison\n %i127 = fmul fast float %i79, %i\n %i128 = fmul fast float %i80, %i\n %i129 = fmul fast float %i81, %i\n %i130 = fmul fast float %i82, %i\n %i131 = fmul fast float %i83, %i65\n %i132 = fadd fast float %i131, %i127\n %i133 = fmul fast float %i84, %i65\n %i134 = fadd fast float %i133, %i128\n %i135 = fmul fast float %i85, %i65\n %i136 = fadd fast float %i135, %i129\n %i137 = fmul fast float %i86, %i65\n %i138 = fadd fast float %i137, %i130\n %i139 = fadd fast float %i132, poison\n %i140 = fadd fast float %i134, poison\n %i141 = fadd fast float %i136, poison\n %i142 = fadd fast float %i138, poison\n %i143 = fadd fast float %i139, poison\n %i144 = fadd fast float %i140, poison\n %i145 = fadd fast float %i141, poison\n %i146 = fadd fast float %i142, poison\n %i147 = fmul fast float %i79, poison\n %i148 = fmul fast float %i80, poison\n %i149 = fmul fast float %i81, poison\n %i150 = fmul fast float %i82, poison\n %i151 = fmul fast float %i83, poison\n %i152 = fadd fast float %i151, %i147\n %i153 = fmul fast float %i84, poison\n %i154 = fadd fast float %i153, %i148\n %i155 = fmul fast float %i85, poison\n %i156 = fadd fast float %i155, %i149\n %i157 = fmul fast float %i86, poison\n %i158 = fadd fast float %i157, %i150\n %i159 = fadd fast float %i152, poison\n %i160 = fadd fast float %i154, poison\n %i161 = fadd fast float %i156, poison\n %i162 = fadd fast float %i158, poison\n %i163 = fadd fast float %i159, poison\n %i164 = fadd fast float %i160, poison\n %i165 = fadd fast float %i161, poison\n %i166 = fadd fast float %i162, poison\n br i1 poison, label %bb78, label %bb167\n\nbb167: ; preds = %bb78, %bb64\n %i168 = phi nsz float [ %i76, %bb64 ], [ %i166, %bb78 ]\n %i169 = phi nsz float [ poison, %bb64 ], [ %i165, %bb78 ]\n %i170 = phi nsz float [ poison, %bb64 ], [ %i164, %bb78 ]\n %i171 = phi nsz float [ %i75, %bb64 ], [ %i163, %bb78 ]\n %i172 = phi nsz float [ %i74, %bb64 ], [ %i146, %bb78 ]\n %i173 = phi nsz float [ %i73, %bb64 ], [ %i145, %bb78 ]\n %i174 = phi nsz float [ %i72, %bb64 ], [ %i144, %bb78 ]\n %i175 = phi nsz float [ %i71, %bb64 ], [ %i143, %bb78 ]\n %i176 = phi nsz float [ %i70, %bb64 ], [ %i126, %bb78 ]\n %i177 = phi nsz float [ poison, %bb64 ], [ %i125, %bb78 ]\n %i178 = phi nsz float [ %i69, %bb64 ], [ %i124, %bb78 ]\n %i179 = phi nsz float [ poison, %bb64 ], [ %i123, %bb78 ]\n %i180 = phi nsz float [ poison, %bb64 ], [ %i106, %bb78 ]\n %i181 = phi nsz float [ %i68, %bb64 ], [ %i105, %bb78 ]\n %i182 = phi nsz float [ %i67, %bb64 ], [ %i104, %bb78 ]\n %i183 = phi nsz float [ %i66, %bb64 ], [ %i103, %bb78 ]\n store float %i182, ptr poison, align 1\n store float %i174, ptr poison, align 1\n br i1 poison, label %bb186, label %bb184\n\nbb184: ; preds = %bb167\n br label %bb185\n\nbb185: ; preds = %bb185, %bb184\n br i1 poison, label %bb185, label %bb186\n\nbb186: ; preds = %bb185, %bb167\n %i187 = phi nsz float [ %i178, %bb167 ], [ poison, %bb185 ]\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[SLP] Assertion \"All elements in mask must be less than CommonVF.\" failed",
"body": "[PR77529](https://github.com/llvm/llvm-project/pull/77529) trigger assertion on \"All elements in mask must be less than CommonVF.\" failed.\r\n\r\n@alexey-bataev \r\n\r\nTo reproduce, run with: opt -S -passes=slp-vectorizer t.ll -o o.ll\r\nUsing reduced t.ll below\r\n```\r\ntarget datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32\"\r\ntarget triple = \"aarch64-unknown-linux-gnu\"\r\n\r\ndefine void @test() {\r\nentry:\r\n br label %bb61\r\n\r\nbb61:\r\n br label %bb64\r\n\r\nbb62:\r\n br i1 poison, label %bb63, label %bb64\r\n\r\nbb63:\r\n br label %bb64\r\n\r\nbb64:\r\n %i = phi nsz float [ poison, %bb61 ], [ poison, %bb63 ], [ poison, %bb62 ]\r\n %i65 = phi nsz float [ poison, %bb61 ], [ poison, %bb63 ], [ poison, %bb62 ]\r\n %i66 = load float, ptr poison, align 16\r\n %i67 = load float, ptr poison, align 4\r\n %i68 = load float, ptr poison, align 8\r\n %i69 = load float, ptr poison, align 4\r\n %i70 = load float, ptr poison, align 4\r\n %i71 = load float, ptr poison, align 16\r\n %i72 = load float, ptr poison, align 4\r\n %i73 = load float, ptr poison, align 8\r\n %i74 = load float, ptr poison, align 4\r\n %i75 = load float, ptr poison, align 16\r\n %i76 = load float, ptr poison, align 4\r\n br i1 poison, label %bb167, label %bb77\r\n\r\nbb77: ; preds = %bb64\r\n br label %bb78\r\n\r\nbb78: ; preds = %bb78, %bb77\r\n %i79 = phi nsz float [ %i66, %bb77 ], [ %i103, %bb78 ]\r\n %i80 = phi nsz float [ %i67, %bb77 ], [ %i104, %bb78 ]\r\n %i81 = phi nsz float [ %i68, %bb77 ], [ %i105, %bb78 ]\r\n %i82 = phi nsz float [ poison, %bb77 ], [ %i106, %bb78 ]\r\n %i83 = phi nsz float [ poison, %bb77 ], [ %i123, %bb78 ]\r\n %i84 = phi nsz float [ %i69, %bb77 ], [ %i124, %bb78 ]\r\n %i85 = phi nsz float [ poison, %bb77 ], [ %i125, %bb78 ]\r\n %i86 = phi nsz float [ %i70, %bb77 ], [ %i126, %bb78 ]\r\n %i87 = fmul fast float %i79, poison\r\n %i88 = fmul fast float %i80, poison\r\n %i89 = fmul fast float %i81, poison\r\n %i90 = fmul fast float %i82, poison\r\n %i91 = fmul fast float %i83, poison\r\n %i92 = fadd fast float %i91, %i87\r\n %i93 = fmul fast float %i84, poison\r\n %i94 = fadd fast float %i93, %i88\r\n %i95 = fmul fast float %i85, poison\r\n %i96 = fadd fast float %i95, %i89\r\n %i97 = fmul fast float %i86, poison\r\n %i98 = fadd fast float %i97, %i90\r\n %i99 = fadd fast float %i92, poison\r\n %i100 = fadd fast float %i94, poison\r\n %i101 = fadd fast float %i96, poison\r\n %i102 = fadd fast float %i98, poison\r\n %i103 = fadd fast float %i99, poison\r\n %i104 = fadd fast float %i100, poison\r\n %i105 = fadd fast float %i101, poison\r\n %i106 = fadd fast float %i102, poison\r\n %i107 = fmul fast float %i79, poison\r\n %i108 = fmul fast float %i80, poison\r\n %i109 = fmul fast float %i81, poison\r\n %i110 = fmul fast float %i82, poison\r\n %i111 = fmul fast float %i83, poison\r\n %i112 = fadd fast float %i111, %i107\r\n %i113 = fmul fast float %i84, poison\r\n %i114 = fadd fast float %i113, %i108\r\n %i115 = fmul fast float %i85, poison\r\n %i116 = fadd fast float %i115, %i109\r\n %i117 = fmul fast float %i86, poison\r\n %i118 = fadd fast float %i117, %i110\r\n %i119 = fadd fast float %i112, poison\r\n %i120 = fadd fast float %i114, poison\r\n %i121 = fadd fast float %i116, poison\r\n %i122 = fadd fast float %i118, poison\r\n %i123 = fadd fast float %i119, poison\r\n %i124 = fadd fast float %i120, poison\r\n %i125 = fadd fast float %i121, poison\r\n %i126 = fadd fast float %i122, poison\r\n %i127 = fmul fast float %i79, %i\r\n %i128 = fmul fast float %i80, %i\r\n %i129 = fmul fast float %i81, %i\r\n %i130 = fmul fast float %i82, %i\r\n %i131 = fmul fast float %i83, %i65\r\n %i132 = fadd fast float %i131, %i127\r\n %i133 = fmul fast float %i84, %i65\r\n %i134 = fadd fast float %i133, %i128\r\n %i135 = fmul fast float %i85, %i65\r\n %i136 = fadd fast float %i135, %i129\r\n %i137 = fmul fast float %i86, %i65\r\n %i138 = fadd fast float %i137, %i130\r\n %i139 = fadd fast float %i132, poison\r\n %i140 = fadd fast float %i134, poison\r\n %i141 = fadd fast float %i136, poison\r\n %i142 = fadd fast float %i138, poison\r\n %i143 = fadd fast float %i139, poison\r\n %i144 = fadd fast float %i140, poison\r\n %i145 = fadd fast float %i141, poison\r\n %i146 = fadd fast float %i142, poison\r\n %i147 = fmul fast float %i79, poison\r\n %i148 = fmul fast float %i80, poison\r\n %i149 = fmul fast float %i81, poison\r\n %i150 = fmul fast float %i82, poison\r\n %i151 = fmul fast float %i83, poison\r\n %i152 = fadd fast float %i151, %i147\r\n %i153 = fmul fast float %i84, poison\r\n %i154 = fadd fast float %i153, %i148\r\n %i155 = fmul fast float %i85, poison\r\n %i156 = fadd fast float %i155, %i149\r\n %i157 = fmul fast float %i86, poison\r\n %i158 = fadd fast float %i157, %i150\r\n %i159 = fadd fast float %i152, poison\r\n %i160 = fadd fast float %i154, poison\r\n %i161 = fadd fast float %i156, poison\r\n %i162 = fadd fast float %i158, poison\r\n %i163 = fadd fast float %i159, poison\r\n %i164 = fadd fast float %i160, poison\r\n %i165 = fadd fast float %i161, poison\r\n %i166 = fadd fast float %i162, poison\r\n br i1 poison, label %bb78, label %bb167\r\n\r\nbb167: ; preds = %bb78, %bb64\r\n %i168 = phi nsz float [ %i76, %bb64 ], [ %i166, %bb78 ]\r\n %i169 = phi nsz float [ poison, %bb64 ], [ %i165, %bb78 ]\r\n %i170 = phi nsz float [ poison, %bb64 ], [ %i164, %bb78 ]\r\n %i171 = phi nsz float [ %i75, %bb64 ], [ %i163, %bb78 ]\r\n %i172 = phi nsz float [ %i74, %bb64 ], [ %i146, %bb78 ]\r\n %i173 = phi nsz float [ %i73, %bb64 ], [ %i145, %bb78 ]\r\n %i174 = phi nsz float [ %i72, %bb64 ], [ %i144, %bb78 ]\r\n %i175 = phi nsz float [ %i71, %bb64 ], [ %i143, %bb78 ]\r\n %i176 = phi nsz float [ %i70, %bb64 ], [ %i126, %bb78 ]\r\n %i177 = phi nsz float [ poison, %bb64 ], [ %i125, %bb78 ]\r\n %i178 = phi nsz float [ %i69, %bb64 ], [ %i124, %bb78 ]\r\n %i179 = phi nsz float [ poison, %bb64 ], [ %i123, %bb78 ]\r\n %i180 = phi nsz float [ poison, %bb64 ], [ %i106, %bb78 ]\r\n %i181 = phi nsz float [ %i68, %bb64 ], [ %i105, %bb78 ]\r\n %i182 = phi nsz float [ %i67, %bb64 ], [ %i104, %bb78 ]\r\n %i183 = phi nsz float [ %i66, %bb64 ], [ %i103, %bb78 ]\r\n store float %i182, ptr poison, align 1\r\n store float %i174, ptr poison, align 1\r\n br i1 poison, label %bb186, label %bb184\r\n\r\nbb184: ; preds = %bb167\r\n br label %bb185\r\n\r\nbb185: ; preds = %bb185, %bb184\r\n br i1 poison, label %bb185, label %bb186\r\n\r\nbb186: ; preds = %bb185, %bb167\r\n %i187 = phi nsz float [ %i178, %bb167 ], [ poison, %bb185 ]\r\n ret void\r\n}\r\n```",
"author": "huihzhang",
"labels": [
"llvm:SLPVectorizer",
"crash"
],
"comments": []
} | true | null |
77064 | https://github.com/llvm/llvm-project/issues/77064 | crash | 255f95a40377677dd762df5a1aa65bcbb4f75c79 | 2024-01-05T09:28:42 | [
"llvm/test/Transforms/InstCombine"
] | {
"fix_commit": "a001e9718fd974859f2797a9f9ed7bf87d364e4f",
"components": [
"SimplifyLibCalls"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": [
[
3735,
3760
]
],
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": [
"LibCallSimplifier::optimizeCall"
],
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit a001e9718fd974859f2797a9f9ed7bf87d364e4f
Author: Nikita Popov <[email protected]>
Date: Fri Jan 5 10:41:44 2024 +0100
[SimplifyLibCalls] Don't try to manually reprocess calls
The current code for reprocessing the result of fortified libcall
simplifications is not correct, because we might simplify to an
argument of the original call, and if that is again a libcall,
mistakenly think that this is actually the simplification result.
Instead of trying to fix this, simply remove the code entirely,
because InstCombine nowadays correctly handles reprocessing of
SimplifyLibCall results.
Fixes https://github.com/llvm/llvm-project/issues/77064.
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 760a626c8b6f..a7cd68e860e4 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -3735,26 +3735,8 @@ Value *LibCallSimplifier::optimizeCall(CallInst *CI, IRBuilderBase &Builder) {
// Also try to simplify calls to fortified library functions.
if (Value *SimplifiedFortifiedCI =
- FortifiedSimplifier.optimizeCall(CI, Builder)) {
- // Try to further simplify the result.
- CallInst *SimplifiedCI = dyn_cast<CallInst>(SimplifiedFortifiedCI);
- if (SimplifiedCI && SimplifiedCI->getCalledFunction()) {
- // Ensure that SimplifiedCI's uses are complete, since some calls have
- // their uses analyzed.
- replaceAllUsesWith(CI, SimplifiedCI);
-
- // Set insertion point to SimplifiedCI to guarantee we reach all uses
- // we might replace later on.
- IRBuilderBase::InsertPointGuard Guard(Builder);
- Builder.SetInsertPoint(SimplifiedCI);
- if (Value *V = optimizeStringMemoryLibCall(SimplifiedCI, Builder)) {
- // If we were able to further simplify, remove the now redundant call.
- substituteInParent(SimplifiedCI, V);
- return V;
- }
- }
+ FortifiedSimplifier.optimizeCall(CI, Builder))
return SimplifiedFortifiedCI;
- }
// Then check for known library functions.
if (TLI->getLibFunc(*Callee, Func) && isLibFuncEmittable(M, TLI, Func)) {
| [
{
"file": "llvm/test/Transforms/InstCombine/pr77064.ll",
"commands": [
"opt -S -passes=instcombine < %s"
],
"tests": [
{
"test_name": "main",
"test_body": "define void @main(ptr %ptr) {\n %opendir = call fastcc ptr @opendir(ptr %ptr)\n %memset = call ptr @__memset_chk(ptr %opendir, i32 0, i64 596, i64 -1)\n ret void\n}\n\ndeclare ptr @__memset_chk(ptr, i32, i64, i64)\n\ndeclare fastcc ptr @opendir(ptr)\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[SimplifyLibCalls] Calling convention assertion fails",
"body": "```llvm\r\n; RUN: opt -S -passes=instcombine\r\ndefine void @main(ptr %ptr) {\r\n %opendir = call fastcc ptr @opendir(ptr %ptr)\r\n %memset = call ptr @__memset_chk(ptr %opendir, i32 0, i64 596, i64 -1)\r\n ret void\r\n}\r\n\r\ndeclare ptr @__memset_chk(ptr, i32, i64, i64)\r\n\r\ndeclare fastcc ptr @opendir(ptr)\r\n```\r\n\r\n> opt: /home/npopov/repos/llvm-project/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp:3488: Value *llvm::LibCallSimplifier::optimizeStringMemoryLibCall(CallInst *, IRBuilderBase &): Assertion `(ignoreCallingConv(Func) || TargetLibraryInfoImpl::isCallingConvCCompatible(CI)) && \"Optimizing string/memory libcall would change the calling convention\"' failed.\r\n\r\nEncountered when building openjpeg2.",
"author": "nikic",
"labels": [
"llvm:crash",
"llvm:instcombine"
],
"comments": []
} | true | null |
93298 | https://github.com/llvm/llvm-project/issues/93298 | crash | f31b197d9df141effd439de8be51ce24f3e8f200 | 2024-05-24T12:01:44 | [
"llvm/test/Transforms/DeadStoreElimination"
] | {
"fix_commit": "243ffbdf8b25285d04ee4393e86094312cb7c64f",
"components": [
"DeadStoreElimination"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": [
[
2109,
2118
]
],
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": [
"eliminateRedundantStoresOfExistingValues"
],
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 243ffbdf8b25285d04ee4393e86094312cb7c64f
Author: eaeltsin <[email protected]>
Date: Mon May 27 09:26:44 2024 +0200
[DSE] Check write location in IsRedundantStore (#93400)
Fix https://github.com/llvm/llvm-project/issues/93298.
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index ed4212d29cef..172cce2cfa38 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -2109,10 +2109,12 @@ struct DSEState {
if (auto *MemSetI = dyn_cast<MemSetInst>(UpperInst)) {
if (auto *SI = dyn_cast<StoreInst>(DefInst)) {
// MemSetInst must have a write location.
- MemoryLocation UpperLoc = *getLocForWrite(UpperInst);
+ auto UpperLoc = getLocForWrite(UpperInst);
+ if (!UpperLoc)
+ return false;
int64_t InstWriteOffset = 0;
int64_t DepWriteOffset = 0;
- auto OR = isOverwrite(UpperInst, DefInst, UpperLoc, *MaybeDefLoc,
+ auto OR = isOverwrite(UpperInst, DefInst, *UpperLoc, *MaybeDefLoc,
InstWriteOffset, DepWriteOffset);
Value *StoredByte = isBytewiseValue(SI->getValueOperand(), DL);
return StoredByte && StoredByte == MemSetI->getOperand(1) &&
| [
{
"file": "llvm/test/Transforms/DeadStoreElimination/simple.ll",
"commands": [
"opt < %s -passes=dse -S",
"opt < %s -aa-pipeline=basic-aa -passes=dse -S"
],
"tests": [
{
"test_name": "test48",
"test_body": "target datalayout = \"E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128\"\n\ndefine i32 @test48(ptr %P, ptr noalias %Q, ptr %R) {\n store i32 1, ptr %Q, align 4\n store i32 2, ptr %P, align 4\n store i32 3, ptr %Q, align 4\n %l = load i32, ptr %R, align 4\n ret i32 %l\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "test49",
"test_body": "target datalayout = \"E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128\"\n\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)\ndeclare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0\n\ndefine void @test49() {\nbb:\n call void @llvm.memset.p0.i64(ptr readonly null, i8 0, i64 0, i1 false)\n store ptr null, ptr null, align 8\n ret void\n}\n\nattributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[DSE] crash on applying * to std::nullopt",
"body": "[reduced5.zip](https://github.com/llvm/llvm-project/files/15433764/reduced5.zip)\r\n\r\nThe command\r\n```\r\nopt -passes=dse reduced5.ll\r\n```\r\nfails occasionally. Debug version reliably complains\r\n```\r\ninclude/c++/v1/optional:805: assertion this->has_value() failed: optional operator* called on a disengaged value\r\n```\r\nwith stack trace\r\n```\r\n frame #3: 0x00005555663c6a43 opt`std::__u::optional<llvm::MemoryLocation>::operator*(this= Has Value=false ) && at optional:805:5\r\n frame #4: 0x00005555663c4d58 opt`(anonymous namespace)::DSEState::eliminateRedundantStoresOfExistingValues(this=0x00007fffffff9130)::'lambda'()::operator()() const at DeadStoreElimination.cpp:2119:39\r\n frame #5: 0x00005555663bf842 opt`(anonymous namespace)::DSEState::eliminateRedundantStoresOfExistingValues(this=0x00007fffffff9960) at DeadStoreElimination.cpp:2132:12\r\n frame #6: 0x00005555663b8956 opt`(anonymous namespace)::eliminateDeadStores(F=0x000033187fe3e008, AA=0x000033187feaafc8, MSSA=0x000033187fe603f0, DT=0x000033187fef6d78, PDT=0x000033187fed18d0, TLI=0x000033187fe0cd18, LI=0x000033187fe11cc8) at DeadStoreElimination.cpp:2332:23\r\n frame #7: 0x00005555663b6b3e opt`llvm::DSEPass::run(this=0x000033187fe08ad8, F=0x000033187fe3e008, AM=0x00007fffffffc1d8) at DeadStoreElimination.cpp:2355:18\r\n```\r\n\r\nThe local fix is\r\n```\r\n==== llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp#184\r\n# action=edit type=text\r\n--- llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp\t2024-04-15 20:27:56.000000000 -0700\r\n+++ llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp\t2024-05-24 04:36:17.000000000 -0700\r\n@@ -2109,10 +2109,12 @@\r\n if (auto *MemSetI = dyn_cast<MemSetInst>(UpperInst)) {\r\n if (auto *SI = dyn_cast<StoreInst>(DefInst)) {\r\n // MemSetInst must have a write location.\r\n- MemoryLocation UpperLoc = *getLocForWrite(UpperInst);\r\n+ auto UpperLoc = getLocForWrite(UpperInst);\r\n+ if (!UpperLoc)\r\n+ return false;\r\n int64_t InstWriteOffset = 0;\r\n int64_t DepWriteOffset = 0;\r\n- auto OR = isOverwrite(UpperInst, DefInst, UpperLoc, *MaybeDefLoc,\r\n+ auto OR = isOverwrite(UpperInst, DefInst, *UpperLoc, *MaybeDefLoc,\r\n InstWriteOffset, DepWriteOffset);\r\n Value *StoredByte = isBytewiseValue(SI->getValueOperand(), DL);\r\n return StoredByte && StoredByte == MemSetI->getOperand(1) &&\r\n```\r\nwhich basically reverts a piece of https://github.com/llvm/llvm-project/commit/81d69e1bda9e4b6a83f29ba1f614e43ab4700972\r\n\r\nLooks like the actual problem happened earlier?\r\n\r\nPlease take a look, this is blocking us significantly.\r\n\r\n",
"author": "eaeltsin",
"labels": [
"crash",
"llvm:transforms"
],
"comments": [
{
"author": "eaeltsin",
"body": "@nikic @fhahn FYI\r\n\r\nthe reproducer was cooked by @alinas \r\n"
}
]
} | true | null |
121897 | https://github.com/llvm/llvm-project/issues/121897 | crash | 3b19e787fc5da27dfcc9ac6552b06a763f12ea03 | 2025-01-07T08:06:43 | [
"llvm/test/Transforms/LoopVectorize"
] | {
"fix_commit": "0eaa69eb234798774a08743b64a9aa0cf71c5356",
"components": [
"LoopVectorize"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": [
[
49,
55
]
],
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": [
"isUniformAfterVectorization"
],
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 0eaa69eb234798774a08743b64a9aa0cf71c5356
Author: Florian Hahn <[email protected]>
Date: Tue Jan 7 21:26:40 2025 +0000
[VPlan] Handle VPExpandSCEVRecipe in isUniformAfterVectorization.
VPExpandSCEVRecipes must be placed in the entry and are alway uniform.
This fixes a crash by always identifying them as uniform, even if the
main vector loop region has been removed.
Fixes https://github.com/llvm/llvm-project/issues/121897.
diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.h b/llvm/lib/Transforms/Vectorize/VPlanUtils.h
index 965777002052..777944264f45 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanUtils.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.h
@@ -49,7 +49,8 @@ inline bool isUniformAfterVectorization(const VPValue *VPV) {
return all_of(GEP->operands(), isUniformAfterVectorization);
if (auto *VPI = dyn_cast<VPInstruction>(Def))
return VPI->isSingleScalar() || VPI->isVectorToScalar();
- return false;
+ // VPExpandSCEVRecipes must be placed in the entry and are alway uniform.
+ return isa<VPExpandSCEVRecipe>(Def);
}
/// Return true if \p V is a header mask in \p Plan.
| [
{
"file": "llvm/test/Transforms/LoopVectorize/vector-loop-backedge-elimination.ll",
"commands": [
"opt -passes='loop-vectorize,verify<loops>' -force-vector-width=8 -force-vector-interleave=1 -S %s",
"opt -passes='loop-vectorize,verify<loops>' -force-vector-width=8 -force-vector-interleave=2 -S %s",
"opt -passes='loop-vectorize,verify<loops>' -force-vector-width=16 -force-vector-interleave=1 -S %s"
],
"tests": [
{
"test_name": "scev_expand_step",
"test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\n\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)\ndeclare void @llvm.assume(i1 noundef) #0\n\ndefine void @scev_expand_step(i64 %x, ptr %dst) {\nentry:\n %c = icmp eq i64 %x, 65536\n call void @llvm.assume(i1 %c)\n %fr = freeze i64 %x\n %step = add i64 %fr, -65534\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.next = add i64 %iv, %step\n %gep.dst = getelementptr i8, ptr %dst, i64 %iv.next\n store i8 0, ptr %gep.dst, align 1\n %ec = icmp slt i64 %iv.next, 16\n br i1 %ec, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "remove_loop_region_outer_loop",
"test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\n\ndeclare i1 @cond()\n\ndefine void @remove_loop_region_outer_loop(i64 range(i64 8, 17) %N, ptr noalias %src, ptr %dst) {\nentry:\n br label %outer.header\n\nouter.header: ; preds = %outer.latch, %entry\n %outer.iv = phi ptr [ %src, %entry ], [ %outer.iv.next, %outer.latch ]\n br label %inner\n\ninner: ; preds = %inner, %outer.header\n %inner.iv = phi i64 [ 0, %outer.header ], [ %iv.next, %inner ]\n %gep.src = getelementptr i8, ptr %outer.iv, i64 %inner.iv\n %l = load i8, ptr %gep.src, align 1\n %gep.dst = getelementptr i8, ptr %dst, i64 %inner.iv\n store i8 %l, ptr %gep.dst, align 1\n %iv.next = add i64 %inner.iv, 1\n %c.1 = icmp eq i64 %iv.next, %N\n br i1 %c.1, label %outer.latch, label %inner\n\nouter.latch: ; preds = %inner\n %outer.iv.next = getelementptr i8, ptr %outer.iv, i64 1\n %c.2 = call i1 @cond()\n br i1 %c.2, label %outer.header, label %exit\n\nexit: ; preds = %outer.latch\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "remove_loop_region_with_replicate_recipe",
"test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\n\ndefine void @remove_loop_region_with_replicate_recipe(ptr %dst, i64 range(i64 5, 10) %N) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 2, %entry ], [ %iv.next, %loop ]\n %gep.dst = getelementptr i16, ptr %dst, i64 %iv\n store i16 0, ptr %gep.dst, align 2\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, %N\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "test_tc_less_than_16",
"test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\n\ndefine void @test_tc_less_than_16(ptr %A, i64 %N) {\nentry:\n %and = and i64 %N, 15\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ %and, %entry ], [ %iv.next, %loop ]\n %p.src = phi ptr [ %A, %entry ], [ %p.src.next, %loop ]\n %p.src.next = getelementptr inbounds i8, ptr %p.src, i64 1\n %l = load i8, ptr %p.src, align 1\n %add = add nsw i8 %l, 10\n store i8 %add, ptr %p.src, align 1\n %iv.next = add nsw i64 %iv, -1\n %cmp = icmp eq i64 %iv.next, 0\n br i1 %cmp, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[clang] Crash at -O3: Assertion `hasVectorValue(Def)' failed.",
"body": "This code crashes at `-O3`:\n\n```c\nint *a;\nint b, d;\nstatic int f = 65535;\nchar c[];\nint h(int i) {\n int g = 1;\n for (; b;)\n if (a[0]) {\n g = 0;\n break;\n }\n if (g)\n a;\n else if (i)\n return 1;\n return 0;\n}\nvoid k() {\n int *e[10] = {&f};\n for (;;) {\n d = 0;\n for (; d < 8; d = f - 65535 + d + 1) {\n int j = h(f);\n c[j + f - 65534 + d] = 0;\n }\n }\n}\nvoid main() {}\n```\n\nCompiler Explorer: https://godbolt.org/z/rcGqsE196 \n\nBisected to https://github.com/llvm/llvm-project/commit/f48884ded884d982a7fd13394b0e93e6588f4143, which was comitted by @fhahn \n\nCrash:\n\n```console\nclang: /root/llvm-project/llvm/lib/Transforms/Vectorize/VPlan.cpp:236: llvm::Value* llvm::VPTransformState::get(llvm::VPValue*, const llvm::VPLane&): Assertion `hasVectorValue(Def)' failed.\n```\n\nBacktrace:\n\n```console\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O3 <source>\n1.\t<eof> parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function<eager-inv>(float2int,lower-constant-intrinsics,chr,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O3>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"<source>\"\n4.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"k\"\n #0 0x0000000003c71738 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c71738)\n #1 0x0000000003c6f444 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3c6f444)\n #2 0x0000000003bbc988 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\n #3 0x000077fbea242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x000077fbea2969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #5 0x000077fbea242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x000077fbea2287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x000077fbea22871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x000077fbea239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x00000000058fd2be llvm::VPTransformState::get(llvm::VPValue*, llvm::VPLane const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x58fd2be)\n#10 0x0000000005790d0d llvm::InnerLoopVectorizer::scalarizeInstruction(llvm::Instruction const*, llvm::VPReplicateRecipe*, llvm::VPLane const&, llvm::VPTransformState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5790d0d)\n#11 0x00000000057916d0 llvm::VPReplicateRecipe::execute(llvm::VPTransformState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x57916d0)\n#12 0x00000000058e3ce7 llvm::VPBasicBlock::executeRecipes(llvm::VPTransformState*, llvm::BasicBlock*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x58e3ce7)\n#13 0x00000000058ef282 llvm::VPBasicBlock::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x58ef282)\n#14 0x00000000058f0ef1 llvm::VPRegionBlock::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x58f0ef1)\n#15 0x00000000058fddb1 llvm::VPlan::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x58fddb1)\n#16 0x00000000057be1eb llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*, bool, llvm::DenseMap<llvm::SCEV const*, llvm::Value*, llvm::DenseMapInfo<llvm::SCEV const*, void>, llvm::detail::DenseMapPair<llvm::SCEV const*, llvm::Value*>> const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x57be1eb)\n#17 0x00000000057d24c3 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x57d24c3)\n#18 0x00000000057d3e19 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x57d3e19)\n#19 0x00000000057d4453 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x57d4453)\n#20 0x00000000052f765e llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x52f765e)\n#21 0x000000000361c6e0 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x361c6e0)\n#22 0x00000000011305ce llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x11305ce)\n#23 0x000000000361affb llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x361affb)\n#24 0x000000000112fc5e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x112fc5e)\n#25 0x000000000361aa00 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x361aa00)\n#26 0x0000000003f247bf (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#27 0x0000000003f28335 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f28335)\n#28 0x000000000460209e clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x460209e)\n#29 0x000000000660f9cc clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x660f9cc)\n#30 0x0000000004602478 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4602478)\n#31 0x00000000048be799 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48be799)\n#32 0x0000000004840e2e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4840e2e)\n#33 0x00000000049abb8e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x49abb8e)\n#34 0x0000000000ce93ef cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xce93ef)\n#35 0x0000000000ce0e8a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#36 0x0000000004647ae9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\n#37 0x0000000003bbce34 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3bbce34)\n#38 0x00000000046480df clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\n#39 0x000000000460c1ed clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x460c1ed)\n#40 0x000000000460d26e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x460d26e)\n#41 0x0000000004614d95 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4614d95)\n#42 0x0000000000ce6233 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xce6233)\n#43 0x0000000000bb2524 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xbb2524)\n#44 0x000077fbea229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#45 0x000077fbea229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#46 0x0000000000ce0935 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xce0935)\n```",
"author": "cardigan1008",
"labels": [
"vectorizers",
"crash-on-valid"
],
"comments": [
{
"author": "fhahn",
"body": "Reduced repro:\n\n```\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @k() {\nentry:\n %.fr = freeze i32 65535\n %invariant.op = add i32 %.fr, -65534\n br label %for.cond.us\n\nfor.cond.us: ; preds = %for.body.us.us, %entry\n br label %for.body.us.us\n\nfor.body.us.us: ; preds = %for.body.us.us, %for.cond.us\n %storemerge7.us.us = phi i32 [ 0, %for.cond.us ], [ %sub.reass.us.us, %for.body.us.us ]\n %sub.reass.us.us = add i32 %storemerge7.us.us, %invariant.op\n %idxprom.us.us = sext i32 %sub.reass.us.us to i64\n %arrayidx.us.us = getelementptr [0 x i8], ptr null, i64 0, i64 %idxprom.us.us\n store i8 0, ptr %arrayidx.us.us, align 1\n %cmp.us.us = icmp slt i32 %sub.reass.us.us, 8\n br i1 %cmp.us.us, label %for.body.us.us, label %for.cond.us\n}\n```"
}
]
} | true | null |
110787 | https://github.com/llvm/llvm-project/issues/110787 | crash | 8805ff72a04308562ea9e962415d238dd356be69 | 2024-10-02T04:16:44 | [
"llvm/test/Transforms/SLPVectorizer"
] | {
"fix_commit": "4dede756f25b153a81ea883ef84064f5a1eaaec2",
"components": [
"SLPVectorizer"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
[
18848,
18853
],
[
18877,
18883
]
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
"tryToReduce"
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 4dede756f25b153a81ea883ef84064f5a1eaaec2
Author: Alexey Bataev <[email protected]>
Date: Wed Oct 2 05:50:20 2024 -0700
[SLP]Transform nodes before building externally used values
transformNodes function may create new vector nodes, so the reduced
values might be vectorized later. Need to build the list of the
externally used values after the transformNodes() function call to avoid
compiler crash.
Fixe #110787
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 15e798bd6c98..ce1e5753c0c8 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -18848,6 +18848,7 @@ public:
++SameValuesCounter.try_emplace(OrigV).first->second;
}
}
+ V.transformNodes();
SmallPtrSet<Value *, 4> VLScalars(VL.begin(), VL.end());
// Gather externally used values.
SmallPtrSet<Value *, 4> Visited;
@@ -18877,7 +18878,6 @@ public:
for (Value *RdxVal : VL)
if (RequiredExtract.contains(RdxVal))
LocalExternallyUsedValues[RdxVal];
- V.transformNodes();
V.buildExternalUses(LocalExternallyUsedValues);
V.computeMinimumValueSizes();
| [
{
"file": "llvm/test/Transforms/SLPVectorizer/X86/reduced-val-vectorized-in-transform.ll",
"commands": [
"opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s"
],
"tests": [
{
"test_name": "test",
"test_body": "define i32 @test(i1 %cond) {\nentry:\n br label %bb\n\nbb: ; preds = %bb, %entry\n %p1 = phi i32 [ %or92, %bb ], [ 0, %entry ]\n %p2 = phi i32 [ %0, %bb ], [ 0, %entry ]\n %p3 = phi i32 [ %4, %bb ], [ 0, %entry ]\n %0 = or i32 1, 0\n %or8.i = or i32 0, 0\n %or9.i = or i32 0, 0\n %or91 = or i32 %p1, 0\n %or12.i = or i32 %p2, 0\n %or92 = or i32 1, 0\n %1 = xor i32 %or91, %or12.i\n %2 = xor i32 %1, %or9.i\n %3 = xor i32 %2, %or8.i\n %4 = xor i32 %3, %or92\n br i1 %cond, label %exit, label %bb\n\nexit: ; preds = %bb\n ret i32 %4\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[SLPVectorizer] Assertion `(I->use_empty() || all_of(I->uses(), [&](Use &U) { return isDeleted( cast<Instruction>(U.getUser())); })) && \"trying to erase instruction with users.\"' failed.",
"body": "Reproducer: https://godbolt.org/z/b8cz56M9z\r\n```\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine i32 @test(i1 %cond) {\r\nentry:\r\n br label %for.end14.i.i.i.us.i\r\n\r\nfor.end14.i.i.i.us.i:\r\n %.promoted10921110.i.i.i.us.i = phi i32 [ %inc229.1.2.i.i.i.us.us.12.i, %for.end14.i.i.i.us.i ], [ 0, %entry ]\r\n %.promoted1106.i.i.i.us.i = phi i32 [ %0, %for.end14.i.i.i.us.i ], [ 0, %entry ]\r\n %g_276.promoted956960.i.i.i.us.i = phi i32 [ %4, %for.end14.i.i.i.us.i ], [ 0, %entry ]\r\n %0 = or i32 1, 0\r\n %inc229.1974.i.i.i.us.us.8.i = or i32 0, 0\r\n %inc229.1974.i.i.i.us.us.9.i = or i32 0, 0\r\n %inc229.1.2.i.i.i.us.us.9.i = or i32 %.promoted10921110.i.i.i.us.i, 0\r\n %inc229.1974.i.i.i.us.us.12.i = or i32 %.promoted1106.i.i.i.us.i, 0\r\n %inc229.1.2.i.i.i.us.us.12.i = or i32 1, 0\r\n %1 = xor i32 %inc229.1.2.i.i.i.us.us.9.i, %inc229.1974.i.i.i.us.us.12.i\r\n %2 = xor i32 %1, %inc229.1974.i.i.i.us.us.9.i\r\n %3 = xor i32 %2, %inc229.1974.i.i.i.us.us.8.i\r\n %4 = xor i32 %3, %inc229.1.2.i.i.i.us.us.12.i\r\n br i1 %cond, label %exit, label %for.end14.i.i.i.us.i\r\n\r\nexit:\r\n ret i32 %4\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:2720: void llvm::slpvectorizer::BoUpSLP::removeInstructionsAndOperands(llvm::ArrayRef<U*>) [with T = llvm::Instruction]: Assertion `(I->use_empty() || all_of(I->uses(), [&](Use &U) { return isDeleted( cast<Instruction>(U.getUser())); })) && \"trying to erase instruction with users.\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=slp-vectorizer <source>\r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"test\"\r\n #0 0x000000000507e338 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x507e338)\r\n #1 0x000000000507bcec SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f54a0842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007f54a08969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007f54a0842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007f54a08287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007f54a082871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007f54a0839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000004102d6f void llvm::slpvectorizer::BoUpSLP::removeInstructionsAndOperands<llvm::Instruction>(llvm::ArrayRef<llvm::Instruction*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4102d6f)\r\n #9 0x000000000415dea2 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::MapVector<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u>, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, llvm::SmallVector<std::pair<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u>>, 0u>> const&, llvm::Instruction*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x415dea2)\r\n#10 0x0000000004167819 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#11 0x000000000416a302 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x416a302)\r\n#12 0x000000000416ebb8 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x416ebb8)\r\n#13 0x0000000004172da1 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4172da1)\r\n#14 0x00000000041796b1 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\r\n#15 0x000000000417a33b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x417a33b)\r\n#16 0x0000000002f33c8e llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f33c8e)\r\n#17 0x0000000004e81158 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e81158)\r\n#18 0x0000000000e15bde llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe15bde)\r\n#19 0x0000000004e7fb7e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7fb7e)\r\n#20 0x0000000000e1538e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe1538e)\r\n#21 0x0000000004e7f5b0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7f5b0)\r\n#22 0x0000000000904102 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x904102)\r\n#23 0x00000000008f6f8c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8f6f8c)\r\n#24 0x00007f54a0829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#25 0x00007f54a0829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#26 0x00000000008eea5e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8eea5e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\nllvm version: e379094328e49731a606304f7e3559d4f1fa96f9",
"author": "dtcxzyw",
"labels": [
"llvm:SLPVectorizer",
"crash-on-valid"
],
"comments": [
{
"author": "alexey-bataev",
"body": "Fixed in 4dede756f25b153a81ea883ef84064f5a1eaaec2"
}
]
} | true | null |
122496 | https://github.com/llvm/llvm-project/issues/122496 | miscompilation | b4ce29ab31b29ca926704c160e3909298ddf2b2b | 2025-01-10T16:59:46 | [
"llvm/test/Transforms/LoopVectorize"
] | {
"fix_commit": "8df64ed77727ab9b7540819f2fe64379e88a50be",
"components": [
"LoopVectorize"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
[
3806,
3812
]
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [
[
621,
648
]
],
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
"LoopVectorizationCostModel::collectLoopUniforms"
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [
"legalizeAndOptimizeInductions"
],
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 8df64ed77727ab9b7540819f2fe64379e88a50be
Author: Florian Hahn <[email protected]>
Date: Sun Jan 12 22:03:21 2025 +0000
[LV] Don't consider IV increments uniform if exit value is used outside.
In some cases, there might be a chain of uniform instructions producing
the exit value. To generate correct code in all cases, consider the IV
increment not uniform, if there are users outside the loop.
Instead, let VPlan narrow the IV, if possible using the logic from
3ff1d01985752.
Test case from #122602 verified with Alive2:
https://alive2.llvm.org/ce/z/bA4EGj
Fixes https://github.com/llvm/llvm-project/issues/122496.
Fixes https://github.com/llvm/llvm-project/issues/122602.
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index b017b61a45a0..d32a463a996c 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -3806,7 +3806,7 @@ void LoopVectorizationCostModel::collectLoopUniforms(ElementCount VF) {
// uniform after vectorization.
bool UniformIndUpdate = all_of(IndUpdate->users(), [&](User *U) -> bool {
auto *I = cast<Instruction>(U);
- return I == Ind || !TheLoop->contains(I) || Worklist.count(I) ||
+ return I == Ind || Worklist.count(I) ||
IsVectorizedMemAccessUse(I, IndUpdate);
});
if (!UniformIndUpdate)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index f440bf2eb022..545d277d7aa0 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -621,28 +621,6 @@ static void legalizeAndOptimizeInductions(VPlan &Plan) {
Def->replaceAllUsesWith(Clone);
}
- // Check if any uniform VPReplicateRecipes using the phi recipe are used by
- // ExtractFromEnd. Those must be replaced by a regular VPReplicateRecipe to
- // ensure the final value is available.
- // TODO: Remove once uniformity analysis is done on VPlan.
- for (VPUser *U : Users) {
- auto *ExitIRI = dyn_cast<VPIRInstruction>(U);
- VPValue *Op;
- if (!ExitIRI || !match(ExitIRI->getOperand(0),
- m_VPInstruction<VPInstruction::ExtractFromEnd>(
- m_VPValue(Op), m_VPValue())))
- continue;
- auto *RepR = dyn_cast<VPReplicateRecipe>(Op);
- if (!RepR || !RepR->isUniform())
- continue;
- assert(!RepR->isPredicated() && "RepR must not be predicated");
- Instruction *I = RepR->getUnderlyingInstr();
- auto *Clone =
- new VPReplicateRecipe(I, RepR->operands(), /*IsUniform*/ false);
- Clone->insertAfter(RepR);
- RepR->replaceAllUsesWith(Clone);
- }
-
// Replace wide pointer inductions which have only their scalars used by
// PtrAdd(IndStart, ScalarIVSteps (0, Step)).
if (auto *PtrIV = dyn_cast<VPWidenPointerInductionRecipe>(&Phi)) {
| [
{
"file": "<issue>",
"commands": [
"opt -passes=loop-vectorize -S %s"
],
"tests": [
{
"test_name": "<module>",
"test_body": "; bin/opt -passes=loop-vectorize test.ll -S\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@f = global [8 x [1 x i32]] zeroinitializer\n\ndefine i32 @main() {\nentry:\n br label %for.body6.i\n\nfor.body6.i: ; preds = %for.body6.i, %entry\n %conv34.i = phi i32 [ %conv.i, %for.body6.i ], [ 0, %entry ]\n %storemerge3133.i = phi i16 [ %inc.i, %for.body6.i ], [ 0, %entry ]\n %idxprom.i = zext i32 %conv34.i to i64\n %arrayidx.i = getelementptr [8 x [1 x i32]], ptr @f, i64 0, i64 %idxprom.i\n store i32 0, ptr %arrayidx.i, align 4\n %inc.i = add i16 %storemerge3133.i, 1\n %conv.i = zext i16 %inc.i to i32\n %cmp4.i = icmp ult i16 %storemerge3133.i, 3\n br i1 %cmp4.i, label %for.body6.i, label %for.cond11thread-pre-split.i\n\nfor.cond11thread-pre-split.i: ; preds = %for.body6.i\n %0 = add i32 %conv.i, -9\n %cmp24.i = icmp ult i32 %0, -6\n br i1 %cmp24.i, label %for.cond23.i, label %for.end27.i\n\nfor.cond23.i: ; preds = %for.cond23.i, %for.cond11thread-pre-split.i\n br label %for.cond23.i\n\nfor.end27.i: ; preds = %for.cond11thread-pre-split.i\n ret i32 0\n}",
"lli_expected_out": "",
"additional_args": null
}
]
}
] | {
"title": "[clang] Miscompilation at -O2/3",
"body": "This code prints 0 at `-O0/1` and triggers SIGKILL at `-O2/3`:\n\n```c\nint printf(const char *, ...);\nint a;\nshort b, c;\nlong e;\nint f[8][1];\nunsigned g;\nint h(int i) {\n long d = 0;\n for (; (a -= i) >= 0; d += 6)\n ;\n return d;\n}\nvoid j() {\n g = 0;\n for (; h(90) + g <= 0; g++) {\n int k = -1;\n b = 0;\n for (; k + g - -1 + b <= 3; b++)\n f[b + 3][0] = c;\n for (; b + g - 3 + e <= 8; e++)\n ;\n for (; e <= 3;)\n ;\n }\n}\nint main() {\n j();\n printf(\"%d\\n\", f[0][0]);\n}\n```\n\nCompiler Explorer: https://godbolt.org/z/3x8Yc3fnW\n\nIt seems to be a recent regression. ",
"author": "cardigan1008",
"labels": [
"regression",
"miscompilation",
"vectorizers"
],
"comments": [
{
"author": "fhahn",
"body": "Bisecting now"
},
{
"author": "dtcxzyw",
"body": "Reproducer: https://godbolt.org/z/6bzT9rs3K\n```\n; bin/opt -passes=loop-vectorize test.ll -S\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@f = global [8 x [1 x i32]] zeroinitializer\n\ndefine i32 @main() {\nentry:\n br label %for.body6.i\n\nfor.body6.i: ; preds = %for.body6.i, %entry\n %conv34.i = phi i32 [ %conv.i, %for.body6.i ], [ 0, %entry ]\n %storemerge3133.i = phi i16 [ %inc.i, %for.body6.i ], [ 0, %entry ]\n %idxprom.i = zext i32 %conv34.i to i64\n %arrayidx.i = getelementptr [8 x [1 x i32]], ptr @f, i64 0, i64 %idxprom.i\n store i32 0, ptr %arrayidx.i, align 4\n %inc.i = add i16 %storemerge3133.i, 1\n %conv.i = zext i16 %inc.i to i32\n %cmp4.i = icmp ult i16 %storemerge3133.i, 3\n br i1 %cmp4.i, label %for.body6.i, label %for.cond11thread-pre-split.i\n\nfor.cond11thread-pre-split.i: ; preds = %for.body6.i\n %0 = add i32 %conv.i, -9\n %cmp24.i = icmp ult i32 %0, -6\n br i1 %cmp24.i, label %for.cond23.i, label %for.end27.i\n\nfor.cond23.i: ; preds = %for.cond23.i, %for.cond11thread-pre-split.i\n br label %for.cond23.i\n\nfor.end27.i: ; preds = %for.cond11thread-pre-split.i\n ret i32 0\n}\n```\n[llubi](https://github.com/dtcxzyw/llvm-ub-aware-interpreter) output:\n\nBefore:\n```\nEntering function main\n br label %for.body6.i jump to %for.body6.i\n phi i32 %conv34.i -> i32 0\n phi i16 %storemerge3133.i -> i16 0\n %idxprom.i = zext i32 %conv34.i to i64 -> i64 0\n %arrayidx.i = getelementptr [8 x [1 x i32]], ptr @f, i64 0, i64 %idxprom.i -> Ptr 16[@f]\n store i32 0, ptr %arrayidx.i, align 4\n %inc.i = add i16 %storemerge3133.i, 1 -> i16 1\n %conv.i = zext i16 %inc.i to i32 -> i32 1\n %cmp4.i = icmp ult i16 %storemerge3133.i, 3 -> T\n br i1 %cmp4.i, label %for.body6.i, label %for.cond11thread-pre-split.i jump to %for.body6.i\n phi i32 %conv34.i -> i32 1\n phi i16 %storemerge3133.i -> i16 1\n %idxprom.i = zext i32 %conv34.i to i64 -> i64 1\n %arrayidx.i = getelementptr [8 x [1 x i32]], ptr @f, i64 0, i64 %idxprom.i -> Ptr 20[@f + 4]\n store i32 0, ptr %arrayidx.i, align 4\n %inc.i = add i16 %storemerge3133.i, 1 -> i16 2\n %conv.i = zext i16 %inc.i to i32 -> i32 2\n %cmp4.i = icmp ult i16 %storemerge3133.i, 3 -> T\n br i1 %cmp4.i, label %for.body6.i, label %for.cond11thread-pre-split.i jump to %for.body6.i\n phi i32 %conv34.i -> i32 2\n phi i16 %storemerge3133.i -> i16 2\n %idxprom.i = zext i32 %conv34.i to i64 -> i64 2\n %arrayidx.i = getelementptr [8 x [1 x i32]], ptr @f, i64 0, i64 %idxprom.i -> Ptr 24[@f + 8]\n store i32 0, ptr %arrayidx.i, align 4\n %inc.i = add i16 %storemerge3133.i, 1 -> i16 3\n %conv.i = zext i16 %inc.i to i32 -> i32 3\n %cmp4.i = icmp ult i16 %storemerge3133.i, 3 -> T\n br i1 %cmp4.i, label %for.body6.i, label %for.cond11thread-pre-split.i jump to %for.body6.i\n phi i32 %conv34.i -> i32 3\n phi i16 %storemerge3133.i -> i16 3\n %idxprom.i = zext i32 %conv34.i to i64 -> i64 3\n %arrayidx.i = getelementptr [8 x [1 x i32]], ptr @f, i64 0, i64 %idxprom.i -> Ptr 28[@f + 12]\n store i32 0, ptr %arrayidx.i, align 4\n %inc.i = add i16 %storemerge3133.i, 1 -> i16 4\n %conv.i = zext i16 %inc.i to i32 -> i32 4\n %cmp4.i = icmp ult i16 %storemerge3133.i, 3 -> F\n br i1 %cmp4.i, label %for.body6.i, label %for.cond11thread-pre-split.i jump to %for.cond11thread-pre-split.i\n %0 = add i32 %conv.i, -9 -> i32 -5\n %cmp24.i = icmp ult i32 %0, -6 -> F\n br i1 %cmp24.i, label %for.cond23.i, label %for.end27.i jump to %for.end27.i\n ret i32 0\nExiting function main\n```\nAfter:\n```\nEntering function main\n br i1 false, label %scalar.ph, label %vector.ph jump to %vector.ph\n br label %vector.body jump to %vector.body\n %0 = zext i32 0 to i64 -> i64 0\n %1 = getelementptr [8 x [1 x i32]], ptr @f, i64 0, i64 %0 -> Ptr 16[@f]\n %2 = getelementptr i32, ptr %1, i32 0 -> Ptr 16[@f]\n store <4 x i32> zeroinitializer, ptr %2, align 4\n %3 = add i16 0, 1 -> i16 1\n %4 = zext i16 %3 to i32 -> i32 1\n %5 = zext i16 %3 to i32 -> i32 1\n %6 = zext i16 %3 to i32 -> i32 1\n %7 = zext i16 %3 to i32 -> i32 1\n br label %middle.block jump to %middle.block\n br i1 true, label %for.cond11thread-pre-split.i, label %scalar.ph jump to %for.cond11thread-pre-split.i\n phi i32 %conv.i.lcssa -> i32 1\n %8 = add i32 %conv.i.lcssa, -9 -> i32 -8\n %cmp24.i = icmp ult i32 %8, -6 -> T\n br i1 %cmp24.i, label %for.cond23.i.preheader, label %for.end27.i jump to %for.cond23.i.preheader\n br label %for.cond23.i jump to %for.cond23.i\n br label %for.cond23.i jump to %for.cond23.i\n br label %for.cond23.i jump to %for.cond23.i\n ...\n```\n"
}
]
} | true | null |
122584 | https://github.com/llvm/llvm-project/issues/122584 | crash | 34ba84fe90b3e369c03e695a395ec632ef60e23d | 2025-01-11T08:32:25 | [
"llvm/test/Transforms/SLPVectorizer"
] | {
"fix_commit": "af524de1fa94e4b4cee8b745d1b68f4ea0090759",
"components": [
"SLPVectorizer"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
[
14935,
14942
]
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
"BoUpSLP::processBuildVector"
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit af524de1fa94e4b4cee8b745d1b68f4ea0090759
Author: Alexey Bataev <[email protected]>
Date: Mon Jan 13 06:48:56 2025 -0800
[SLP]Do not include subvectors for fully matched buildvectors
If the buildvector node fully matched another node, need to exclude
subvectors, when building final shuffle, just a shuffle of the original
node must be emitted.
Fixes #122584
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index e3487b501534..df46c69ff3ab 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -14935,8 +14935,8 @@ ResTy BoUpSLP::processBuildVector(const TreeEntry *E, Type *ScalarTy,
}
}
ShuffleBuilder.add(*FrontTE, Mask);
- Res = ShuffleBuilder.finalize(E->getCommonMask(), SubVectors,
- SubVectorsMask);
+ // Full matched entry found, no need to insert subvectors.
+ Res = ShuffleBuilder.finalize(E->getCommonMask(), {}, {});
return Res;
}
if (!Resized) {
| [
{
"file": "llvm/test/Transforms/SLPVectorizer/AArch64/vectorizable-selects-uniform-cmps.ll",
"commands": [
"opt -passes=slp-vectorizer -S %s",
"opt -aa-pipeline=basic-aa -passes='slp-vectorizer' -S %s"
],
"tests": [
{
"test_name": "select_uniform_ugt_16xi8",
"test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"arm64-apple-ios5.0.0\"\n\ndefine void @select_uniform_ugt_16xi8(ptr %ptr, i8 %x) {\nentry:\n %l.0 = load i8, ptr %ptr, align 1\n %cmp.0 = icmp ugt i8 %l.0, -1\n %s.0 = select i1 %cmp.0, i8 %l.0, i8 %x\n store i8 %s.0, ptr %ptr, align 2\n %gep.1 = getelementptr inbounds i8, ptr %ptr, i8 1\n %l.1 = load i8, ptr %gep.1, align 1\n %cmp.1 = icmp ugt i8 %l.1, -1\n %s.1 = select i1 %cmp.1, i8 %l.1, i8 %x\n store i8 %s.1, ptr %gep.1, align 2\n %gep.2 = getelementptr inbounds i8, ptr %ptr, i8 2\n %l.2 = load i8, ptr %gep.2, align 1\n %cmp.2 = icmp ugt i8 %l.2, -1\n %s.2 = select i1 %cmp.2, i8 %l.2, i8 %x\n store i8 %s.2, ptr %gep.2, align 2\n %gep.3 = getelementptr inbounds i8, ptr %ptr, i8 3\n %l.3 = load i8, ptr %gep.3, align 1\n %cmp.3 = icmp ugt i8 %l.3, -1\n %s.3 = select i1 %cmp.3, i8 %l.3, i8 %x\n store i8 %s.3, ptr %gep.3, align 2\n %gep.4 = getelementptr inbounds i8, ptr %ptr, i8 4\n %l.4 = load i8, ptr %gep.4, align 1\n %cmp.4 = icmp ugt i8 %l.4, -1\n %s.4 = select i1 %cmp.4, i8 %l.4, i8 %x\n store i8 %s.4, ptr %gep.4, align 2\n %gep.5 = getelementptr inbounds i8, ptr %ptr, i8 5\n %l.5 = load i8, ptr %gep.5, align 1\n %cmp.5 = icmp ugt i8 %l.5, -1\n %s.5 = select i1 %cmp.5, i8 %l.5, i8 %x\n store i8 %s.5, ptr %gep.5, align 2\n %gep.6 = getelementptr inbounds i8, ptr %ptr, i8 6\n %l.6 = load i8, ptr %gep.6, align 1\n %cmp.6 = icmp ugt i8 %l.6, -1\n %s.6 = select i1 %cmp.6, i8 %l.6, i8 %x\n store i8 %s.6, ptr %gep.6, align 2\n %gep.7 = getelementptr inbounds i8, ptr %ptr, i8 7\n %l.7 = load i8, ptr %gep.7, align 1\n %cmp.7 = icmp ugt i8 %l.7, -1\n %s.7 = select i1 %cmp.7, i8 %l.7, i8 %x\n store i8 %s.7, ptr %gep.7, align 2\n %gep.8 = getelementptr inbounds i8, ptr %ptr, i8 8\n %l.8 = load i8, ptr %gep.8, align 1\n %cmp.8 = icmp ugt i8 %l.8, -1\n %s.8 = select i1 %cmp.8, i8 %l.0, i8 %x\n store i8 %s.0, ptr %gep.8, align 2\n %gep.9 = getelementptr inbounds i8, ptr %ptr, i8 9\n %l.9 = load i8, ptr %gep.9, align 1\n %cmp.9 = icmp ugt i8 %l.9, -1\n %s.9 = select i1 %cmp.9, i8 %l.9, i8 %x\n store i8 %s.9, ptr %gep.9, align 2\n %gep.10 = getelementptr inbounds i8, ptr %ptr, i8 10\n %l.10 = load i8, ptr %gep.10, align 1\n %cmp.10 = icmp ugt i8 %l.10, -1\n %s.10 = select i1 %cmp.10, i8 %l.10, i8 %x\n store i8 %s.10, ptr %gep.10, align 2\n %gep.11 = getelementptr inbounds i8, ptr %ptr, i8 11\n %l.11 = load i8, ptr %gep.11, align 1\n %cmp.11 = icmp ugt i8 %l.11, -1\n %s.11 = select i1 %cmp.11, i8 %l.11, i8 %x\n store i8 %s.11, ptr %gep.11, align 2\n %gep.12 = getelementptr inbounds i8, ptr %ptr, i8 12\n %l.12 = load i8, ptr %gep.12, align 1\n %cmp.12 = icmp ugt i8 %l.12, -1\n %s.12 = select i1 %cmp.12, i8 %l.12, i8 %x\n store i8 %s.12, ptr %gep.12, align 2\n %gep.13 = getelementptr inbounds i8, ptr %ptr, i8 13\n %l.13 = load i8, ptr %gep.13, align 1\n %cmp.13 = icmp ugt i8 %l.13, -1\n %s.13 = select i1 %cmp.13, i8 %l.13, i8 %x\n store i8 %s.13, ptr %gep.13, align 2\n %gep.14 = getelementptr inbounds i8, ptr %ptr, i8 14\n %l.14 = load i8, ptr %gep.14, align 1\n %cmp.14 = icmp ugt i8 %l.14, -1\n %s.14 = select i1 %cmp.14, i8 %l.14, i8 %x\n store i8 %s.14, ptr %gep.14, align 2\n %gep.15 = getelementptr inbounds i8, ptr %ptr, i8 15\n %l.15 = load i8, ptr %gep.15, align 1\n %cmp.15 = icmp ugt i8 %l.15, -1\n %s.15 = select i1 %cmp.15, i8 %l.15, i8 %x\n store i8 %s.15, ptr %gep.15, align 2\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/SLPVectorizer/X86/full-matched-bv-with-subvectors.ll",
"commands": [
"opt -S --passes=slp-vectorizer -slp-threshold=-9999 -mtriple=x86_64-unknown-linux-gnu < %s"
],
"tests": [
{
"test_name": "test",
"test_body": "define i32 @test(i64 %l.549) {\nentry:\n %conv3 = sext i32 0 to i64\n br label %if.then19\n\np: ; preds = %if.end29, %if.end25\n %l.0 = phi i64 [ %xor, %if.end29 ], [ %l.5493, %if.end25 ]\n %m.0 = phi i64 [ %not21, %if.end29 ], [ %m.550, %if.end25 ]\n br i1 false, label %s, label %q\n\nq: ; preds = %land.lhs.true, %p\n %xor39 = phi i64 [ 0, %p ], [ 0, %land.lhs.true ]\n %l.1 = phi i64 [ 0, %p ], [ 0, %land.lhs.true ]\n %m.1 = phi i64 [ 0, %p ], [ 0, %land.lhs.true ]\n br i1 false, label %lor.lhs.false, label %r\n\nlor.lhs.false: ; preds = %q\n br i1 false, label %land.lhs.true, label %s\n\nr: ; preds = %if.then19, %q\n %xor38 = phi i64 [ %xor39, %q ], [ %xor, %if.then19 ]\n %j.0 = phi i64 [ %conv3, %q ], [ %not21, %if.then19 ]\n %l.2 = phi i64 [ %l.1, %q ], [ %l.549, %if.then19 ]\n %m.2 = phi i64 [ %m.1, %q ], [ %m.550, %if.then19 ]\n br i1 false, label %s, label %land.lhs.true\n\nland.lhs.true: ; preds = %r, %lor.lhs.false\n %xor37 = phi i64 [ %xor38, %r ], [ 0, %lor.lhs.false ]\n %j.1 = phi i64 [ %j.0, %r ], [ 0, %lor.lhs.false ]\n %l.3 = phi i64 [ %l.2, %r ], [ 0, %lor.lhs.false ]\n %m.3 = phi i64 [ %m.2, %r ], [ 0, %lor.lhs.false ]\n br i1 false, label %q, label %s\n\ns: ; preds = %land.lhs.true, %r, %lor.lhs.false, %p\n %xor36 = phi i64 [ %xor37, %land.lhs.true ], [ %xor38, %r ], [ %xor39, %lor.lhs.false ], [ %l.0, %p ]\n %j.2 = phi i64 [ %j.1, %land.lhs.true ], [ %j.0, %r ], [ %conv3, %lor.lhs.false ], [ %m.0, %p ]\n %l.4 = phi i64 [ %l.3, %land.lhs.true ], [ %l.2, %r ], [ %l.1, %lor.lhs.false ], [ %l.0, %p ]\n %m.4 = phi i64 [ %m.3, %land.lhs.true ], [ %m.2, %r ], [ %m.1, %lor.lhs.false ], [ %m.0, %p ]\n br label %if.then19\n\nif.then19: ; preds = %s, %entry\n %m.550 = phi i64 [ 0, %entry ], [ %m.4, %s ]\n %l.5493 = phi i64 [ 0, %entry ], [ %l.4, %s ]\n %xor = xor i64 0, 0\n %not21 = xor i64 0, 0\n br i1 false, label %r, label %if.end25\n\nif.end25: ; preds = %if.then19\n br i1 false, label %if.end29, label %p\n\nif.end29: ; preds = %if.end25\n br label %p\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "clang crashes on valid code at -O{s,2,3} on x86_64-linux-gnu: Assertion `I1 == PoisonMaskElem && \"Expected unused subvectors mask\"' failed",
"body": "It appears to be a recent regression as it doesn't reproduce with 19.1.0 and earlier.\n\nCompiler Explorer: https://godbolt.org/z/vWPhsMfoz\n\n```\n[510] % clangtk -v\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git 24bd9bc0b59d51c82e9a4d84c21d86d58d0ef6ce)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nCandidate multilib: .;@m64\nSelected multilib: .;@m64\nFound CUDA installation: /usr/local/cuda, version 12.1\n[511] % \n[511] % clangtk -O2 small.c\nclang-20: /local/suz-local/software/clangbuild/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:10936: llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::finalize(llvm::ArrayRef<int>, llvm::ArrayRef<std::pair<const llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int> >, llvm::ArrayRef<int>, unsigned int, llvm::function_ref<void(llvm::Value*&, llvm::SmallVectorImpl<int>&)>): Assertion `I1 == PoisonMaskElem && \"Expected unused subvectors mask\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\nStack dump:\n0.\tProgram arguments: /local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/local/suz-local/software/emitesting/bugs/20250111-clangtk-m64-Os-build-025751/delta -fcoverage-compilation-dir=/local/suz-local/software/emitesting/bugs/20250111-clangtk-m64-Os-build-025751/delta -resource-dir /local/home/suz/suz-local/software/local/clang-trunk/lib/clang/20 -I /usr/local/include -I /local/suz-local/software/local/include -internal-isystem /local/home/suz/suz-local/software/local/clang-trunk/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-2771d7.o -x c small.c\n1.\t<eof> parser at end of file\n2.\tOptimizer\n3.\tRunning pass \"function<eager-inv>(float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"small.c\"\n4.\tRunning pass \"slp-vectorizer\" on function \"main\"\n #0 0x0000562bd646d500 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x4576500)\n #1 0x0000562bd646a91f llvm::sys::RunSignalHandlers() (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x457391f)\n #2 0x0000562bd646aa75 SignalHandler(int) Signals.cpp:0:0\n #3 0x00007f13d1771520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #4 0x00007f13d17c5a7c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x96a7c)\n #5 0x00007f13d1771476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #6 0x00007f13d17577f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #7 0x00007f13d175771b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #8 0x00007f13d1768e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #9 0x0000562bd7f25a4f llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator::finalize(llvm::ArrayRef<int>, llvm::ArrayRef<std::pair<llvm::slpvectorizer::BoUpSLP::TreeEntry const*, unsigned int>>, llvm::ArrayRef<int>, unsigned int, llvm::function_ref<void (llvm::Value*&, llvm::SmallVectorImpl<int>&)>) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x602ea4f)\n#10 0x0000562bd7f9164b llvm::InstructionCost llvm::slpvectorizer::BoUpSLP::processBuildVector<llvm::slpvectorizer::BoUpSLP::ShuffleCostEstimator, llvm::InstructionCost, llvm::TargetTransformInfo, llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP, llvm::SmallPtrSetImpl<llvm::Value*>>(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::Type*, llvm::TargetTransformInfo&, llvm::ArrayRef<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP&, llvm::SmallPtrSetImpl<llvm::Value*>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x609a64b)\n#11 0x0000562bd7f92881 llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x609b881)\n#12 0x0000562bd7faaa12 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x60b3a12)\n#13 0x0000562bd7fb43e8 llvm::SLPVectorizerPass::tryToVectorizeList(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, bool) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x60bd3e8)\n#14 0x0000562bd7fb92b0 bool tryToVectorizeSequence<llvm::Value>(llvm::SmallVectorImpl<llvm::Value*>&, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::Value*, llvm::Value*)>, llvm::function_ref<bool (llvm::ArrayRef<llvm::Value*>, bool)>, bool, llvm::slpvectorizer::BoUpSLP&) (.constprop.0) SLPVectorizer.cpp:0:0\n#15 0x0000562bd7fbabe9 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x60c3be9)\n#16 0x0000562bd7fc268e llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\n#17 0x0000562bd7fc31d1 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x60cc1d1)\n#18 0x0000562bd79d6826 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x5adf826)\n#19 0x0000562bd5de82ef llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3ef12ef)\n#20 0x0000562bd37a5226 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x18ae226)\n#21 0x0000562bd5de664b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3eef64b)\n#22 0x0000562bd37a3b36 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x18acb36)\n#23 0x0000562bd5de724d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x3ef024d)\n#24 0x0000562bd67194c7 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\n#25 0x0000562bd671d213 clang::emitBackendOutput(clang::CompilerInstance&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x4826213)\n#26 0x0000562bd6df1805 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x4efa805)\n#27 0x0000562bd8a8c2cc clang::ParseAST(clang::Sema&, bool, bool) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x6b952cc)\n#28 0x0000562bd70d6ca9 clang::FrontendAction::Execute() (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x51dfca9)\n#29 0x0000562bd7054ad5 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x515dad5)\n#30 0x0000562bd71bbf73 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x52c4f73)\n#31 0x0000562bd334425f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x144d25f)\n#32 0x0000562bd333ab2a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\n#33 0x0000562bd333efe7 clang_main(int, char**, llvm::ToolContext const&) (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x1447fe7)\n#34 0x0000562bd322eb3b main (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x1337b3b)\n#35 0x00007f13d1758d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#36 0x00007f13d1758e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#37 0x0000562bd333a255 _start (/local/home/suz/suz-local/software/local/clang-trunk/bin/clang-20+0x1443255)\nclangtk: error: unable to execute command: Aborted\nclangtk: error: clang frontend command failed due to signal (use -v to see invocation)\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git 24bd9bc0b59d51c82e9a4d84c21d86d58d0ef6ce)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nclangtk: note: diagnostic msg: \n********************\n\nPLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\nPreprocessed source(s) and associated run script(s) are located at:\nclangtk: note: diagnostic msg: /tmp/small-929da7.c\nclangtk: note: diagnostic msg: /tmp/small-929da7.sh\nclangtk: note: diagnostic msg: \n\n********************\n[512] % \n[512] % cat small.c\nint a, b, d, e, f, i, n;\nlong c, g, h;\nunsigned o;\nint main() {\n unsigned long j;\n long l, m;\n if (0) {\n k:\n h = ~g;\n l = g;\n m = j;\n i = d;\n p:\n b = g = i;\n if (d) {\n q:\n j = a;\n if (i || i >= a)\n r:\n if (f && h > a)\n goto q;\n goto s;\n }\n g = l;\n j = m;\n s:;\n }\n if (c) {\n n = j % -1;\n o = b;\n if (n) {\n g = d ^ j;\n j = ~(1 / o);\n if (!(n - 1))\n goto r;\n if (e)\n goto p;\n }\n goto k;\n }\n}\n```",
"author": "zhendongsu",
"labels": [
"llvm:SLPVectorizer",
"crash-on-valid",
"generated by fuzzer"
],
"comments": [
{
"author": "dtcxzyw",
"body": "Reduced reproducer: https://godbolt.org/z/MzcesqWz1\n```\n; bin/opt -passes=slp-vectorizer reduced.ll -S\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @main(i64 %l.549) {\nentry:\n %conv3 = sext i32 0 to i64\n br label %if.then19\n\np: ; preds = %if.end29, %if.end25\n %l.0 = phi i64 [ %xor, %if.end29 ], [ %l.5493, %if.end25 ]\n %m.0 = phi i64 [ %not21, %if.end29 ], [ %m.550, %if.end25 ]\n br i1 false, label %s, label %q\n\nq: ; preds = %land.lhs.true, %p\n %xor39 = phi i64 [ 0, %p ], [ 0, %land.lhs.true ]\n %l.1 = phi i64 [ 0, %p ], [ 0, %land.lhs.true ]\n %m.1 = phi i64 [ 0, %p ], [ 0, %land.lhs.true ]\n br i1 false, label %lor.lhs.false, label %r\n\nlor.lhs.false: ; preds = %q\n br i1 false, label %land.lhs.true, label %s\n\nr: ; preds = %if.then19, %q\n %xor38 = phi i64 [ %xor39, %q ], [ %xor, %if.then19 ]\n %j.0 = phi i64 [ %conv3, %q ], [ %not21, %if.then19 ]\n %l.2 = phi i64 [ %l.1, %q ], [ %l.549, %if.then19 ]\n %m.2 = phi i64 [ %m.1, %q ], [ %m.550, %if.then19 ]\n br i1 false, label %s, label %land.lhs.true\n\nland.lhs.true: ; preds = %r, %lor.lhs.false\n %xor37 = phi i64 [ %xor38, %r ], [ 0, %lor.lhs.false ]\n %j.1 = phi i64 [ %j.0, %r ], [ 0, %lor.lhs.false ]\n %l.3 = phi i64 [ %l.2, %r ], [ 0, %lor.lhs.false ]\n %m.3 = phi i64 [ %m.2, %r ], [ 0, %lor.lhs.false ]\n br i1 false, label %q, label %s\n\ns: ; preds = %land.lhs.true, %r, %lor.lhs.false, %p\n %xor36 = phi i64 [ %xor37, %land.lhs.true ], [ %xor38, %r ], [ %xor39, %lor.lhs.false ], [ %l.0, %p ]\n %j.2 = phi i64 [ %j.1, %land.lhs.true ], [ %j.0, %r ], [ %conv3, %lor.lhs.false ], [ %m.0, %p ]\n %l.4 = phi i64 [ %l.3, %land.lhs.true ], [ %l.2, %r ], [ %l.1, %lor.lhs.false ], [ %l.0, %p ]\n %m.4 = phi i64 [ %m.3, %land.lhs.true ], [ %m.2, %r ], [ %m.1, %lor.lhs.false ], [ %m.0, %p ]\n br label %if.then19\n\nif.then19: ; preds = %s, %entry\n %m.550 = phi i64 [ 0, %entry ], [ %m.4, %s ]\n %l.5493 = phi i64 [ 0, %entry ], [ %l.4, %s ]\n %xor = xor i64 0, 0\n %not21 = xor i64 0, 0\n br i1 false, label %r, label %if.end25\n\nif.end25: ; preds = %if.then19\n br i1 false, label %if.end29, label %p\n\nif.end29: ; preds = %if.end25\n br label %p\n}\n\n```"
}
]
} | true | null |
88849 | https://github.com/llvm/llvm-project/issues/88849 | crash | 6b98ab95f0d36705b5a1fc1e755c992ba2329c89 | 2024-04-16T07:36:13 | [
"llvm/test/Transforms/LoopVectorize"
] | {
"fix_commit": "b8741cc185e89a95c9161218084f7c8b5578cf96",
"components": [
"LoopVectorize"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": [
[
254,
259
]
],
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": [
"VPTransformState::get"
],
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit b8741cc185e89a95c9161218084f7c8b5578cf96
Author: Florian Hahn <[email protected]>
Date: Fri Jul 19 10:33:07 2024 +0100
[VPlan] Relax assertion retrieving a scalar from VPTransformState::get.
The current assertion VPTransformState::get when retrieving a single
scalar only does not account for cases where a def has multiple users,
some demanding all scalar lanes, some demanding only a single scalar.
For an example, see the modified test case. Relax the assertion by also
allowing requesting scalar lanes only when the Def doesn't have only its
first lane used.
Fixes https://github.com/llvm/llvm-project/issues/88849.
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index 83a035fb4df8..58de6256900f 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -254,6 +254,7 @@ Value *VPTransformState::get(VPValue *Def, const VPIteration &Instance) {
Value *VPTransformState::get(VPValue *Def, unsigned Part, bool NeedsScalar) {
if (NeedsScalar) {
assert((VF.isScalar() || Def->isLiveIn() || hasVectorValue(Def, Part) ||
+ !vputils::onlyFirstLaneUsed(Def) ||
(hasScalarValue(Def, VPIteration(Part, 0)) &&
Data.PerPartScalars[Def][Part].size() == 1)) &&
"Trying to access a single scalar per part but has multiple scalars "
| [
{
"file": "llvm/test/Transforms/LoopVectorize/SystemZ/scalar-steps-with-users-demanding-all-lanes-and-first-lane-only.ll",
"commands": [
"opt -p loop-vectorize -mtriple=s390x-unknown-linux -mcpu=z16 -S %s"
],
"tests": [
{
"test_name": "test_scalar_iv_steps_used_by_replicate_and_first_lane_only_vpinst",
"test_body": "target datalayout = \"E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64\"\n\n@src = external global [8 x i32], align 4\n\ndefine void @test_scalar_iv_steps_used_by_replicate_and_first_lane_only_vpinst(ptr noalias %dst, ptr noalias %src.1) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %mul.iv = mul nsw i64 %iv, 4\n %gep.src.1 = getelementptr inbounds i8, ptr %src.1, i64 %mul.iv\n %l.1 = load i8, ptr %gep.src.1, align 1\n %c = icmp eq i8 %l.1, 0\n br i1 %c, label %then, label %loop.latch\n\nthen: ; preds = %loop.header\n %iv.or = or disjoint i64 %iv, 4\n %gep.src = getelementptr inbounds [8 x i32], ptr @src, i64 0, i64 %iv.or\n %l.2 = load i32, ptr %gep.src, align 4\n store i32 %l.2, ptr %dst, align 4\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %iv.next = add nuw nsw i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 4\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "LoopVectorizer asserts: Assertion `(VF.isScalar() || Def->isLiveIn() || (hasScalarValue(Def, VPIteration(Part, 0)) && Data.PerPartScalars[Def][Part].size() == 1)) && \"Trying to access a single scalar per part but has multiple scalars \" \"per part.",
"body": "[tc_crash35_aftercreduce.ll.tar.gz](https://github.com/llvm/llvm-project/files/14988465/tc_crash35_aftercreduce.ll.tar.gz)\r\n\r\nopt -mtriple=s390x-unknown-linux -mcpu=z16 -O3 tc_crash35_aftercreduce.ll -o /dev/null\r\n\r\nVPlan.cpp:253: llvm::Value* llvm::VPTransformState::get(llvm::VPValue*, unsigned int, bool): Assertion `(VF.isScalar() || Def->isLiveIn() || (hasScalarValue(Def, VPIteration(Part, 0)) && Data.PerPartScalars[Def][Part].size() == 1)) && \"Trying to access a single scalar per part but has multiple scalars \" \"per part.\"' failed.\r\n\r\n@fhahn ",
"author": "JonPsson1",
"labels": [
"vectorizers",
"crash"
],
"comments": [
{
"author": "fhahn",
"body": "Should be fixed now, sorry for the delay @JonPsson1 !"
}
]
} | true | null |
89672 | https://github.com/llvm/llvm-project/issues/89672 | miscompilation | b64e483785bfef5ec4977988543ed5cfaf62f306 | 2024-04-22T21:35:16 | [
"llvm/test/Transforms/SimplifyCFG"
] | {
"fix_commit": "883887493c882d656d5da100ee637a348e81357c",
"components": [
"SimplifyCFG"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": [
[
2888,
2894
],
[
2896,
2902
]
],
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": [
"isSafeToSpeculateStore"
],
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 883887493c882d656d5da100ee637a348e81357c
Author: Nikita Popov <[email protected]>
Date: Tue Apr 23 12:36:35 2024 +0900
[SimplifyCFG] Check alignment when speculating stores
When speculating a store based on a preceding load/store, we need
to ensure that the speculated store does not have a higher
alignment (which might only be guaranteed by the branch condition).
There are various ways in which this could be strengthened (we
could get or enforce the alignment), but for now just do the
simple check against the preceding load/store.
Fixes https://github.com/llvm/llvm-project/issues/89672.
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index da3eb229c041..0826d748ba0d 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2888,7 +2888,8 @@ static Value *isSafeToSpeculateStore(Instruction *I, BasicBlock *BrBB,
// simple, to avoid introducing a spurious non-atomic write after an
// atomic write.
if (SI->getPointerOperand() == StorePtr &&
- SI->getValueOperand()->getType() == StoreTy && SI->isSimple())
+ SI->getValueOperand()->getType() == StoreTy && SI->isSimple() &&
+ SI->getAlign() >= StoreToHoist->getAlign())
// Found the previous store, return its value operand.
return SI->getValueOperand();
return nullptr; // Unknown store.
@@ -2896,7 +2897,7 @@ static Value *isSafeToSpeculateStore(Instruction *I, BasicBlock *BrBB,
if (auto *LI = dyn_cast<LoadInst>(&CurI)) {
if (LI->getPointerOperand() == StorePtr && LI->getType() == StoreTy &&
- LI->isSimple()) {
+ LI->isSimple() && LI->getAlign() >= StoreToHoist->getAlign()) {
// Local objects (created by an `alloca` instruction) are always
// writable, so once we are past a read from a location it is valid to
// also write to that same location.
| [
{
"file": "llvm/test/Transforms/SimplifyCFG/speculate-store.ll",
"commands": [
"opt -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S < %s"
],
"tests": [
{
"test_name": "wrong_align_store",
"test_body": "define void @wrong_align_store(ptr %A, i32 %B, i32 %C, i32 %D) {\nentry:\n store i32 %B, ptr %A, align 4\n %cmp = icmp sgt i32 %D, 42\n br i1 %cmp, label %if.then, label %ret.end\n\nif.then: ; preds = %entry\n store i32 %C, ptr %A, align 8\n br label %ret.end\n\nret.end: ; preds = %if.then, %entry\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "wrong_align_load",
"test_body": "define void @wrong_align_load(i32 %C, i32 %D) {\nentry:\n %A = alloca i32, align 4\n %0 = load i32, ptr %A, align 4\n %cmp = icmp sgt i32 %D, 42\n br i1 %cmp, label %if.then, label %ret.end\n\nif.then: ; preds = %entry\n store i32 %C, ptr %A, align 8\n br label %ret.end\n\nret.end: ; preds = %if.then, %entry\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "coalescing of redundant vector stores isn't preserving alignment correctly",
"body": "https://alive2.llvm.org/ce/z/-qQphe\r\n\r\noptimizing this code:\r\n```llvm\r\ndefine i32 @f(ptr %0, i1 %1) {\r\n store <2 x i64> zeroinitializer, ptr %0, align 8\r\n br i1 %1, label %4, label %3\r\n\r\n3: ; preds = %2\r\n store <2 x i64> zeroinitializer, ptr %0, align 16\r\n br label %4\r\n\r\n4: ; preds = %3, %2\r\n ret i32 0\r\n}\r\n```\r\n\r\nis mostly doing what we expect, but the coalesced store should retain the smaller alignnment value of the two, not the larger:\r\n```lllvm\r\ndefine noundef i32 @f(ptr nocapture writeonly %0, i1 %1) local_unnamed_addr #0 {\r\n store <2 x i64> zeroinitializer, ptr %0, align 16\r\n ret i32 0\r\n}\r\n\r\nattributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) }\r\n```\r\n\r\ncc @nunoplopes @hatsunespica",
"author": "regehr",
"labels": [
"miscompilation",
"llvm:transforms"
],
"comments": [
{
"author": "nikic",
"body": "The issue is introduced by SimplifyCFG: https://alive2.llvm.org/ce/z/zf-j74"
},
{
"author": "nikic",
"body": "Specifically this is isSafeToSpeculateStore(), which looks for a preceding store to check whether it is safe to speculate, but fails to check alignment."
}
]
} | true | null |
112577 | https://github.com/llvm/llvm-project/issues/112577 | miscompilation | 76196998e25b98d81abc437708622261810782ca | 2024-10-16T16:30:23 | [
"llvm/test/Transforms/SLPVectorizer"
] | {
"fix_commit": "709abacdc350d63c61888607edb28ce272daa0a0",
"components": [
"SLPVectorizer"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
[
17224,
17232
]
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
"BoUpSLP::collectValuesToDemote"
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 709abacdc350d63c61888607edb28ce272daa0a0
Author: Alexey Bataev <[email protected]>
Date: Fri Oct 18 13:54:30 2024 -0700
[SLP]Check that operand of abs does not overflow before making it part of minbitwidth transformation
Need to check that the operand of the abs intrinsic can be safely
truncated before making it part of the minbitwidth transformation.
Fixes #112577
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index e7b52fbdcc3b..e1aa6127ac03 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -17224,9 +17224,25 @@ bool BoUpSLP::collectValuesToDemote(
MaskedValueIsZero(I->getOperand(1), Mask, SimplifyQuery(*DL)));
});
};
+ auto AbsChecker = [&](unsigned BitWidth, unsigned OrigBitWidth) {
+ assert(BitWidth <= OrigBitWidth && "Unexpected bitwidths!");
+ return all_of(E.Scalars, [&](Value *V) {
+ auto *I = cast<Instruction>(V);
+ unsigned SignBits = OrigBitWidth - BitWidth;
+ APInt Mask = APInt::getBitsSetFrom(OrigBitWidth, BitWidth - 1);
+ unsigned Op0SignBits =
+ ComputeNumSignBits(I->getOperand(0), *DL, 0, AC, nullptr, DT);
+ return SignBits <= Op0SignBits &&
+ ((SignBits != Op0SignBits &&
+ !isKnownNonNegative(I->getOperand(0), SimplifyQuery(*DL))) ||
+ MaskedValueIsZero(I->getOperand(0), Mask, SimplifyQuery(*DL)));
+ });
+ };
if (ID != Intrinsic::abs) {
Operands.push_back(getOperandEntry(&E, 1));
CallChecker = CompChecker;
+ } else {
+ CallChecker = AbsChecker;
}
InstructionCost BestCost =
std::numeric_limits<InstructionCost::CostType>::max();
| [
{
"file": "llvm/test/Transforms/SLPVectorizer/abs-overflow-incorrect-minbws.ll",
"commands": [
"opt -S --passes=slp-vectorizer < %s"
],
"tests": [
{
"test_name": "test",
"test_body": "define i32 @test(i32 %n) {\nentry:\n %n1 = add i32 %n, 1\n %zn1 = zext nneg i32 %n1 to i64\n %m1 = mul nuw nsw i64 %zn1, 273837369\n %a1 = call i64 @llvm.abs.i64(i64 %m1, i1 true)\n %t1 = trunc i64 %a1 to i32\n %n2 = add i32 %n, 2\n %zn2 = zext nneg i32 %n2 to i64\n %m2 = mul nuw nsw i64 %zn2, 273837369\n %a2 = call i64 @llvm.abs.i64(i64 %m2, i1 true)\n %t2 = trunc i64 %a2 to i32\n %res1 = add i32 %t1, %t2\n ret i32 %res1\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i64 @llvm.abs.i64(i64, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[SLP] SLP Vectorizer miscompile from reducing abs bitwidth",
"body": "Bisected miscompile to this change https://github.com/llvm/llvm-project/commit/4a1c53f9fabbc18d436dcd4d5b572b82656fbbf9\r\n\r\nReduced internal test to this example:\r\nhttps://godbolt.org/z/njWYP9exd\r\n```llvm\r\ndefine dso_local noundef i32 @test(i32 %n) local_unnamed_addr #0 {\r\nentry:\r\n %n1 = add i32 %n, 1\r\n %zn1 = zext nneg i32 %n1 to i64\r\n %m1 = mul nuw nsw i64 %zn1, 273837369\r\n %a1 = call noundef i64 @llvm.abs.i64(i64 %m1, i1 true)\r\n %t1 = trunc i64 %a1 to i32\r\n %n2 = add i32 %n, 2\r\n %zn2 = zext nneg i32 %n2 to i64\r\n %m2 = mul nuw nsw i64 %zn2, 273837369\r\n %a2 = call noundef i64 @llvm.abs.i64(i64 %m2, i1 true)\r\n %t2 = trunc i64 %a2 to i32\r\n\r\n %res1 = add i32 %t1, %t2\r\n ret i32 %res1\r\n}\r\n```\r\nRunning slp vectorizer on it gives\r\n```llvm\r\ndefine dso_local noundef i32 @test(i32 %n) local_unnamed_addr {\r\n %0 = insertelement <2 x i32> poison, i32 %n, i32 0\r\n %1 = shufflevector <2 x i32> %0, <2 x i32> poison, <2 x i32> zeroinitializer\r\n %2 = add <2 x i32> %1, <i32 1, i32 2>\r\n %3 = mul <2 x i32> %2, <i32 273837369, i32 273837369>\r\n %4 = call <2 x i32> @llvm.abs.v2i32(<2 x i32> %3, i1 false)\r\n %5 = extractelement <2 x i32> %4, i32 0\r\n %6 = extractelement <2 x i32> %4, i32 1\r\n %res1 = add i32 %5, %6\r\n ret i32 %res1\r\n}\r\n```\r\nwhich is incorrect. Counterexample by alive2:\r\nhttps://alive2.llvm.org/ce/z/cEcY-u",
"author": "danilaml",
"labels": [
"miscompilation",
"release:backport",
"llvm:SLPVectorizer"
],
"comments": [
{
"author": "AZero13",
"body": "Do we plan on backporting this to 19.x @alexey-bataev "
}
]
} | true | null |
115744 | https://github.com/llvm/llvm-project/issues/115744 | crash | 28002dd50fb7ec97da1770a11f9c6a99dd9aecb9 | 2024-11-11T17:12:17 | [
"llvm/test/Transforms/LoopVectorize"
] | {
"fix_commit": "8009c1fd81ad0b6ac65724d2b134a92db48f8fbf",
"components": [
"LoopVectorize"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
[
7291,
7297
],
[
7311,
7317
]
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
"LoopVectorizationPlanner::precomputeCosts"
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 8009c1fd81ad0b6ac65724d2b134a92db48f8fbf
Author: Elvis Wang <[email protected]>
Date: Tue Feb 25 11:09:09 2025 +0800
[LV][VPlan] Prevent calculate cost for skiped instructions in precomputeCosts(). (#127966)
Skip calculating instruction costs for exit conditions in
precomputeCosts() when it should be skipped.
Reported from:
https://github.com/llvm/llvm-project/issues/115744#issuecomment-2670479463
Godbolt for reduced test cases: https://godbolt.org/z/fr4YMeqcv
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 4d2df9179aa3..0bf2d71a63ef 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -7291,7 +7291,7 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,
// Collect all exit conditions.
for (BasicBlock *EB : Exiting) {
auto *Term = dyn_cast<BranchInst>(EB->getTerminator());
- if (!Term)
+ if (!Term || CostCtx.skipCostComputation(Term, VF.isVector()))
continue;
if (auto *CondI = dyn_cast<Instruction>(Term->getOperand(0))) {
ExitInstrs.insert(CondI);
@@ -7311,7 +7311,8 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,
Cost += CondICost;
for (Value *Op : CondI->operands()) {
auto *OpI = dyn_cast<Instruction>(Op);
- if (!OpI || any_of(OpI->users(), [&ExitInstrs, this](User *U) {
+ if (!OpI || CostCtx.skipCostComputation(OpI, VF.isVector()) ||
+ any_of(OpI->users(), [&ExitInstrs, this](User *U) {
return OrigLoop->contains(cast<Instruction>(U)->getParent()) &&
!ExitInstrs.contains(cast<Instruction>(U));
}))
| [
{
"file": "llvm/test/Transforms/LoopVectorize/X86/cost-model.ll",
"commands": [
"opt < %s -passes=loop-vectorize -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx -S"
],
"tests": [
{
"test_name": "g",
"test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.8.0\"\n\ndefine i32 @g(i64 %n) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %select = phi i32 [ 0, %entry ], [ %select.next, %loop ]\n %iv.widen = zext i32 %iv to i64\n %exitcond = icmp eq i64 %n, %iv.widen\n %select.i = select i1 %exitcond, i32 0, i32 2\n %select.next = or i32 %select.i, %select\n %iv.next = add i32 %iv, 1\n br i1 %exitcond, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i32 %select.next\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[VPlan] Assertion \"VPlan cost model and legacy cost model disagreed\"' failed.",
"body": "C program:\r\n```c\r\nsigned char a;\r\nshort b;\r\nint c, g;\r\nlong d, e, f;\r\nvoid h(long i[][2], long j[][2][2], short k[][2]) {\r\n for (unsigned l = g; l; l += 4) {\r\n a *= (signed char)((f ? 0 : k[l][l]) ?: (_Bool)(d << j[8][l][e]) ? i[l][l] : c);\r\n b = ~i[e][l];\r\n }\r\n}\r\n```\r\n`/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/clang -march=rv64gcv -O3 red.c -o rv64gcv.bc -w -emit-llvm -c`\r\n\r\nLLVM IR:\r\n```llvm ir\r\n; ModuleID = 'reduced.bc'\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine void @h(ptr %i, ptr %k, i64 %idxprom.us) #0 {\r\nentry:\r\n br label %for.body.us\r\n\r\nfor.body.us: ; preds = %cond.end23.us, %entry\r\n %l.046.us = phi i32 [ %add.us, %cond.end23.us ], [ 0, %entry ]\r\n %conv284345.us = phi i8 [ %conv28.us, %cond.end23.us ], [ 0, %entry ]\r\n %idxprom.us1 = zext i32 %l.046.us to i64\r\n %arrayidx3.us = getelementptr [2 x i16], ptr %k, i64 %idxprom.us1, i64 %idxprom.us\r\n %0 = load i16, ptr %arrayidx3.us, align 2\r\n %tobool4.not.us = icmp eq i16 %0, 0\r\n br i1 %tobool4.not.us, label %cond.false7.us, label %cond.end23.us\r\n\r\ncond.false7.us: ; preds = %for.body.us\r\n %1 = load i64, ptr %i, align 8\r\n %shl.us = shl i64 0, %1\r\n %tobool12.not.us = icmp eq i64 %shl.us, 0\r\n br i1 %tobool12.not.us, label %cond.end23.us, label %cond.true14.us\r\n\r\ncond.true14.us: ; preds = %cond.false7.us\r\n %2 = load i64, ptr %i, align 8\r\n %3 = trunc i64 %2 to i32\r\n br label %cond.end23.us\r\n\r\ncond.end23.us: ; preds = %cond.true14.us, %cond.false7.us, %for.body.us\r\n %cond24.us = phi i32 [ %3, %cond.true14.us ], [ 0, %for.body.us ], [ 0, %cond.false7.us ]\r\n %4 = trunc i32 %cond24.us to i8\r\n %conv28.us = mul i8 0, %4\r\n %arrayidx31.us = getelementptr [2 x i64], ptr %i, i64 0, i64 %idxprom.us1\r\n %5 = load i64, ptr %arrayidx31.us, align 8\r\n %6 = trunc i64 %5 to i16\r\n %conv32.us = xor i16 %6, 0\r\n store i16 %conv32.us, ptr null, align 2\r\n %add.us = add i32 %l.046.us, 4\r\n %tobool.not.us = icmp eq i32 %add.us, 0\r\n br i1 %tobool.not.us, label %for.cond.for.cond.cleanup_crit_edge, label %for.body.us\r\n\r\nfor.cond.for.cond.cleanup_crit_edge: ; preds = %cond.end23.us\r\n store i8 %4, ptr null, align 1\r\n ret void\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-b,-e,-experimental-smctr,-experimental-ssctr,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-sha,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smdbltrp,-smepmp,-smmpm,-smnpm,-smrnmi,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssdbltrp,-ssnpm,-sspm,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-supm,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-svvptc,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zacas,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\n```\r\n\r\nCommand/backtrace:\r\n```\r\n> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt --passes \"loop-vectorize\" reduced.ll -f\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7522: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop) || planContainsAdditionalSimplifications(getPlanFor(LegacyVF.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt --passes loop-vectorize reduced.ll -f\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"h\"\r\n #0 0x000062cc6ec1de70 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x319de70)\r\n #1 0x000062cc6ec1b27f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x319b27f)\r\n #2 0x000062cc6ec1b3d5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x000074efe9a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x000074efe9a969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x000074efe9a969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x000074efe9a969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x000074efe9a42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x000074efe9a287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x000074efe9a2871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x000074efe9a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x000062cc6db65039 llvm::LoopVectorizationPlanner::computeBestVF() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20e5039)\r\n#12 0x000062cc6db7c50c llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20fc50c)\r\n#13 0x000062cc6db7f1e1 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20ff1e1)\r\n#14 0x000062cc6db7f857 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x20ff857)\r\n#15 0x000062cc6c963a06 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xee3a06)\r\n#16 0x000062cc6ea24b0f llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2fa4b0f)\r\n#17 0x000062cc6c966b96 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xee6b96)\r\n#18 0x000062cc6ea22e9b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2fa2e9b)\r\n#19 0x000062cc6c962ac6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xee2ac6)\r\n#20 0x000062cc6ea239fd llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2fa39fd)\r\n#21 0x000062cc6c15c33d llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x6dc33d)\r\n#22 0x000062cc6c14e1c1 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x6ce1c1)\r\n#23 0x000074efe9a29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#24 0x000074efe9a29e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#25 0x000074efe9a29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#26 0x000062cc6c144725 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x6c4725)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\n\r\nGodbolt: https://godbolt.org/z/v5K5Wbxcn\r\n\r\nFound via fuzzer\r\n\r\ncc @fhahn ",
"author": "patrick-rivos",
"labels": [
"release:backport",
"vectorizers",
"crash"
],
"comments": [
{
"author": "patrick-rivos",
"body": "Bisected to b3edc764f70f4e56807af60abdcfbef4dbdc5d95\r\ncc @ElvisWang123 "
},
{
"author": "ElvisWang123",
"body": "> Bisected to [b3edc76](https://github.com/llvm/llvm-project/commit/b3edc764f70f4e56807af60abdcfbef4dbdc5d95) cc @ElvisWang123\r\n\r\nI will take a look."
},
{
"author": "ElvisWang123",
"body": "The main difference of this case is that \r\n`LV: Found an estimated cost of 3 for VF vscale x 2 For instruction: %3 = trunc i64 %2 to i32` from legacy cost model and `Cost of 1 for VF vscale x 2: WIDEN-CAST ir<%3> = trunc ir<%2> to i32` from VPlan-based cost model.\r\n\r\nLegacy cost model will consider the new type after MinBW by `canTruncateToMinimalBitwidth()`. And finds that `i32` can further truncate to `i8`. So the legacy cost model will calculate the cost from `i64` to `i8`.\r\n But in the VPTransforms, the result type of this recipe cannot be shrunk from `i32` to `i8`. So the final recipes will only calculate the cost from `i64` to `i32`.\r\n\r\nI think this might be the MinBW transformation issue which cannot further truncate the type.\r\n\r\nBTW, the cost from the VPlan-based cost model is closer to the generated vector loop.\r\n\r\nSome cost model information:\r\nLegacy cost\r\n```\r\nLV: Found an estimated cost of 0 for VF vscale x 2 For instruction: %l.046.us = phi i32 [ %add.us, %cond.end23.us ], [ 0, %entry ]\r\nLV: Found an estimated cost of 2 for VF vscale x 2 For instruction: %conv284345.us = phi i8 [ %conv28.us, %cond.end23.us ], [ 0, %entr\r\ny ]\r\nLV: Found an estimated cost of 2 for VF vscale x 2 For instruction: %idxprom.us1 = zext i32 %l.046.us to i64\r\nLV: Found an estimated cost of 0 for VF vscale x 2 For instruction: %arrayidx3.us = getelementptr [2 x i16], ptr %k, i64 %idxprom.us1,\r\n i64 %idxprom.us\r\nLV: Found an estimated cost of 4 for VF vscale x 2 For instruction: %0 = load i16, ptr %arrayidx3.us, align 2\r\nLV: Found an estimated cost of 1 for VF vscale x 2 For instruction: %tobool4.not.us = icmp eq i16 %0, 0\r\nLV: Found an estimated cost of 0 for VF vscale x 2 For instruction: br i1 %tobool4.not.us, label %cond.false7.us, label %cond.end23.us\r\nLV: Found an estimated cost of 4 for VF vscale x 2 For instruction: %1 = load i64, ptr %i, align 8\r\nLV: Found an estimated cost of 2 for VF vscale x 2 For instruction: %shl.us = shl i64 0, %1\r\nLV: Found an estimated cost of 2 for VF vscale x 2 For instruction: %tobool12.not.us = icmp eq i64 %shl.us, 0\r\nLV: Found an estimated cost of 0 for VF vscale x 2 For instruction: br i1 %tobool12.not.us, label %cond.end23.us, label %cond.true14.u\r\ns\r\nLV: Found an estimated cost of 4 for VF vscale x 2 For instruction: %2 = load i64, ptr %i, align 8\r\n====> LV: Found an estimated cost of 3 for VF vscale x 2 For instruction: %3 = trunc i64 %2 to i32 <=====\r\nLV: Found an estimated cost of 0 for VF vscale x 2 For instruction: br label %cond.end23.us\r\nLV: Found an estimated cost of 2 for VF vscale x 2 For instruction: %cond24.us = phi i32 [ %3, %cond.true14.us ], [ 0, %for.body.us ],\r\n [ 0, %cond.false7.us ]\r\nLV: Found an estimated cost of 2 for VF vscale x 2 For instruction: %4 = trunc i32 %cond24.us to i8\r\nLV: Found an estimated cost of 1 for VF vscale x 2 For instruction: %conv28.us = mul i8 0, %4\r\nLV: Found an estimated cost of 0 for VF vscale x 2 For instruction: %arrayidx31.us = getelementptr [2 x i64], ptr %i, i64 0, i64 %idxp\r\nrom.us1\r\nLV: Found an estimated cost of 4 for VF vscale x 2 For instruction: %5 = load i64, ptr %arrayidx31.us, align 8\r\nLV: Found an estimated cost of 2 for VF vscale x 2 For instruction: %6 = trunc i64 %5 to i16\r\nLV: Found an estimated cost of 1 for VF vscale x 2 For instruction: %conv32.us = xor i16 %6, 0\r\nLV: Found an estimated cost of 3 for VF vscale x 2 For instruction: store i16 %conv32.us, ptr null, align 2\r\nLV: Found an estimated cost of 1 for VF vscale x 2 For instruction: %add.us = add i32 %l.046.us, 4\r\nLV: Found an estimated cost of 1 for VF vscale x 2 For instruction: %tobool.not.us = icmp eq i32 %add.us, 0\r\nLV: Found an estimated cost of 0 for VF vscale x 2 For instruction: br i1 %tobool.not.us, label %for.cond.for.cond.cleanup_crit_edge, \r\nlabel %for.body.us\r\nLV: Vector loop of width vscale x 2 costs: 10 (assuming a minimum vscale of 2).\r\n```\r\n\r\nVPlan-based\r\n```\r\nCost of 1 for VF vscale x 2: induction instruction %add.us = add i32 %l.046.us, 4\r\nCost of 0 for VF vscale x 2: induction instruction %l.046.us = phi i32 [ %add.us, %cond.end23.us ], [ 0, %entry ]\r\nCost of 1 for VF vscale x 2: exit condition instruction %tobool.not.us = icmp eq i32 %add.us, 0\r\nCost of 0 for VF vscale x 2: EMIT vp<%3> = CANONICAL-INDUCTION ir<0>, vp<%index.next>\r\nCost of 0 for VF vscale x 2: WIDEN-INDUCTION %l.046.us = phi %add.us, 0, ir<4>, vp<%0>\r\nCost of 2 for VF vscale x 2: FIRST-ORDER-RECURRENCE-PHI ir<%conv284345.us> = phi ir<0>, ir<%conv28.us>\r\nCost of 2 for VF vscale x 2: WIDEN-CAST ir<%idxprom.us1> = zext ir<%l.046.us> to i64\r\nCost of 0 for VF vscale x 2: WIDEN-GEP Inv[Var][Inv] ir<%arrayidx3.us> = getelementptr ir<%k>, ir<%idxprom.us1>, ir<%idxprom.us>\r\nCost of 4 for VF vscale x 2: WIDEN ir<%0> = load ir<%arrayidx3.us>\r\nCost of 1 for VF vscale x 2: WIDEN ir<%tobool4.not.us> = icmp eq ir<%0>, ir<0>\r\nCost of 4 for VF vscale x 2: WIDEN ir<%1> = load ir<%i>, ir<%tobool4.not.us>\r\nCost of 2 for VF vscale x 2: WIDEN ir<%shl.us> = shl ir<0>, ir<%1>\r\nCost of 2 for VF vscale x 2: WIDEN ir<%tobool12.not.us> = icmp eq ir<%shl.us>, ir<0>\r\nCost of 0 for VF vscale x 2: EMIT vp<%4> = not ir<%tobool12.not.us>\r\nCost of 0 for VF vscale x 2: EMIT vp<%5> = logical-and ir<%tobool4.not.us>, vp<%4>\r\nCost of 4 for VF vscale x 2: WIDEN ir<%2> = load ir<%i>, vp<%5>\r\n====> Cost of 1 for VF vscale x 2: WIDEN-CAST ir<%3> = trunc ir<%2> to i32 <=======\r\nCost of 0 for VF vscale x 2: EMIT vp<%6> = not ir<%tobool4.not.us>\r\nCost of 2 for VF vscale x 2: BLEND ir<%cond24.us> = ir<0> ir<%3>/vp<%5> ir<0>/vp<%6>\r\nCost of 2 for VF vscale x 2: WIDEN-CAST ir<%4> = trunc ir<%cond24.us> to i8\r\nCost of 1 for VF vscale x 2: WIDEN ir<%conv28.us> = mul ir<0>, ir<%4>\r\nCost of 0 for VF vscale x 2: WIDEN-GEP Inv[Inv][Var] ir<%arrayidx31.us> = getelementptr ir<%i>, ir<0>, ir<%idxprom.us1>\r\nCost of 4 for VF vscale x 2: WIDEN ir<%5> = load ir<%arrayidx31.us>\r\nCost of 2 for VF vscale x 2: WIDEN-CAST ir<%6> = trunc ir<%5> to i16\r\nCost of 1 for VF vscale x 2: WIDEN ir<%conv32.us> = xor ir<%6>, ir<0>\r\nCost of 3 for VF vscale x 2: REPLICATE store ir<%conv32.us>, ir<null>\r\nCost of 0 for VF vscale x 2: EMIT vp<%index.next> = add nuw vp<%3>, vp<%1>\r\nCost of 0 for VF vscale x 2: EMIT branch-on-count vp<%index.next>, vp<%2>\r\nCost of 0 for VF vscale x 2: vector loop backedge\r\nCost for VF vscale x 2: 39\r\n```\r\nGenerated vector.body\r\n``` \r\nvector.body: ; preds = %vector.body, %vector.ph\r\n %index = phi i32 [ 0, %vector.ph ]\r\n %vec.ind = phi <vscale x 2 x i32> [ %induction, %vector.ph ], [ %vec.ind.next, %vector.ph ]\r\n %vector.recur = phi <vscale x 2 x i8> [ %vector.recur.init, %vector.ph ]\r\n %vec.ind.next = add <vscale x 2 x i32> %vec.ind, %.splat\r\n %15 = zext <vscale x 2 x i32> %vec.ind to <vscale x 2 x i64>\r\n %16 = getelementptr [2 x i16], ptr %k, <vscale x 2 x i64> %15, i64 %idxprom.us\r\n %wide.masked.gather = call <vscale x 2 x i16> @llvm.masked.gather.nxv2i16.nxv2p0(<vscale x 2 x ptr> %16, i32 2, <vscale x 2 x i1> shufflevector (<vscale x 2 x i1> insertelement (<vscale x 2 x i1> poison, i1 true, i64 0), <vscale x 2 x i1> poison, <vscale x 2 x i32> zeroinitializer), <vscale x 2 x i16> poison)\r\n %17 = icmp eq <vscale x 2 x i16> %wide.masked.gather, zeroinitializer\r\n %wide.masked.gather1 = call <vscale x 2 x i64> @llvm.masked.gather.nxv2i64.nxv2p0(<vscale x 2 x ptr> %broadcast.splat, i32 8, <vscale x 2 x i1> %17, <vscale x 2 x i64> poison)\r\n %18 = shl <vscale x 2 x i64> zeroinitializer, %wide.masked.gather1\r\n %19 = icmp eq <vscale x 2 x i64> %18, zeroinitializer\r\n %20 = xor <vscale x 2 x i1> %19, shufflevector (<vscale x 2 x i1> insertelement (<vscale x 2 x i1> poison, i1 true, i64 0), <vscale x 2 x i1> poison, <vscale x 2 x i32> zeroinitializer)\r\n %21 = select <vscale x 2 x i1> %17, <vscale x 2 x i1> %20, <vscale x 2 x i1> zeroinitializer\r\n %wide.masked.gather2 = call <vscale x 2 x i64> @llvm.masked.gather.nxv2i64.nxv2p0(<vscale x 2 x ptr> %broadcast.splat, i32 8, <vscale x 2 x i1> %21, <vscale x 2 x i64> poison)\r\n %22 = trunc <vscale x 2 x i64> %wide.masked.gather2 to <vscale x 2 x i32> <================\r\n %23 = xor <vscale x 2 x i1> %17, shufflevector (<vscale x 2 x i1> insertelement (<vscale x 2 x i1> poison, i1 true, i64 0), <vscale x 2 x i1> poison, <vscale x 2 x i32> zeroinitializer)\r\n %predphi = select <vscale x 2 x i1> %21, <vscale x 2 x i32> %22, <vscale x 2 x i32> zeroinitializer\r\n %predphi3 = select <vscale x 2 x i1> %23, <vscale x 2 x i32> zeroinitializer, <vscale x 2 x i32> %predphi\r\n %24 = trunc <vscale x 2 x i32> %predphi3 to <vscale x 2 x i8>\r\n %25 = mul <vscale x 2 x i8> zeroinitializer, %24\r\n %26 = getelementptr [2 x i64], ptr %i, i64 0, <vscale x 2 x i64> %15\r\n %wide.masked.gather4 = call <vscale x 2 x i64> @llvm.masked.gather.nxv2i64.nxv2p0(<vscale x 2 x ptr> %26, i32 8, <vscale x 2 x i1> shufflevector (<vscale x 2 x i1> insertelement (<vscale x 2 x i1> poison, i1 true, i64 0), <vscale x 2 x i1> poison, <vscale x 2 x i32> zeroinitializer), <vscale x 2 x i64> poison)\r\n %27 = trunc <vscale x 2 x i64> %wide.masked.gather4 to <vscale x 2 x i16>\r\n %28 = xor <vscale x 2 x i16> %27, zeroinitializer\r\n %29 = call i32 @llvm.vscale.i32()\r\n%30 = mul i32 %29, 2\r\n %31 = sub i32 %30, 1\r\n %32 = extractelement <vscale x 2 x i16> %28, i32 %31\r\n store i16 %32, ptr null, align 2\r\n %index.next = add nuw i32 %index, %7\r\n %33 = icmp eq i32 %index.next, %n.vec\r\n br i1 %33, <null operand!>, label %vector.body\r\n..."
},
{
"author": "ElvisWang123",
"body": "In this case, we can find that all the following recipes can be shrinkage to `i8`.\n```\n====> Cost of 1 for VF vscale x 2: WIDEN-CAST ir<%3> = trunc ir<%2> to i32 <=======\nCost of 0 for VF vscale x 2: EMIT vp<%6> = not ir<%tobool4.not.us>\nCost of 2 for VF vscale x 2: BLEND ir<%cond24.us> = ir<0> ir<%3>/vp<%5> ir<0>/vp<%6>\nCost of 2 for VF vscale x 2: WIDEN-CAST ir<%4> = trunc ir<%cond24.us> to i8\nCost of 1 for VF vscale x 2: WIDEN ir<%conv28.us> = mul ir<0>, ir<%4>\n```\nBut in current minimal-bit-width analysis, there are some checks prevent this type shrinkage.\n1. If any of instructions in the EC (equivalent class) is PHI node, minimal-bit-width wont narrow the type.\n\nTo support type shrinkage for this case. We need to change the MinBW which is the analysis based on the scalar instructions.\n\nModify current minimal-bit-width architecture (Analysis scalar instructions). This implementation may not be accurate since the VPlan may contains some of the recipe without underlying instructions.\n1. Support Phi node in the EC. Although induction phi should not be modified and the recurrence descriptor will handle the type shrinkage. We still need the information from MinBW to shrinkage the non-header phis.\n2. Add the support of `VPBlendRecipe` in `truncateToMinimalBitWidth()` in VPTransform.\n\nOr rewrite a new minimal-bit-width analysis based on Vplan. This implementation will be more accurate than the current analysis but will be more works.\n\n1. To support Vplan-based MinBW, we may need to rewrite a new VPlan-based DemandedBits analysis.\n\n\n@fhahn What do you think about the these two implementations, modify current MinBW or rewrite a new vplan-based MinBW. Or do you have a better implementation to make MinBW more accurate on Vplan?\n\n@patrick-rivos BTW, the C program in this issue is a little bit weird. Without initializing `a`, loop vectorizer cannot recognize the reduction pattern of the `a *= (signed char)((f ? 0 : k[l][l]) ?: (_Bool)(d << j[8][l][e]) ? i[l][l] : c);`. However, we still have some issue on the minimal-bit-width analysis."
},
{
"author": "cardigan1008",
"body": "Hi, there's another case that triggers this crash:\n\n```c\nint a;\nint b(int c) {\n int d = 0;\n for (; d < c; d++) {\n a++;\n if (d != c - 1)\n a++;\n }\n}\nint *e;\nint f;\nvoid g() {\n for (; e[f]; f++)\n e[b(f + 9)];\n}\n```\n\nCompiler Explorer: https://godbolt.org/z/16Tr15KGx\n\nHope this helps :)"
},
{
"author": "ElvisWang123",
"body": "@cardigan1008 Thanks for your test case. I will take a look."
}
]
} | true | null |
124275 | https://github.com/llvm/llvm-project/issues/124275 | miscompilation | 35df525fd00c2037ef144189ee818b7d612241ff | 2025-01-24T14:33:26 | [
"llvm/test/Analysis/ValueTracking"
] | {
"fix_commit": "c2fba023475fddb893eac29dc9f34dfbdb221cd5",
"components": [
"ValueTracking"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": [
[
593,
603
],
[
610,
620
],
[
1673,
1680
],
[
1705,
1713
]
],
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": [
"breakSelfRecursivePHI",
"computeKnownBitsFromOperator"
],
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit c2fba023475fddb893eac29dc9f34dfbdb221cd5
Author: goldsteinn <[email protected]>
Date: Tue Jan 28 15:54:00 2025 -0600
[ValueTracking] Fix bug of using wrong condition for deducing KnownBits (#124481)
- **[ValueTracking] Add test for issue 124275**
- **[ValueTracking] Fix bug of using wrong condition for deducing
KnownBits**
Fixes https://github.com/llvm/llvm-project/issues/124275
Bug was introduced by https://github.com/llvm/llvm-project/pull/114689
Now that computeKnownBits supports breaking out of recursive Phi
nodes, `IncValue` can be an operand of a different Phi than `P`. This
breaks the previous assumptions we had when using the possibly
condition at `CxtI` to constrain `IncValue`.
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index eba728c7c8c3..b63a0a07f7de 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -593,11 +593,14 @@ static bool cmpExcludesZero(CmpInst::Predicate Pred, const Value *RHS) {
}
static void breakSelfRecursivePHI(const Use *U, const PHINode *PHI,
- Value *&ValOut, Instruction *&CtxIOut) {
+ Value *&ValOut, Instruction *&CtxIOut,
+ const PHINode **PhiOut = nullptr) {
ValOut = U->get();
if (ValOut == PHI)
return;
CtxIOut = PHI->getIncomingBlock(*U)->getTerminator();
+ if (PhiOut)
+ *PhiOut = PHI;
Value *V;
// If the Use is a select of this phi, compute analysis on other arm to break
// recursion.
@@ -610,11 +613,13 @@ static void breakSelfRecursivePHI(const Use *U, const PHINode *PHI,
// incoming value to break recursion.
// TODO: We could handle any number of incoming edges as long as we only have
// two unique values.
- else if (auto *IncPhi = dyn_cast<PHINode>(ValOut);
- IncPhi && IncPhi->getNumIncomingValues() == 2) {
+ if (auto *IncPhi = dyn_cast<PHINode>(ValOut);
+ IncPhi && IncPhi->getNumIncomingValues() == 2) {
for (int Idx = 0; Idx < 2; ++Idx) {
if (IncPhi->getIncomingValue(Idx) == PHI) {
ValOut = IncPhi->getIncomingValue(1 - Idx);
+ if (PhiOut)
+ *PhiOut = IncPhi;
CtxIOut = IncPhi->getIncomingBlock(1 - Idx)->getTerminator();
break;
}
@@ -1673,8 +1678,9 @@ static void computeKnownBitsFromOperator(const Operator *I,
Known.One.setAllBits();
for (const Use &U : P->operands()) {
Value *IncValue;
+ const PHINode *CxtPhi;
Instruction *CxtI;
- breakSelfRecursivePHI(&U, P, IncValue, CxtI);
+ breakSelfRecursivePHI(&U, P, IncValue, CxtI, &CxtPhi);
// Skip direct self references.
if (IncValue == P)
continue;
@@ -1705,9 +1711,10 @@ static void computeKnownBitsFromOperator(const Operator *I,
m_Br(m_c_ICmp(Pred, m_Specific(IncValue), m_APInt(RHSC)),
m_BasicBlock(TrueSucc), m_BasicBlock(FalseSucc)))) {
// Check for cases of duplicate successors.
- if ((TrueSucc == P->getParent()) != (FalseSucc == P->getParent())) {
+ if ((TrueSucc == CxtPhi->getParent()) !=
+ (FalseSucc == CxtPhi->getParent())) {
// If we're using the false successor, invert the predicate.
- if (FalseSucc == P->getParent())
+ if (FalseSucc == CxtPhi->getParent())
Pred = CmpInst::getInversePredicate(Pred);
// Get the knownbits implied by the incoming phi condition.
auto CR = ConstantRange::makeExactICmpRegion(Pred, *RHSC);
| [
{
"file": "llvm/test/Analysis/ValueTracking/phi-known-bits.ll",
"commands": [
"opt -O1 < %s -S"
],
"tests": [
{
"test_name": "issue_124275_wrong_br_direction",
"test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@c = dso_local global i32 1, align 4\n@a = dso_local global i32 0, align 4\n@b = dso_local global i32 0, align 4\n\ndefine dso_local i32 @main() #0 {\nentry:\n %retval = alloca i32, align 4\n %d = alloca i32, align 4\n store i32 0, ptr %retval, align 4\n store i32 -1, ptr @a, align 4\n %0 = load i32, ptr @a, align 4\n %cmp = icmp ult i32 %0, 1\n br i1 %cmp, label %if.then, label %if.end\n\nif.then:\n br label %e\n\nif.end:\n %1 = load i32, ptr @c, align 4\n store i32 %1, ptr %d, align 4\n %2 = load i32, ptr %d, align 4\n %tobool = icmp ne i32 %2, 0\n br i1 %tobool, label %if.then1, label %if.end2\n\nif.then1:\n br label %e\n\ne:\n br label %if.end2\n\nif.end2:\n %3 = load i32, ptr %d, align 4\n %tobool3 = icmp ne i32 %3, 0\n br i1 %tobool3, label %if.end5, label %if.then4\n\nif.then4:\n unreachable\n\nif.end5:\n %4 = load i32, ptr @b, align 4\n %tobool6 = icmp ne i32 %4, 0\n br i1 %tobool6, label %if.then7, label %if.end8\n\nif.then7:\n br label %e\n\nif.end8:\n ret i32 0\n}\n\nattributes #0 = { noinline nounwind uwtable \"frame-pointer\"=\"all\" \"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\" }\n\n!llvm.module.flags = !{!0, !1, !2, !3, !4, !5}\n!llvm.ident = !{!6}\n\n!0 = !{i32 7, !\"Dwarf Version\", i32 4}\n!1 = !{i32 1, !\"wchar_size\", i32 4}\n!2 = !{i32 8, !\"PIC Level\", i32 2}\n!3 = !{i32 7, !\"PIE Level\", i32 2}\n!4 = !{i32 7, !\"uwtable\", i32 2}\n!5 = !{i32 7, !\"frame-pointer\", i32 2}\n!6 = !{!\"clang version 21.0.0git (https://github.com/llvm/llvm-project.git 5c3c0a8cec9205efba78583bd0b8a646270968a1)\"}\n",
"lli_expected_out": null,
"additional_args": "-src-unroll=4 -tgt-unroll=4"
}
]
}
] | {
"title": "wrong code at -O1 and above on x86_64-linux-gnu",
"body": "It appears to be a recent regression from 19.1.0. \n\nCompiler Explorer: https://godbolt.org/z/haMfGoo6h\n\n```\n[548] % clangtk -v\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git ddd2f57b29661f21308eec0400fa92a6d075b0c6)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nCandidate multilib: .;@m64\nSelected multilib: .;@m64\nFound CUDA installation: /usr/local/cuda, version 12.1\n[549] % \n[549] % clangtk -O1 small.c\n[550] % ./a.out\nAborted\n[551] % \n[551] % cat small.c\nint printf(const char *, ...);\nunsigned a;\nint b, c = 1;\nint main() {\n int d;\n a = -1;\n if (a < 1)\n goto e;\n d = c;\n if (d) {\n e:;\n }\n if (!d)\n __builtin_abort();\n if (b)\n goto e;\n return 0;\n}\n```",
"author": "zhendongsu",
"labels": [
"miscompilation",
"llvm:analysis"
],
"comments": [
{
"author": "zhendongsu",
"body": "Another likely related test:\n```\n[552] % clangtk -v\nclang version 20.0.0git (https://github.com/llvm/llvm-project.git ddd2f57b29661f21308eec0400fa92a6d075b0c6)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /local/home/suz/suz-local/software/local/clang-trunk/bin\nBuild config: +assertions\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12\nCandidate multilib: .;@m64\nSelected multilib: .;@m64\nFound CUDA installation: /usr/local/cuda, version 12.1\n[553] % \n[553] % clangtk -O0 small.c\n[554] % ./a.out\n[555] % \n[555] % clangtk -O1 small.c\n[556] % timeout -s 9 5 ./a.out\nKilled\n[557] % cat small.c\nint a, b;\nint main() {\n {\n int c;\n if (a && 0)\n goto d;\n }\n int e = -~b;\n if (e) {\n d:;\n }\n while (!e)\n goto d;\n return 0;\n}\n```"
},
{
"author": "antoniofrighetto",
"body": "Reduced to:\n\n```llvm\n; opt -p instcombine small.ll\ndefine i32 @small(i32 noundef %0) {\n %2 = xor i32 %0, 1\n %3 = sub i32 0, %2\n %4 = icmp ne i32 %3, 0\n br i1 %4, label %5, label %6\n\n5: ; preds = %6, %1\n %.0 = phi i32 [ %.1, %6 ], [ %3, %1 ]\n br label %6\n\n6: ; preds = %5, %1\n %.1 = phi i32 [ %.0, %5 ], [ 0, %1 ]\n %7 = icmp ne i32 %.1, 0\n %8 = xor i1 %7, true\n br i1 %8, label %5, label %9\n\n9: ; preds = %6\n ret i32 0\n}\n```"
},
{
"author": "goldsteinn",
"body": "Fix at: https://github.com/llvm/llvm-project/pull/124481"
}
]
} | true | null |
121745 | https://github.com/llvm/llvm-project/issues/121745 | miscompilation | 3874c64418d2a7e36eab9af9253d905b48b36078 | 2025-01-06T10:26:21 | [
"llvm/test/Transforms/LoopVectorize"
] | {
"fix_commit": "f9369cc602272796c15de1065a782f812e791df3",
"components": [
"LoopVectorize"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [
[
562,
582
],
[
1086,
1103
]
],
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [
"VPlanTransforms::adjustFixedOrderRecurrences",
"VPlanTransforms::clearReductionWrapFlags",
"collectUsersRecursively",
"createScalarIVSteps",
"legalizeAndOptimizeInductions"
],
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit f9369cc602272796c15de1065a782f812e791df3
Author: Florian Hahn <[email protected]>
Date: Mon Jan 6 22:40:41 2025 +0000
[VPlan] Make sure last IV increment value is available if needed.
Legalize extract-from-ends using uniform VPReplicateRecipe of wide
inductions to use regular VPReplicateRecipe, so the correct end value
is available.
Fixes https://github.com/llvm/llvm-project/issues/121745.
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 395287bde76f..3e3f5adf73a0 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -562,21 +562,63 @@ createScalarIVSteps(VPlan &Plan, InductionDescriptor::InductionKind Kind,
return Builder.createScalarIVSteps(InductionOpcode, FPBinOp, BaseIV, Step);
}
+static SmallVector<VPUser *> collectUsersRecursively(VPValue *V) {
+ SetVector<VPUser *> Users(V->user_begin(), V->user_end());
+ for (unsigned I = 0; I != Users.size(); ++I) {
+ VPRecipeBase *Cur = cast<VPRecipeBase>(Users[I]);
+ if (isa<VPHeaderPHIRecipe>(Cur))
+ continue;
+ for (VPValue *V : Cur->definedValues())
+ Users.insert(V->user_begin(), V->user_end());
+ }
+ return Users.takeVector();
+}
+
/// Legalize VPWidenPointerInductionRecipe, by replacing it with a PtrAdd
/// (IndStart, ScalarIVSteps (0, Step)) if only its scalar values are used, as
/// VPWidenPointerInductionRecipe will generate vectors only. If some users
/// require vectors while other require scalars, the scalar uses need to extract
/// the scalars from the generated vectors (Note that this is different to how
-/// int/fp inductions are handled). Also optimize VPWidenIntOrFpInductionRecipe,
-/// if any of its users needs scalar values, by providing them scalar steps
-/// built on the canonical scalar IV and update the original IV's users. This is
-/// an optional optimization to reduce the needs of vector extracts.
+/// int/fp inductions are handled). Legalize extract-from-ends using uniform
+/// VPReplicateRecipe of wide inductions to use regular VPReplicateRecipe, so
+/// the correct end value is available. Also optimize
+/// VPWidenIntOrFpInductionRecipe, if any of its users needs scalar values, by
+/// providing them scalar steps built on the canonical scalar IV and update the
+/// original IV's users. This is an optional optimization to reduce the needs of
+/// vector extracts.
static void legalizeAndOptimizeInductions(VPlan &Plan) {
+ using namespace llvm::VPlanPatternMatch;
SmallVector<VPRecipeBase *> ToRemove;
VPBasicBlock *HeaderVPBB = Plan.getVectorLoopRegion()->getEntryBasicBlock();
bool HasOnlyVectorVFs = !Plan.hasVF(ElementCount::getFixed(1));
VPBuilder Builder(HeaderVPBB, HeaderVPBB->getFirstNonPhi());
for (VPRecipeBase &Phi : HeaderVPBB->phis()) {
+ auto *PhiR = dyn_cast<VPHeaderPHIRecipe>(&Phi);
+ if (!PhiR)
+ break;
+
+ // Check if any uniform VPReplicateRecipes using the phi recipe are used by
+ // ExtractFromEnd. Those must be replaced by a regular VPReplicateRecipe to
+ // ensure the final value is available.
+ // TODO: Remove once uniformity analysis is done on VPlan.
+ for (VPUser *U : collectUsersRecursively(PhiR)) {
+ auto *ExitIRI = dyn_cast<VPIRInstruction>(U);
+ VPValue *Op;
+ if (!ExitIRI || !match(ExitIRI->getOperand(0),
+ m_VPInstruction<VPInstruction::ExtractFromEnd>(
+ m_VPValue(Op), m_VPValue())))
+ continue;
+ auto *RepR = dyn_cast<VPReplicateRecipe>(Op);
+ if (!RepR || !RepR->isUniform())
+ continue;
+ assert(!RepR->isPredicated() && "RepR must not be predicated");
+ Instruction *I = RepR->getUnderlyingInstr();
+ auto *Clone =
+ new VPReplicateRecipe(I, RepR->operands(), /*IsUniform*/ false);
+ Clone->insertAfter(RepR);
+ RepR->replaceAllUsesWith(Clone);
+ }
+
// Replace wide pointer inductions which have only their scalars used by
// PtrAdd(IndStart, ScalarIVSteps (0, Step)).
if (auto *PtrIV = dyn_cast<VPWidenPointerInductionRecipe>(&Phi)) {
@@ -1086,18 +1128,6 @@ bool VPlanTransforms::adjustFixedOrderRecurrences(VPlan &Plan,
return true;
}
-static SmallVector<VPUser *> collectUsersRecursively(VPValue *V) {
- SetVector<VPUser *> Users(V->user_begin(), V->user_end());
- for (unsigned I = 0; I != Users.size(); ++I) {
- VPRecipeBase *Cur = cast<VPRecipeBase>(Users[I]);
- if (isa<VPHeaderPHIRecipe>(Cur))
- continue;
- for (VPValue *V : Cur->definedValues())
- Users.insert(V->user_begin(), V->user_end());
- }
- return Users.takeVector();
-}
-
void VPlanTransforms::clearReductionWrapFlags(VPlan &Plan) {
for (VPRecipeBase &R :
Plan.getVectorLoopRegion()->getEntryBasicBlock()->phis()) {
| [
{
"file": "llvm/test/Transforms/LoopVectorize/iv_outside_user.ll",
"commands": [
"opt -S -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=2 < %s",
"opt -S -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=1 < %s"
],
"tests": [
{
"test_name": "test_iv_uniform_with_outside_use_scev_simplification",
"test_body": "define i32 @test_iv_uniform_with_outside_use_scev_simplification(ptr %dst) {\nentry:\n %step.1 = sext i8 0 to i32\n %step.2 = add nsw i32 %step.1, 1\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.dst = getelementptr inbounds i16, ptr %dst, i32 %iv\n store i16 0, ptr %gep.dst, align 2\n %iv.next = add i32 %step.2, %iv\n %cmp.i = icmp slt i32 %iv.next, 8\n br i1 %cmp.i, label %loop, label %e.exit\n\ne.exit: ; preds = %loop\n %res = phi i32 [ %iv.next, %loop ]\n ret i32 %res\n}\n",
"lli_expected_out": null,
"additional_args": "-src-unroll=8 -tgt-unroll=8"
}
]
}
] | {
"title": "[clang] Miscompilation at -O2/3",
"body": "This code prints 8 at `-O0/1` and prints 1 at `-O2/3`:\n\n```c\nint printf(const char *, ...);\nstatic char a;\nstatic char *b = &a;\nstatic int c;\nshort d;\nvoid e() {\n short f[8];\n char **g[] = {&b, &b};\n c = 0;\n for (; c < 8; c = 81 + 462704684 + *b - 462704765 + c + 1)\n f[c] = 0;\n d = f[5];\n}\nint main() {\n e();\n printf(\"%d\\n\", c);\n}\n```\n\nCompiler Explorer: https://godbolt.org/z/MEKz8oncP\n\nBisected to https://github.com/llvm/llvm-project/commit/df4a615c988f3ae56f7e68a7df86acb60f16493a, which was committed by @fhahn ",
"author": "cardigan1008",
"labels": [
"miscompilation",
"vectorizers"
],
"comments": [
{
"author": "dtcxzyw",
"body": "Reduced testcase: https://alive2.llvm.org/ce/z/6Bg63G\n```\n; bin/opt -passes=loop-vectorize test.ll -S\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @src() {\nentry:\n %f.i = alloca [8 x i16], align 16\n %conv.i = sext i8 0 to i32\n %invariant.op.i = add nsw i32 %conv.i, 1\n br label %for.body.i\n\nfor.body.i: ; preds = %for.body.i, %entry\n %0 = phi i32 [ 0, %entry ], [ %add2.reass.i, %for.body.i ]\n %idxprom.i = sext i32 %0 to i64\n %arrayidx.i = getelementptr [8 x i16], ptr %f.i, i64 0, i64 %idxprom.i\n store i16 0, ptr %arrayidx.i, align 2\n %add2.reass.i = add i32 %invariant.op.i, %0\n %cmp.i = icmp slt i32 %add2.reass.i, 8\n br i1 %cmp.i, label %for.body.i, label %e.exit\n\ne.exit: ; preds = %for.body.i\n %add2.reass.i.lcssa = phi i32 [ %add2.reass.i, %for.body.i ]\n ret i32 %add2.reass.i.lcssa\n}\n```"
},
{
"author": "fhahn",
"body": "Looking into it now, thanks"
},
{
"author": "yaoxinliu",
"body": "Thank God! clang19 works as expected."
}
]
} | true | null |
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/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": [
[
3369,
3376
]
],
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": [
"InstCombinerImpl::foldAndOrOfICmps"
],
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 3bf2295ee0ebd1eafe66ca15dff44bdb31e6198a
Author: Yingwei Zheng <[email protected]>
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 | null |
82243 | https://github.com/llvm/llvm-project/issues/82243 | miscompilation | fcd6549e5801de938935b93fd2d13020b42eebdb | 2024-02-19T12:48:24 | [
"llvm/test/Transforms/IndVarSimplify"
] | {
"fix_commit": "4db93e5d56440be44d8ad2036e2579208c82ad37",
"components": [
"ScalarEvolution",
"SimplifyIndVar"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": [
[
1131,
1137
],
[
1731,
1737
],
[
1825,
1835
],
[
1996,
2006
],
[
2024,
2030
]
],
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": [
[
258,
263
]
],
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": [
[
771,
776
]
],
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": [
"WidenIV::createWideIV",
"WidenIV::widenIVUse"
],
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": [
"SCEVExpander::hoistIVInc"
],
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 4db93e5d56440be44d8ad2036e2579208c82ad37
Author: Florian Hahn <[email protected]>
Date: Tue Feb 20 14:03:25 2024 +0000
[IndVars] Recompute flags if needed in widenIVUse of IV increment. (#82352)
widenIVUse may hoist a wide induction increment and introduce new uses,
but does not recompute the wrap flags. In some cases this can make the
new uses of the wide IV inc more poisonous.
Update the code to recompute flags if needed when hoisting an IV. If
both the narrow and wide IV increment's flags match and we can re-use
the flags from the increments, there's no need to recompute the flags,
as the replacement won't make the new uses of the wide IV's increment
more poisonous.
Note that this also updates a stale comment which claimed that the widen
increment is only used if it dominates the new use.
The helper should also be used to guard the code added in da437330be,
which I am planning on doing separately once the helper lands.
Fixes https://github.com/llvm/llvm-project/issues/82243.
diff --git a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
index 035705b7f4b7..fa10443f14bb 100644
--- a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
+++ b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
@@ -258,6 +258,14 @@ public:
bool hoistIVInc(Instruction *IncV, Instruction *InsertPos,
bool RecomputePoisonFlags = false);
+ /// Return true if both increments directly increment the corresponding IV PHI
+ /// nodes and have the same opcode. It is not safe to re-use the flags from
+ /// the original increment, if it is more complex and SCEV expansion may have
+ /// yielded a more simplified wider increment.
+ static bool canReuseFlagsFromOriginalIVInc(PHINode *OrigPhi, PHINode *WidePhi,
+ Instruction *OrigInc,
+ Instruction *WideInc);
+
/// replace congruent phis with their most canonical representative. Return
/// the number of phis eliminated.
unsigned replaceCongruentIVs(Loop *L, const DominatorTree *DT,
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index 3a28909473d9..fbe1dba5b8d4 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -771,6 +771,15 @@ bool SCEVExpander::hoistIVInc(Instruction *IncV, Instruction *InsertPos,
return true;
}
+bool SCEVExpander::canReuseFlagsFromOriginalIVInc(PHINode *OrigPhi,
+ PHINode *WidePhi,
+ Instruction *OrigInc,
+ Instruction *WideInc) {
+ return match(OrigInc, m_c_BinOp(m_Specific(OrigPhi), m_Value())) &&
+ match(WideInc, m_c_BinOp(m_Specific(WidePhi), m_Value())) &&
+ OrigInc->getOpcode() == WideInc->getOpcode();
+}
+
/// Determine if this cyclic phi is in a form that would have been generated by
/// LSR. We don't care if the phi was actually expanded in this pass, as long
/// as it is in a low-cost form, for example, no implied multiplication. This
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
index 5aa6df49e7f6..66bba1ca2f1d 100644
--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -1131,7 +1131,8 @@ protected:
const SCEV *getSCEVByOpCode(const SCEV *LHS, const SCEV *RHS,
unsigned OpCode) const;
- Instruction *widenIVUse(NarrowIVDefUse DU, SCEVExpander &Rewriter);
+ Instruction *widenIVUse(NarrowIVDefUse DU, SCEVExpander &Rewriter,
+ PHINode *OrigPhi, PHINode *WidePhi);
bool widenLoopCompare(NarrowIVDefUse DU);
bool widenWithVariantUse(NarrowIVDefUse DU);
@@ -1731,7 +1732,9 @@ bool WidenIV::widenWithVariantUse(WidenIV::NarrowIVDefUse DU) {
/// Determine whether an individual user of the narrow IV can be widened. If so,
/// return the wide clone of the user.
-Instruction *WidenIV::widenIVUse(WidenIV::NarrowIVDefUse DU, SCEVExpander &Rewriter) {
+Instruction *WidenIV::widenIVUse(WidenIV::NarrowIVDefUse DU,
+ SCEVExpander &Rewriter, PHINode *OrigPhi,
+ PHINode *WidePhi) {
assert(ExtendKindMap.count(DU.NarrowDef) &&
"Should already know the kind of extension used to widen NarrowDef");
@@ -1825,11 +1828,18 @@ Instruction *WidenIV::widenIVUse(WidenIV::NarrowIVDefUse DU, SCEVExpander &Rewri
if (!WideAddRec.first)
return nullptr;
- // Reuse the IV increment that SCEVExpander created as long as it dominates
- // NarrowUse.
+ // Reuse the IV increment that SCEVExpander created. Recompute flags, unless
+ // the flags for both increments agree and it is safe to use the ones from
+ // the original inc. In that case, the new use of the wide increment won't
+ // be more poisonous.
+ bool NeedToRecomputeFlags =
+ !SCEVExpander::canReuseFlagsFromOriginalIVInc(OrigPhi, WidePhi,
+ DU.NarrowUse, WideInc) ||
+ DU.NarrowUse->hasNoUnsignedWrap() != WideInc->hasNoUnsignedWrap() ||
+ DU.NarrowUse->hasNoSignedWrap() != WideInc->hasNoSignedWrap();
Instruction *WideUse = nullptr;
if (WideAddRec.first == WideIncExpr &&
- Rewriter.hoistIVInc(WideInc, DU.NarrowUse))
+ Rewriter.hoistIVInc(WideInc, DU.NarrowUse, NeedToRecomputeFlags))
WideUse = WideInc;
else {
WideUse = cloneIVUser(DU, WideAddRec.first);
@@ -1996,11 +2006,9 @@ PHINode *WidenIV::createWideIV(SCEVExpander &Rewriter) {
// the same opcode. It is not safe to re-use the flags from the original
// increment, if it is more complex and SCEV expansion may have yielded a
// more simplified wider increment.
- bool MatchingOps =
- match(OrigInc, m_c_BinOp(m_Specific(OrigPhi), m_Value())) &&
- match(WideInc, m_c_BinOp(m_Specific(WidePhi), m_Value())) &&
- OrigInc->getOpcode() == WideInc->getOpcode();
- if (MatchingOps && isa<OverflowingBinaryOperator>(OrigInc) &&
+ if (SCEVExpander::canReuseFlagsFromOriginalIVInc(OrigPhi, WidePhi,
+ OrigInc, WideInc) &&
+ isa<OverflowingBinaryOperator>(OrigInc) &&
isa<OverflowingBinaryOperator>(WideInc)) {
WideInc->setHasNoUnsignedWrap(WideInc->hasNoUnsignedWrap() ||
OrigInc->hasNoUnsignedWrap());
@@ -2024,7 +2032,7 @@ PHINode *WidenIV::createWideIV(SCEVExpander &Rewriter) {
// Process a def-use edge. This may replace the use, so don't hold a
// use_iterator across it.
- Instruction *WideUse = widenIVUse(DU, Rewriter);
+ Instruction *WideUse = widenIVUse(DU, Rewriter, OrigPhi, WidePhi);
// Follow all def-use edges from the previous narrow use.
if (WideUse)
| [
{
"file": "llvm/test/Transforms/IndVarSimplify/hoist-wide-inc-for-narrow-use-recompute-flags.ll",
"commands": [
"opt -p indvars -S %s"
],
"tests": [
{
"test_name": "test_pr82243",
"test_body": "target datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128\"\n\ndefine void @test_pr82243(ptr %f) {\nentry:\n br label %outer.header\n\nouter.header: ; preds = %outer.latch, %entry\n %iv = phi i32 [ 1, %entry ], [ %iv.next, %outer.latch ]\n %iv.sext = sext i32 %iv to i64\n %gep.iv.ext = getelementptr i32, ptr %f, i64 %iv.sext\n store i32 1, ptr %gep.iv.ext, align 4\n %sub = add i32 %iv, -1\n %shl = shl i32 123, %sub\n %gep.shl = getelementptr i32, ptr %f, i32 %shl\n br label %inner.header\n\ninner.header: ; preds = %inner.latch, %outer.header\n store i32 0, ptr %gep.shl, align 4\n br i1 false, label %inner.latch, label %exit\n\ninner.latch: ; preds = %inner.header\n br i1 false, label %inner.header, label %outer.latch\n\nouter.latch: ; preds = %inner.latch\n %iv.next = add i32 %iv, -1\n br label %outer.header\n\nexit: ; preds = %inner.header\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "Wrong code at -Os on x86-64_gnu-linux (recent regression)",
"body": "Clang at -Os produced the wrong code.\r\n\r\nBisected to dce77a357948709e335910ddc07f9c3f2eb2ac4b, which was committed by @fhahn \r\n\r\nCompiler explorer: https://godbolt.org/z/fTrenPK4h\r\n\r\n```console\r\n% cat reduced.c\r\nint printf(const char *, ...);\r\nint a, b, c, d, e;\r\nint f[9];\r\nint g(int i) {\r\n c = 1 << i;\r\n if (b & c)\r\n return 4;\r\n return 0;\r\n}\r\nint j(int i) {\r\n int h = g(i);\r\n return h;\r\n}\r\nint k() {\r\n d = 6;\r\n for (; d; d--) {\r\n e = 0;\r\n for (; e <= 6; e++) {\r\n f[j(d - 1)] = f[d];\r\n for (; e + d;)\r\n return 0;\r\n }\r\n }\r\n return 0;\r\n}\r\nint main() {\r\n k();\r\n printf(\"%d\\n\", a);\r\n}\r\n%\r\n% clang -O3 reduced.c && ./a.out\r\n0\r\n% clang -Os reduced.c && ./a.out\r\n\r\n%\r\n```",
"author": "shao-hua-li",
"labels": [
"miscompilation",
"llvm:SCEV"
],
"comments": [
{
"author": "fhahn",
"body": "The issue is that IndVars doesn't drop poison-generating flags when hoisting the IV to introduce a new use of the widened IV. working on a fix"
},
{
"author": "fhahn",
"body": "Should be fixed, thanks again as always @shao-hua-li "
},
{
"author": "shao-hua-li",
"body": "You're welcome @fhahn "
}
]
} | true | null |
83127 | https://github.com/llvm/llvm-project/issues/83127 | hang | 7a0acccd81df268dc7ad4c0358c42552789f19b4 | 2024-02-27T12:20:45 | [
"llvm/test/Transforms/InstCombine"
] | {
"fix_commit": "9f45c5e1a65a1abf4920b617d36ed05e73c04bea",
"components": [
"InstCombine"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [
[
1285,
1291
],
[
1303,
1309
]
],
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [
"InstCombinerImpl::foldSelectValueEquivalence"
],
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 9f45c5e1a65a1abf4920b617d36ed05e73c04bea
Author: Nikita Popov <[email protected]>
Date: Wed Mar 6 09:33:51 2024 +0100
[InstCombine] Fix infinite loop in select equivalence fold (#84036)
When replacing with a non-constant, it's possible that the result of the
simplification is actually more complicated than the original, and may
result in an infinite combine loop.
Mitigate the issue by requiring that either the replacement or
simplification result is constant, which should ensure that it's
simpler. While this check is crude, it does not appear to cause
optimization regressions in real-world code in practice.
Fixes https://github.com/llvm/llvm-project/issues/83127.
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index c47bc33df070..aee18d770f72 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -1285,7 +1285,11 @@ Instruction *InstCombinerImpl::foldSelectValueEquivalence(SelectInst &Sel,
isGuaranteedNotToBeUndefOrPoison(CmpRHS, SQ.AC, &Sel, &DT)) {
if (Value *V = simplifyWithOpReplaced(TrueVal, CmpLHS, CmpRHS, SQ,
/* AllowRefinement */ true))
- return replaceOperand(Sel, Swapped ? 2 : 1, V);
+ // Require either the replacement or the simplification result to be a
+ // constant to avoid infinite loops.
+ // FIXME: Make this check more precise.
+ if (isa<Constant>(CmpRHS) || isa<Constant>(V))
+ return replaceOperand(Sel, Swapped ? 2 : 1, V);
// Even if TrueVal does not simplify, we can directly replace a use of
// CmpLHS with CmpRHS, as long as the instruction is not used anywhere
@@ -1303,7 +1307,8 @@ Instruction *InstCombinerImpl::foldSelectValueEquivalence(SelectInst &Sel,
isGuaranteedNotToBeUndefOrPoison(CmpLHS, SQ.AC, &Sel, &DT))
if (Value *V = simplifyWithOpReplaced(TrueVal, CmpRHS, CmpLHS, SQ,
/* AllowRefinement */ true))
- return replaceOperand(Sel, Swapped ? 2 : 1, V);
+ if (isa<Constant>(CmpLHS) || isa<Constant>(V))
+ return replaceOperand(Sel, Swapped ? 2 : 1, V);
auto *FalseInst = dyn_cast<Instruction>(FalseVal);
if (!FalseInst)
| [
{
"file": "llvm/test/Transforms/InstCombine/select.ll",
"commands": [
"opt < %s -passes=instcombine -S"
],
"tests": [
{
"test_name": "select_replacement_shift_noundef",
"test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine i8 @select_replacement_shift_noundef(i8 %x, i8 %y, i8 %z) {\n %shr = lshr exact i8 %x, 1\n call void @use_i8(i8 noundef %shr)\n %cmp = icmp eq i8 %shr, %y\n %shl = shl i8 %y, 1\n %sel = select i1 %cmp, i8 %shl, i8 %z\n ret i8 %sel\n}\n\ndeclare void @use_i8(i8)\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "select_replacement_loop4",
"test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine i16 @select_replacement_loop4(i16 noundef %p_12) {\n %cmp1 = icmp ult i16 %p_12, 2\n %and1 = and i16 %p_12, 1\n %and2 = select i1 %cmp1, i16 %and1, i16 0\n %cmp2 = icmp eq i16 %and2, %p_12\n %and3 = select i1 %cmp2, i16 %and1, i16 0\n ret i16 %and3\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "select_replacement_loop3",
"test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine i8 @select_replacement_loop3(i32 noundef %x) {\n %trunc = trunc i32 %x to i8\n %rev = call i8 @llvm.bitreverse.i8(i8 %trunc)\n %ext = zext i8 %rev to i32\n %cmp = icmp eq i32 %ext, %x\n %sel = select i1 %cmp, i8 %trunc, i8 0\n ret i8 %sel\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i8 @llvm.bitreverse.i8(i8) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "select_replacement_sub",
"test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine i8 @select_replacement_sub(i8 %x, i8 %y, i8 %z) {\n %cmp = icmp eq i8 %x, %y\n %sub = sub i8 %x, %y\n %sel = select i1 %cmp, i8 %sub, i8 %z\n ret i8 %sel\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "select_replacement_gep_inbounds",
"test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine ptr @select_replacement_gep_inbounds(ptr %base, i64 %offset) {\n %cmp = icmp eq i64 %offset, 0\n %gep = getelementptr inbounds i8, ptr %base, i64 %offset\n %sel = select i1 %cmp, ptr %base, ptr %gep\n ret ptr %sel\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "select_replacement_loop2",
"test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine i32 @select_replacement_loop2(i32 %arg, i32 %arg2) {\n %div = udiv i32 %arg, %arg2\n %mul = mul nsw i32 %div, %arg2\n %cmp = icmp eq i32 %mul, %arg\n %sel = select i1 %cmp, i32 %div, i32 undef\n ret i32 %sel\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[InstCombine] InstCombine gets stuck when simplifying selects",
"body": "Reduced test case: https://godbolt.org/z/ds9eq96db\r\n```\r\ndefine i16 @func(i16 noundef %p_12) {\r\nentry:\r\n %cmp1 = icmp ult i16 %p_12, 2\r\n %and1 = and i16 %p_12, 1\r\n %and2 = select i1 %cmp1, i16 %and1, i16 0\r\n %cmp2 = icmp eq i16 %and2, %p_12\r\n %and3 = select i1 %cmp2, i16 %and1, i16 0\r\n ret i16 %and3\r\n}\r\n```\r\n```\r\nADD: %and3 = select i1 %cmp2, i16 %and2, i16 0\r\nADD: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nADD: %and1 = and i16 %p_12, 1\r\nIC: Visiting: %and1 = and i16 %p_12, 1\r\nIC: Visiting: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nIC: Visiting: %and3 = select i1 %cmp2, i16 %and2, i16 0\r\nADD DEFERRED: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nADD DEFERRED: %cmp2 = icmp eq i16 %and2, %p_12\r\nIC: Mod = %and3 = select i1 %cmp2, i16 %and2, i16 0\r\n New = %and3 = select i1 %cmp2, i16 %and1, i16 0\r\nADD: %and3 = select i1 %cmp2, i16 %and1, i16 0\r\nADD: %cmp2 = icmp eq i16 %and2, %p_12\r\nADD: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nIC: Visiting: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nIC: Visiting: %cmp2 = icmp eq i16 %and2, %p_12\r\nIC: Visiting: %and3 = select i1 %cmp2, i16 %and1, i16 0\r\nADD DEFERRED: %and1 = and i16 %p_12, 1\r\nADD DEFERRED: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nIC: Mod = %and3 = select i1 %cmp2, i16 %and1, i16 0\r\n New = %and3 = select i1 %cmp2, i16 %and2, i16 0\r\n\r\n\r\nADD: %and3 = select i1 %cmp2, i16 %and2, i16 0\r\nADD: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nADD: %and1 = and i16 %p_12, 1\r\nIC: Visiting: %and1 = and i16 %p_12, 1\r\nIC: Visiting: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nIC: Visiting: %and3 = select i1 %cmp2, i16 %and2, i16 0\r\nADD DEFERRED: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nADD DEFERRED: %cmp2 = icmp eq i16 %and2, %p_12\r\nIC: Mod = %and3 = select i1 %cmp2, i16 %and2, i16 0\r\n New = %and3 = select i1 %cmp2, i16 %and1, i16 0\r\nADD: %and3 = select i1 %cmp2, i16 %and1, i16 0\r\nADD: %cmp2 = icmp eq i16 %and2, %p_12\r\nADD: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nIC: Visiting: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nIC: Visiting: %cmp2 = icmp eq i16 %and2, %p_12\r\nIC: Visiting: %and3 = select i1 %cmp2, i16 %and1, i16 0\r\nADD DEFERRED: %and1 = and i16 %p_12, 1\r\nADD DEFERRED: %and2 = select i1 %cmp1, i16 %and1, i16 0\r\nIC: Mod = %and3 = select i1 %cmp2, i16 %and1, i16 0\r\n New = %and3 = select i1 %cmp2, i16 %and2, i16 0\r\n\r\n...\r\n```",
"author": "dtcxzyw",
"labels": [
"llvm:instcombine",
"llvm:hang"
],
"comments": [
{
"author": "dtcxzyw",
"body": "Another reproducer: https://godbolt.org/z/7MEYTe9cq\r\n```\r\ndeclare void @use(i32,i32)\r\n\r\ndefine void @func(ptr %p) {\r\n %1 = load i32, ptr %p, align 4\r\n %2 = sext i32 %1 to i64\r\n %3 = icmp slt i64 %2, 2\r\n %4 = zext i1 %3 to i32\r\n %5 = and i32 %4, %1\r\n %6 = icmp eq i32 %5, %1\r\n %7 = zext i1 %6 to i32\r\n %8 = and i32 %7, %1\r\n call void @use(i32 %8, i32 noundef %1)\r\n ret void\r\n}\r\n```\r\n"
},
{
"author": "dtcxzyw",
"body": "Third reproducer: https://godbolt.org/z/8f8b4xved\r\n```\r\ndefine i8 @func(i32 noundef %p_38) {\r\nentry:\r\n %conv393 = trunc i32 %p_38 to i8\r\n %0 = call i8 @llvm.bitreverse.i8(i8 %conv393)\r\n %conv394 = zext i8 %0 to i32\r\n %cmp395 = icmp eq i32 %conv394, %p_38\r\n %conv397 = zext i1 %cmp395 to i8\r\n %mul.i = mul i8 %conv393, %conv397\r\n ret i8 %mul.i\r\n}\r\n```"
},
{
"author": "dtcxzyw",
"body": "> Third reproducer: https://godbolt.org/z/8f8b4xved\r\n> \r\n> ```\r\n> define i8 @func(i32 noundef %p_38) {\r\n> entry:\r\n> %conv393 = trunc i32 %p_38 to i8\r\n> %0 = call i8 @llvm.bitreverse.i8(i8 %conv393)\r\n> %conv394 = zext i8 %0 to i32\r\n> %cmp395 = icmp eq i32 %conv394, %p_38\r\n> %conv397 = zext i1 %cmp395 to i8\r\n> %mul.i = mul i8 %conv393, %conv397\r\n> ret i8 %mul.i\r\n> }\r\n> ```\r\n\r\nA simpler testcase:\r\n```\r\ndefine i8 @func(i32 noundef %x) {\r\nentry:\r\n %trunc = trunc i32 %x to i8\r\n %rev = call i8 @llvm.bitreverse.i8(i8 %trunc)\r\n %ext = zext i8 %rev to i32\r\n %cmp = icmp eq i32 %ext, %x\r\n %sel = select i1 %cmp, i8 %trunc, i8 0\r\n ret i8 %sel\r\n}\r\n```\r\n\r\n@nikic I have no idea how to fix it in `foldSelectValueEquivalence`/`simplifyWithOpReplaced`. `simplifyWithOpReplaced` may replace the input `x` with a more complicated value `f(x)`.\r\n"
},
{
"author": "dtcxzyw",
"body": "@nikic Ping."
}
]
} | true | null |
112922 | https://github.com/llvm/llvm-project/issues/112922 | crash | b5fa4fee46c1d0046cc395e3338ae13fe6e2cb84 | 2024-10-18T15:25:44 | [
"llvm/test/Transforms/LoopVectorize"
] | {
"fix_commit": "2a6b09e0d3d3c1a05d3d5165202a6e68900974b1",
"components": [
"LoopVectorize"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
[
5738,
5751
],
[
5760,
5767
]
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [
[
2958,
2968
],
[
2976,
2983
]
],
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
"LoopVectorizationCostModel::getInterleaveGroupCost"
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": [
"VPInterleaveRecipe::computeCost"
],
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 2a6b09e0d3d3c1a05d3d5165202a6e68900974b1
Author: Florian Hahn <[email protected]>
Date: Fri Oct 18 19:12:39 2024 -0700
[LV] Use type from InsertPos for cost computation of interleave groups.
Previously the legacy cost model would pick the type for the cost
computation depending on the order of the members in the input IR.
This is incompatible with the VPlan-based cost model (independent of
original IR order) and also doesn't match code-gen, which uses the type
of the insert position.
Update the legacy cost model to use the type (and address space) from
the Group's insert position.
This brings the legacy cost model in line with the legacy cost model and
fixes a divergence between both models.
Note that the X86 cost model seems to assign different costs to groups
with i64 and double types. Added a TODO to check.
Fixes https://github.com/llvm/llvm-project/issues/112922.
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 857efbdf687c..ce0903b838aa 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -5738,14 +5738,15 @@ LoopVectorizationCostModel::getGatherScatterCost(Instruction *I,
InstructionCost
LoopVectorizationCostModel::getInterleaveGroupCost(Instruction *I,
ElementCount VF) {
- Type *ValTy = getLoadStoreType(I);
- auto *VectorTy = cast<VectorType>(ToVectorTy(ValTy, VF));
- unsigned AS = getLoadStoreAddressSpace(I);
- enum TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
-
const auto *Group = getInterleavedAccessGroup(I);
assert(Group && "Fail to get an interleaved access group.");
+ Instruction *InsertPos = Group->getInsertPos();
+ Type *ValTy = getLoadStoreType(InsertPos);
+ auto *VectorTy = cast<VectorType>(ToVectorTy(ValTy, VF));
+ unsigned AS = getLoadStoreAddressSpace(InsertPos);
+ enum TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
+
unsigned InterleaveFactor = Group->getFactor();
auto *WideVecTy = VectorType::get(ValTy, VF * InterleaveFactor);
@@ -5760,8 +5761,9 @@ LoopVectorizationCostModel::getInterleaveGroupCost(Instruction *I,
(Group->requiresScalarEpilogue() && !isScalarEpilogueAllowed()) ||
(isa<StoreInst>(I) && (Group->getNumMembers() < Group->getFactor()));
InstructionCost Cost = TTI.getInterleavedMemoryOpCost(
- I->getOpcode(), WideVecTy, Group->getFactor(), Indices, Group->getAlign(),
- AS, CostKind, Legal->isMaskRequired(I), UseMaskForGaps);
+ InsertPos->getOpcode(), WideVecTy, Group->getFactor(), Indices,
+ Group->getAlign(), AS, CostKind, Legal->isMaskRequired(I),
+ UseMaskForGaps);
if (Group->isReverse()) {
// TODO: Add support for reversed masked interleaved access.
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index f4a1f58debba..41f13cc2d9a9 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -2958,11 +2958,20 @@ void VPInterleaveRecipe::print(raw_ostream &O, const Twine &Indent,
InstructionCost VPInterleaveRecipe::computeCost(ElementCount VF,
VPCostContext &Ctx) const {
- Instruction *I = getInsertPos();
+ Instruction *InsertPos = getInsertPos();
+ // Find the VPValue index of the interleave group. We need to skip gaps.
+ unsigned InsertPosIdx = 0;
+ for (unsigned Idx = 0; IG->getFactor(); ++Idx)
+ if (auto *Member = IG->getMember(Idx)) {
+ if (Member == InsertPos)
+ break;
+ InsertPosIdx++;
+ }
Type *ValTy = Ctx.Types.inferScalarType(
- getNumDefinedValues() > 0 ? getVPValue(0) : getStoredValues()[0]);
+ getNumDefinedValues() > 0 ? getVPValue(InsertPosIdx)
+ : getStoredValues()[InsertPosIdx]);
auto *VectorTy = cast<VectorType>(ToVectorTy(ValTy, VF));
- unsigned AS = getLoadStoreAddressSpace(I);
+ unsigned AS = getLoadStoreAddressSpace(InsertPos);
enum TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
unsigned InterleaveFactor = IG->getFactor();
@@ -2976,8 +2985,8 @@ InstructionCost VPInterleaveRecipe::computeCost(ElementCount VF,
// Calculate the cost of the whole interleaved group.
InstructionCost Cost = Ctx.TTI.getInterleavedMemoryOpCost(
- I->getOpcode(), WideVecTy, IG->getFactor(), Indices, IG->getAlign(), AS,
- CostKind, getMask(), NeedsMaskForGaps);
+ InsertPos->getOpcode(), WideVecTy, IG->getFactor(), Indices,
+ IG->getAlign(), AS, CostKind, getMask(), NeedsMaskForGaps);
if (!IG->isReverse())
return Cost;
| [
{
"file": "llvm/test/Transforms/LoopVectorize/X86/interleave-cost.ll",
"commands": [
"opt -p loop-vectorize -S %s"
],
"tests": [
{
"test_name": "geps_feeding_interleave_groups_with_reuse",
"test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.15.0\"\n\ndefine void @geps_feeding_interleave_groups_with_reuse(ptr %arg, i64 %arg1, ptr %arg2) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %shl.iv.5 = shl i64 %iv, 5\n %gep.1 = getelementptr i8, ptr %arg, i64 %shl.iv.5\n %add.5 = or disjoint i64 %shl.iv.5, 16\n %gep.2 = getelementptr i8, ptr %arg, i64 %add.5\n %shl.iv.4 = shl i64 %iv, 4\n %gep.3 = getelementptr i8, ptr %arg2, i64 %shl.iv.4\n %l.1 = load float, ptr %gep.1, align 4\n %l.2 = load float, ptr %gep.2, align 4\n %add.1 = fadd float %l.1, %l.2\n %mul.1 = fmul float %add.1, 0.000000e+00\n store float %mul.1, ptr %gep.3, align 4\n %gep.4 = getelementptr i8, ptr %gep.1, i64 4\n %l.3 = load float, ptr %gep.4, align 4\n %gep.5 = getelementptr i8, ptr %gep.2, i64 4\n %l.4 = load float, ptr %gep.5, align 4\n %add.2 = fadd float %l.3, %l.4\n %mul.2 = fmul float %add.2, 0.000000e+00\n %gep.6 = getelementptr i8, ptr %gep.3, i64 4\n store float %mul.2, ptr %gep.6, align 4\n %gep.7 = getelementptr i8, ptr %gep.1, i64 8\n %l.5 = load float, ptr %gep.7, align 4\n %gep.8 = getelementptr i8, ptr %gep.2, i64 8\n %l.6 = load float, ptr %gep.8, align 4\n %add.3 = fadd float %l.5, %l.6\n %mul.3 = fmul float %add.3, 0.000000e+00\n %gep.9 = getelementptr i8, ptr %gep.3, i64 8\n store float %mul.3, ptr %gep.9, align 4\n %i27 = getelementptr i8, ptr %gep.1, i64 12\n %l.7 = load float, ptr %i27, align 4\n %gep.10 = getelementptr i8, ptr %gep.2, i64 12\n %l.8 = load float, ptr %gep.10, align 4\n %add.4 = fadd float %l.7, %l.8\n %mul.4 = fmul float %add.4, 0.000000e+00\n %gep.11 = getelementptr i8, ptr %gep.3, i64 12\n store float %mul.4, ptr %gep.11, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, %arg1\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"target-features\"=\"+sse4.2\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "geps_feeding_interleave_groups_with_reuse2",
"test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.15.0\"\n\ndefine void @geps_feeding_interleave_groups_with_reuse2(ptr %A, ptr %B, i64 %N) #0 {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next.7, %loop ]\n %shr.1 = lshr exact i64 %iv, 1\n %gep.B = getelementptr nusw i32, ptr %B, i64 %shr.1\n %l = load i32, ptr %gep.B, align 4\n %gep.A = getelementptr i32, ptr %A, i64 %iv\n store i32 %l, ptr %gep.A, align 4\n %iv.next = or disjoint i64 %iv, 1\n %gep.A.1 = getelementptr i32, ptr %A, i64 %iv.next\n store i32 0, ptr %gep.A.1, align 4\n %iv.next.1 = or disjoint i64 %iv, 2\n %shr.2 = lshr exact i64 %iv.next.1, 1\n %gep.B.2 = getelementptr i32, ptr %B, i64 %shr.2\n %0 = load i32, ptr %gep.B.2, align 4\n %gep.A.2 = getelementptr i32, ptr %A, i64 %iv.next.1\n store i32 %0, ptr %gep.A.2, align 4\n %iv.next.2 = or disjoint i64 %iv, 3\n %gep.A.3 = getelementptr i32, ptr %A, i64 %iv.next.2\n store i32 0, ptr %gep.A.3, align 4\n %iv.next.3 = or disjoint i64 %iv, 4\n %gep.B.4 = getelementptr i32, ptr %B, i64 %iv\n %1 = load i32, ptr %gep.B.4, align 4\n %gep.A.4 = getelementptr i32, ptr %A, i64 %iv.next.3\n store i32 %1, ptr %gep.A.4, align 4\n %iv.next.4 = or disjoint i64 %iv, 5\n %gep.A.5 = getelementptr i32, ptr %A, i64 %iv.next.4\n store i32 0, ptr %gep.A.5, align 4\n %iv.next.5 = or disjoint i64 %iv, 6\n %gep.A.6 = getelementptr i32, ptr %A, i64 %iv.next.5\n store i32 0, ptr %gep.A.6, align 4\n %iv.next.6 = or disjoint i64 %iv, 7\n %gep.A.7 = getelementptr i32, ptr %A, i64 %iv.next.6\n store i32 0, ptr %gep.A.7, align 4\n %iv.next.7 = add nuw nsw i64 %iv, 8\n %ec = icmp eq i64 %iv, %N\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n\nattributes #0 = { \"min-legal-vector-width\"=\"0\" \"target-cpu\"=\"cascadelake\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "interleave_store_double_i64_2",
"test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.15.0\"\n\ndefine void @interleave_store_double_i64_2(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.1 = getelementptr { i64, double }, ptr %dst, i64 %iv, i32 1\n store double 0.000000e+00, ptr %gep.1, align 8\n %gep.0 = getelementptr { i64, double }, ptr %dst, i64 %iv\n store i64 %iv, ptr %gep.0, align 8\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 1\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "interleave_store_i64_double",
"test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.15.0\"\n\ndefine void @interleave_store_i64_double(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.0 = getelementptr { double, i64 }, ptr %dst, i64 %iv\n store double 0.000000e+00, ptr %gep.0, align 8\n %gep.1 = getelementptr { double, i64 }, ptr %dst, i64 %iv, i32 1\n store i64 %iv, ptr %gep.1, align 8\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 1\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "test_free_instructions_feeding_geps_for_interleave_groups",
"test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.15.0\"\n\ndefine void @test_free_instructions_feeding_geps_for_interleave_groups(ptr noalias %p.invar, ptr noalias %dst.1, ptr noalias %dst.2) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %l.0 = load float, ptr %p.invar, align 4\n %iv.mul = shl i64 %iv, 2\n %gep.dst.19 = getelementptr float, ptr %dst.1, i64 %iv.mul\n store float %l.0, ptr %gep.dst.19, align 4\n %l.1 = load float, ptr %p.invar, align 4\n %add.1 = or disjoint i64 %iv.mul, 1\n %gep.dst.119 = getelementptr float, ptr %dst.1, i64 %add.1\n store float %l.1, ptr %gep.dst.119, align 4\n %add.2 = or disjoint i64 %iv.mul, 2\n %gep.dst.129 = getelementptr float, ptr %dst.1, i64 %add.2\n store float 0.000000e+00, ptr %gep.dst.129, align 4\n %add.3 = or disjoint i64 %iv.mul, 3\n %gep.dst.140 = getelementptr float, ptr %dst.1, i64 %add.3\n store float 0.000000e+00, ptr %gep.dst.140, align 4\n %l.2 = load float, ptr %p.invar, align 4\n %gep.dst.247 = getelementptr float, ptr %dst.2, i64 %iv.mul\n store float %l.2, ptr %gep.dst.247, align 4\n %gep.dst.255 = getelementptr float, ptr %dst.2, i64 %add.1\n store float 0.000000e+00, ptr %gep.dst.255, align 4\n %gep.dst.265 = getelementptr float, ptr %dst.2, i64 %add.2\n store float 0.000000e+00, ptr %gep.dst.265, align 4\n %gep.dst.276 = getelementptr float, ptr %dst.2, i64 %add.3\n store float 0.000000e+00, ptr %gep.dst.276, align 4\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, 0\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "interleave_store_double_i64",
"test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.15.0\"\n\ndefine void @interleave_store_double_i64(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.1 = getelementptr { double, i64 }, ptr %dst, i64 %iv, i32 1\n store i64 %iv, ptr %gep.1, align 8\n %gep.0 = getelementptr { double, i64 }, ptr %dst, i64 %iv\n store double 0.000000e+00, ptr %gep.0, align 8\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 1\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "interleave_store_i64_double_2",
"test_body": "target datalayout = \"e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-apple-macosx10.15.0\"\n\ndefine void @interleave_store_i64_double_2(ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %gep.0 = getelementptr { i64, double }, ptr %dst, i64 %iv\n store i64 %iv, ptr %gep.0, align 8\n %gep.1 = getelementptr { i64, double }, ptr %dst, i64 %iv, i32 1\n store double 0.000000e+00, ptr %gep.1, align 8\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv, 1\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[clang] Assertion in `llvm::LoopVectorizationPlanner::computeBestVF()`",
"body": "When building the METIS (v5.1.0) library (GKLib) an assertion is thrown during LoopVectorize. This error was introduced within the past few days (see git sha of broken and working versions below).\r\n\r\n#### Error:\r\n```shell\r\nclang: /mnt/thera/cicd/actions_work/ActionsRunner/ActionsRunner/trunk_repos/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7457: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\r\nStack dump:\r\n0. Program arguments: /share/contrib-modules/Core/llvm/2024-10-16/bin/clang -I/home/bcornill/libraries/metis-5.1.0/GKlib/. -I/home/bcornill/libraries/metis-5.1.0/GKlib/test -DLINUX -D_FILE_OFFSET_BITS=64 -DNDEBUG -DNDEBUG2 -DHAVE_EXECINFO_H -DHAVE_GETLINE -O3 -MD -MT CMakeFiles/GKlib.dir/blas.c.o -MF CMakeFiles/GKlib.dir/blas.c.o.d -o CMakeFiles/GKlib.dir/blas.c.o -c /home/bcornill/libraries/metis-5.1.0/GKlib/blas.c\r\n1. <eof> parser at end of file\r\n2. Optimizer\r\n3. Running pass \"function<eager-inv>(float2int,lower-constant-intrinsics,chr,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O3>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)\" on module \"/home/bcornill/libraries/metis-5.1.0/GKlib/blas.c\"\r\n4. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"gk_dargmax_n\"\r\n #0 0x00007fa15911cc8b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMSupport.so.20.0git+0x1c2c8b)\r\n #1 0x00007fa15911a664 llvm::sys::CleanupOnSignal(unsigned long) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMSupport.so.20.0git+0x1c0664)\r\n #2 0x00007fa1590227f8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\r\n #3 0x00007fa1615e0dd0 __restore_rt sigaction.c:0:0\r\n #4 0x00007fa15821e70f raise (/lib64/libc.so.6+0x3770f)\r\n #5 0x00007fa158208b25 abort (/lib64/libc.so.6+0x21b25)\r\n #6 0x00007fa1582089f9 _nl_load_domain.cold.0 loadmsgcat.c:0:0\r\n #7 0x00007fa158216cc6 .annobin___GI___assert_fail.end assert.c:0:0\r\n #8 0x00007fa15db3af1b llvm::LoopVectorizationPlanner::computeBestVF() (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMVectorize.so.20.0git+0xb5f1b)\r\n #9 0x00007fa15db52d46 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMVectorize.so.20.0git+0xcdd46)\r\n#10 0x00007fa15db55ed1 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMVectorize.so.20.0git+0xd0ed1)\r\n#11 0x00007fa15db56517 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMVectorize.so.20.0git+0xd1517)\r\n#12 0x00007fa155d90a9e llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/../lib/libLLVMPasses.so.20.0git+0x76a9e)\r\n#13 0x00007fa15998eab7 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMCore.so.20.0git+0x323ab7)\r\n#14 0x00007fa16434e17e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMX86CodeGen.so.20.0git+0xa917e)\r\n#15 0x00007fa15998ce55 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMCore.so.20.0git+0x321e55)\r\n#16 0x00007fa16434e56e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMX86CodeGen.so.20.0git+0xa956e)\r\n#17 0x00007fa15998d9bc llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMCore.so.20.0git+0x3229bc)\r\n#18 0x00007fa15faab288 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\r\n#19 0x00007fa15faaeb9c clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libclangCodeGen.so.20.0git+0x111b9c)\r\n#20 0x00007fa15ffdd293 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libclangCodeGen.so.20.0git+0x640293)\r\n#21 0x00007fa150c5592c clang::ParseAST(clang::Sema&, bool, bool) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/../lib/libclangParse.so.20.0git+0x3c92c)\r\n#22 0x00007fa15d75dee9 clang::FrontendAction::Execute() (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libclangFrontend.so.20.0git+0x138ee9)\r\n#23 0x00007fa15d6ceb05 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libclangFrontend.so.20.0git+0xa9b05)\r\n#24 0x00007fa1613cad83 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libclangFrontendTool.so.20.0git+0x4d83)\r\n#25 0x00000000004141c7 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/share/contrib-modules/Core/llvm/2024-10-16/bin/clang+0x4141c7)\r\n#26 0x000000000040b96a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#27 0x00007fa15d135049 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\r\n#28 0x00007fa159022cb4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libLLVMSupport.so.20.0git+0xc8cb4)\r\n#29 0x00007fa15d13589e clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\r\n#30 0x00007fa15d0f22fc clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libclangDriver.so.20.0git+0x922fc)\r\n#31 0x00007fa15d0f33fd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libclangDriver.so.20.0git+0x933fd)\r\n#32 0x00007fa15d1039c4 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/../lib/libclangDriver.so.20.0git+0xa39c4)\r\n#33 0x0000000000410b5b clang_main(int, char**, llvm::ToolContext const&) (/share/contrib-modules/Core/llvm/2024-10-16/bin/clang+0x410b5b)\r\n#34 0x000000000040b074 main (/share/contrib-modules/Core/llvm/2024-10-16/bin/clang+0x40b074)\r\n#35 0x00007fa15820a6a3 __libc_start_main (/lib64/libc.so.6+0x236a3)\r\n#36 0x000000000040b0be _start (/share/contrib-modules/Core/llvm/2024-10-16/bin/clang+0x40b0be)\r\nclang: error: clang frontend command failed with exit code 134 (use -v to see invocation)\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project ae68d532f810e217c747b10b26aeea3bb84c3844)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin\r\nBuild config: +assertions\r\nConfiguration file: /share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/clang.cfg\r\nclang: note: diagnostic msg:\r\n********************\r\n\r\nPLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\r\nPreprocessed source(s) and associated run script(s) are located at:\r\nclang: note: diagnostic msg: /tmp/blas-9fe25d.c\r\nclang: note: diagnostic msg: /tmp/blas-9fe25d.sh\r\nclang: note: diagnostic msg:\r\n\r\n********************\r\n```\r\n#### Reproducer:\r\n[gklib-blas.tar.gz](https://github.com/user-attachments/files/17437550/gklib-blas.tar.gz)\r\n\r\n#### Broken Versions:\r\n```shell\r\n>> clang --version\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project ae68d532f810e217c747b10b26aeea3bb84c3844)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin\r\nBuild config: +assertions\r\nConfiguration file: /share/contrib-modules/Core/llvm/2024-10-16_20.0-0/bin/clang.cfg\r\n\r\n>> clang --version\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project af90e7c5161de9a36af768dd5c9d73464e0eed64)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /share/contrib-modules/Core/llvm/2024-10-18_20.0-0/bin\r\nBuild config: +assertions\r\nConfiguration file: /share/contrib-modules/Core/llvm/2024-10-18_20.0-0/bin/clang.cfg\r\n```\r\n\r\n#### Working version:\r\n```shell\r\n>> clang --version\r\nclang version 20.0.0git (https://github.com/llvm/llvm-project 48deb3568eb2452ff385b04b8f71c34121f47387)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /share/contrib-modules/Core/llvm/2024-10-13_20.0-0/bin\r\nBuild config: +assertions\r\nConfiguration file: /share/contrib-modules/Core/llvm/2024-10-13_20.0-0/bin/clang.cfg\r\n```",
"author": "bcornille",
"labels": [
"vectorizers",
"crash"
],
"comments": [
{
"author": "fhahn",
"body": "Thanks, taking a look!"
}
]
} | true | null |
91957 | https://github.com/llvm/llvm-project/issues/91957 | miscompilation | c2a9a974ca85e4ac4509e368d4b9acae7e67bf71 | 2024-05-13T13:05:21 | [
"llvm/test/Transforms/LICM"
] | {
"fix_commit": "70091dc943ade280d75cea1e5ea5e93d9a8f934a",
"components": [
"LICM"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": [
[
2751,
2757
],
[
2759,
2766
]
],
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": [
"hoistMulAddAssociation"
],
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 70091dc943ade280d75cea1e5ea5e93d9a8f934a
Author: Antonio Frighetto <[email protected]>
Date: Sat May 18 16:52:17 2024 +0200
[LICM] Invalidate cached SCEV results in `hoistMulAddAssociation`
While reassociating expressions, LICM is required to invalidate SCEV
results, as otherwise subsequent passes in the pipeline that leverage
LICM foldings (e.g. IndVars), may reason on invalid expressions; thus
miscompiling. This is achieved by rewriting the reassociable
instruction from scratch.
Fixes: https://github.com/llvm/llvm-project/issues/91957.
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index 6aa4188d1cc4..5eccf7b4adb6 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -2751,7 +2751,7 @@ static bool hoistMulAddAssociation(Instruction &I, Loop &L,
IRBuilder<> Builder(Preheader->getTerminator());
for (auto *U : Changes) {
assert(L.isLoopInvariant(U->get()));
- Instruction *Ins = cast<Instruction>(U->getUser());
+ auto *Ins = cast<BinaryOperator>(U->getUser());
Value *Mul;
if (I.getType()->isIntOrIntVectorTy()) {
Mul = Builder.CreateMul(U->get(), Factor, "factor.op.mul");
@@ -2759,8 +2759,20 @@ static bool hoistMulAddAssociation(Instruction &I, Loop &L,
Ins->dropPoisonGeneratingFlags();
} else
Mul = Builder.CreateFMulFMF(U->get(), Factor, Ins, "factor.op.fmul");
- U->set(Mul);
+
+ // Rewrite the reassociable instruction.
+ unsigned OpIdx = U->getOperandNo();
+ auto *LHS = OpIdx == 0 ? Mul : Ins->getOperand(0);
+ auto *RHS = OpIdx == 1 ? Mul : Ins->getOperand(1);
+ auto *NewBO = BinaryOperator::Create(Ins->getOpcode(), LHS, RHS,
+ Ins->getName() + ".reass", Ins);
+ NewBO->copyIRFlags(Ins);
+ if (VariantOp == Ins)
+ VariantOp = NewBO;
+ Ins->replaceAllUsesWith(NewBO);
+ eraseInstruction(*Ins, SafetyInfo, MSSAU);
}
+
I.replaceAllUsesWith(VariantOp);
eraseInstruction(I, SafetyInfo, MSSAU);
return true;
| [
{
"file": "llvm/test/Transforms/LICM/update-scev-after-hoist.ll",
"commands": [
"opt -S -passes='loop-unroll,loop-mssa(licm,indvars)' -unroll-count=4 < %s 2>&1"
],
"tests": [
{
"test_name": "main",
"test_body": "define i16 @main() {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %mul = phi i16 [ 1, %entry ], [ %mul.n, %loop ]\n %div = phi i16 [ 32767, %entry ], [ %div.n, %loop ]\n %mul.n = mul i16 %mul, 2\n %div.n = sdiv i16 %div, 2\n %cmp = icmp sgt i16 %div, 0\n br i1 %cmp, label %loop, label %end\n\nend: ; preds = %loop\n ret i16 %mul\n}\n",
"lli_expected_out": null,
"additional_args": "-src-unroll=16 -tgt-unroll=16"
}
]
}
] | {
"title": "Miscompile with opt -passes=\"loop-unroll,loop-mssa(licm,indvars)\" -unroll-count=4 ",
"body": "llvm commit: e76b257483e6c\r\nReproduce with:\r\n```opt -passes=\"loop-unroll,loop-mssa(licm,indvars)\" -unroll-count=4 bbi-95405.ll -S -o -```\r\n\r\nThe input function returns 32768, but after running the passes as above we get\r\n```\r\ndefine i16 @foo() {\r\nentry:\r\n br label %loop\r\n\r\nloop: ; preds = %loop, %entry\r\n br i1 false, label %loop, label %end, !llvm.loop !0\r\n\r\nend: ; preds = %loop\r\n ret i16 8192\r\n}\r\n\r\n!0 = distinct !{!0, !1}\r\n!1 = !{!\"llvm.loop.unroll.disable\"}\r\n```\r\nSo now the function returns 8192 instead.\r\n\r\nIf I extract the IR after loop-unroll or licm and run the rest of the passes instead I get the correct result.\r\n\r\n[bbi-95405.ll.gz](https://github.com/llvm/llvm-project/files/15294896/bbi-95405.ll.gz)\r\n",
"author": "mikaelholmen",
"labels": [
"miscompilation",
"llvm:transforms"
],
"comments": [
{
"author": "mikaelholmen",
"body": "This starts happening with https://github.com/llvm/llvm-project/pull/67736 , commit 2dd52046816\r\n```\r\nRecommit \"[LICM] Support integer mul/add in hoistFPAssociation. (#67736)\"\r\n\r\nWith a fix for build bot failure. I was accessing the type of a deleted\r\nInstruction.\r\n\r\nOriginal message:\r\n\r\nThe reassociation this is trying to repair can happen for integer types\r\ntoo.\r\n\r\nThis patch adds support for integer mul/add to hoistFPAssociation. The\r\nfunction has been renamed to hoistMulAddAssociation. I've used separate\r\nstatistics and limits for integer to allow tuning flexibility.\r\n```\r\n"
},
{
"author": "nikic",
"body": "Without looking into this in detail, it's possible that the way the LICM code modifies instructions in place results incorrect cached SCEV results."
},
{
"author": "mikaelholmen",
"body": "> Without looking into this in detail, it's possible that the way the LICM code modifies instructions in place results incorrect cached SCEV results.\r\n\r\nI added some printouts and see that when IndVarSimplify run rewriteLoopExitValues we do\r\n```\r\nconst SCEV *ExitValue = SE->getSCEVAtScope(Inst, L->getParentLoop());\r\n```\r\nfor Inst being\r\n```\r\n%mul.n = mul i16 %mul, 8\r\n```\r\nand then we get the SCEV\r\n```\r\n(2 * %mul)\r\n```\r\nwhich looks wrong.\r\n\r\nIf I split up the pipeline in several opt runs we instead get the SCEV\r\n```\r\n(8 * %mul)\r\n```\r\nwhich looks more reasonable (and then we also get the correct result).\r\nLICM changed\r\n```\r\n%mul.n = mul i16 %mul, 2\r\n```\r\nto\r\n```\r\n%mul.n = mul i16 %mul, 8\r\n```\r\nso yeah, it should perhaps do something (more) about SCEV."
},
{
"author": "mikaelholmen",
"body": "@antoniofrighetto : nice that you work on this!\r\n\r\nBut oh it's annoying that I don't get any emails from github about that there was activity here with a linked PR with a fix etc even if I wrote this issue. :( I do get emails when there are comments but not when the issue was assigned or the PR was created. :("
},
{
"author": "antoniofrighetto",
"body": "@mikaelholmen This is a bit inconvenient indeed, GH doesn’t seem to send notifications wrt that :( Closed this, thanks for reporting!"
},
{
"author": "mikaelholmen",
"body": "> @mikaelholmen This is a bit inconvenient indeed, GH doesn’t seem to send notifications wrt that :( Closed this, thanks for reporting!\r\n\r\nThank you!"
}
]
} | true | null |
89958 | https://github.com/llvm/llvm-project/issues/89958 | miscompilation | e913a33fcfbd667e4e3a35919b6bd9c5876a90a3 | 2024-04-24T17:36:34 | [
"llvm/test/Transforms/LoopVectorize"
] | {
"fix_commit": "b060661da8b3b53db55644e5e358bb2dca8b56d7",
"components": [
"ScalarEvolution"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": [
[
126,
131
]
],
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": [
[
681,
687
],
[
1376,
1386
],
[
1395,
1400
]
],
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": [
"SCEVExpander::expandMinMaxExpr",
"SCEVExpander::visitSMaxExpr",
"SCEVExpander::visitUDivExpr"
],
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit b060661da8b3b53db55644e5e358bb2dca8b56d7
Author: Florian Hahn <[email protected]>
Date: Thu Oct 17 13:55:20 2024 -0700
[SCEVExpander] Expand UDiv avoiding UB when in seq_min/max. (#92177)
Update SCEVExpander to introduce an SafeUDivMode, which is set
when expanding operands of SCEVSequentialMinMaxExpr. In this mode,
the expander will make sure that the divisor of the expanded UDiv is
neither 0 nor poison.
Fixes https://github.com/llvm/llvm-project/issues/89958.
PR https://github.com/llvm/llvm-project/pull/92177
diff --git a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
index 5697d983c9ad..7dd754a2bc0d 100644
--- a/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
+++ b/llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
@@ -126,6 +126,11 @@ class SCEVExpander : public SCEVVisitor<SCEVExpander, Value *> {
/// "expanded" form.
bool LSRMode;
+ /// When true, rewrite any divisors of UDiv expressions that may be 0 to
+ /// umax(Divisor, 1) to avoid introducing UB. If the divisor may be poison,
+ /// freeze it first.
+ bool SafeUDivMode = false;
+
typedef IRBuilder<InstSimplifyFolder, IRBuilderCallbackInserter> BuilderType;
BuilderType Builder;
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index c412d0398b95..39da38e49181 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -681,7 +681,21 @@ Value *SCEVExpander::visitUDivExpr(const SCEVUDivExpr *S) {
SCEV::FlagAnyWrap, /*IsSafeToHoist*/ true);
}
- Value *RHS = expand(S->getRHS());
+ const SCEV *RHSExpr = S->getRHS();
+ Value *RHS = expand(RHSExpr);
+ if (SafeUDivMode) {
+ bool GuaranteedNotPoison =
+ ScalarEvolution::isGuaranteedNotToBePoison(RHSExpr);
+ if (!GuaranteedNotPoison)
+ RHS = Builder.CreateFreeze(RHS);
+
+ // We need an umax if either RHSExpr is not known to be zero, or if it is
+ // not guaranteed to be non-poison. In the later case, the frozen poison may
+ // be 0.
+ if (!SE.isKnownNonZero(RHSExpr) || !GuaranteedNotPoison)
+ RHS = Builder.CreateIntrinsic(RHS->getType(), Intrinsic::umax,
+ {RHS, ConstantInt::get(RHS->getType(), 1)});
+ }
return InsertBinop(Instruction::UDiv, LHS, RHS, SCEV::FlagAnyWrap,
/*IsSafeToHoist*/ SE.isKnownNonZero(S->getRHS()));
}
@@ -1376,11 +1390,14 @@ Value *SCEVExpander::visitSignExtendExpr(const SCEVSignExtendExpr *S) {
Value *SCEVExpander::expandMinMaxExpr(const SCEVNAryExpr *S,
Intrinsic::ID IntrinID, Twine Name,
bool IsSequential) {
+ bool PrevSafeMode = SafeUDivMode;
+ SafeUDivMode |= IsSequential;
Value *LHS = expand(S->getOperand(S->getNumOperands() - 1));
Type *Ty = LHS->getType();
if (IsSequential)
LHS = Builder.CreateFreeze(LHS);
for (int i = S->getNumOperands() - 2; i >= 0; --i) {
+ SafeUDivMode = (IsSequential && i != 0) || PrevSafeMode;
Value *RHS = expand(S->getOperand(i));
if (IsSequential && i != 0)
RHS = Builder.CreateFreeze(RHS);
@@ -1395,6 +1412,7 @@ Value *SCEVExpander::expandMinMaxExpr(const SCEVNAryExpr *S,
}
LHS = Sel;
}
+ SafeUDivMode = PrevSafeMode;
return LHS;
}
| [
{
"file": "<issue>",
"commands": [
"opt -p loop-vectorize -force-vector-width=4 -S %s"
],
"tests": [
{
"test_name": "f",
"test_body": "define i64 @f(i64 %0) {\n br label %2\n\n2: ; preds = %5, %1\n %3 = phi i64 [ 0, %1 ], [ %6, %5 ]\n %4 = icmp slt i64 %3, %0\n br i1 %4, label %5, label %9\n\n5: ; preds = %2\n %6 = add i64 %3, 1\n %7 = udiv i64 42, %0\n %8 = icmp slt i64 %3, %7\n br i1 %8, label %2, label %9\n\n9: ; preds = %5, %2\n %10 = phi i64 [ 1, %2 ], [ 0, %5 ]\n ret i64 %10\n}",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "miscompilation due to LoopVectorize making a function vulnerable to integer divide-by-zero",
"body": "https://alive2.llvm.org/ce/z/Kx2anL\r\n\r\nthis function:\r\n```llvm\r\ndefine i64 @f(i64 %0) {\r\n br label %2\r\n\r\n2: ; preds = %5, %1\r\n %3 = phi i64 [ 0, %1 ], [ %6, %5 ]\r\n %4 = icmp slt i64 %3, %0\r\n br i1 %4, label %5, label %9\r\n\r\n5: ; preds = %2\r\n %6 = add i64 %3, 1\r\n %7 = udiv i64 42, %0\r\n %8 = icmp slt i64 %3, %7\r\n br i1 %8, label %2, label %9\r\n\r\n9: ; preds = %5, %2\r\n %10 = phi i64 [ 1, %2 ], [ 0, %5 ]\r\n ret i64 %10\r\n}\r\n```\r\nis getting optimized to:\r\n```lllvm\r\ndefine noundef i64 @f(i64 %0) local_unnamed_addr #0 {\r\n %smax = tail call i64 @llvm.smax.i64(i64 %0, i64 0)\r\n %2 = udiv i64 42, %0\r\n %umin = tail call i64 @llvm.umin.i64(i64 %smax, i64 %2)\r\n %min.iters.check = icmp ult i64 %umin, 4\r\n br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph\r\n\r\nvector.ph: ; preds = %1\r\n %3 = add nuw nsw i64 %umin, 1\r\n %n.mod.vf = and i64 %3, 3\r\n %4 = icmp eq i64 %n.mod.vf, 0\r\n %5 = select i1 %4, i64 4, i64 %n.mod.vf\r\n %n.vec = sub nsw i64 %3, %5\r\n br label %vector.body\r\n\r\nvector.body: ; preds = %vector.body, %vector.ph\r\n %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]\r\n %index.next = add nuw i64 %index, 4\r\n %6 = icmp eq i64 %index.next, %n.vec\r\n br i1 %6, label %scalar.ph.preheader, label %vector.body, !llvm.loop !0\r\n\r\nscalar.ph.preheader: ; preds = %vector.body, %1\r\n %.ph = phi i64 [ 0, %1 ], [ %n.vec, %vector.body ]\r\n br label %scalar.ph\r\n\r\nscalar.ph: ; preds = %scalar.ph.preheader, %9\r\n %7 = phi i64 [ %10, %9 ], [ %.ph, %scalar.ph.preheader ]\r\n %8 = icmp slt i64 %7, %0\r\n br i1 %8, label %9, label %13\r\n\r\n9: ; preds = %scalar.ph\r\n %10 = add nuw nsw i64 %7, 1\r\n %11 = udiv i64 42, %0\r\n %12 = icmp ult i64 %7, %11\r\n br i1 %12, label %scalar.ph, label %13, !llvm.loop !3\r\n\r\n13: ; preds = %9, %scalar.ph\r\n %14 = phi i64 [ 1, %scalar.ph ], [ 0, %9 ]\r\n ret i64 %14\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i64 @llvm.smax.i64(i64, i64) #1\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i64 @llvm.umin.i64(i64, i64) #1\r\n\r\nattributes #0 = { nofree norecurse nosync nounwind memory(none) }\r\nattributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n\r\n!0 = distinct !{!0, !1, !2}\r\n!1 = !{!\"llvm.loop.isvectorized\", i32 1}\r\n!2 = !{!\"llvm.loop.unroll.runtime.disable\"}\r\n!3 = distinct !{!3, !2, !1}\r\n```\r\n\r\nthe problem is that the optimized code can divide by zero even when the original code doesn't. to see this, pass 0 as an argument to `f`. I also independently verified on an x64-64 that the optimized code traps out with an FPE while the original code does not. it's LoopVectorize that's the culprit.\r\n\r\ncc @nunoplopes @hatsunespica\r\n",
"author": "regehr",
"labels": [
"miscompilation",
"llvm:SCEV"
],
"comments": [
{
"author": "dtcxzyw",
"body": "cc @fhahn "
}
]
} | true | null |
97674 | https://github.com/llvm/llvm-project/issues/97674 | crash | c67653fbc3dd4ea9ab2a32c481a9ac4411020c7b | 2024-07-04T04:06:51 | [
"llvm/test/Transforms/CorrelatedValuePropagation"
] | {
"fix_commit": "899fe2cf318f6e3c7a183125ff17ef53944b2989",
"components": [
"LazyValueInfo"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": [
[
1723,
1729
],
[
1758,
1764
]
],
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": [
"LazyValueInfo::getConstantOnEdge"
],
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 899fe2cf318f6e3c7a183125ff17ef53944b2989
Author: goldsteinn <[email protected]>
Date: Thu Jul 4 15:14:39 2024 +0800
[CVP][LVI] Fix incorrect scalar type when getting constant folded vec (#97682)
Fixes #97674
After #97428 added support for vectors, our constant ranges can now be
from splat vectors so when they reduce to a singe constant value, we
need to return the original type as opposed to just an int.
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp
index b30e6a6a367c..4209ee4a7795 100644
--- a/llvm/lib/Analysis/LazyValueInfo.cpp
+++ b/llvm/lib/Analysis/LazyValueInfo.cpp
@@ -1370,6 +1370,7 @@ LazyValueInfoImpl::getEdgeValueLocal(Value *Val, BasicBlock *BBFrom,
// If V is the condition of the branch itself, then we know exactly what
// it is.
+ // NB: The condition on a `br` can't be a vector type.
if (Condition == Val)
return ValueLatticeElement::get(ConstantInt::get(
Type::getInt1Ty(Val->getContext()), isTrueDest));
@@ -1723,7 +1724,7 @@ Constant *LazyValueInfo::getConstant(Value *V, Instruction *CxtI) {
if (Result.isConstantRange()) {
const ConstantRange &CR = Result.getConstantRange();
if (const APInt *SingleVal = CR.getSingleElement())
- return ConstantInt::get(V->getContext(), *SingleVal);
+ return ConstantInt::get(V->getType(), *SingleVal);
}
return nullptr;
}
@@ -1758,7 +1759,7 @@ Constant *LazyValueInfo::getConstantOnEdge(Value *V, BasicBlock *FromBB,
if (Result.isConstantRange()) {
const ConstantRange &CR = Result.getConstantRange();
if (const APInt *SingleVal = CR.getSingleElement())
- return ConstantInt::get(V->getContext(), *SingleVal);
+ return ConstantInt::get(V->getType(), *SingleVal);
}
return nullptr;
}
| [
{
"file": "llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll",
"commands": [
"opt -S -passes=correlated-propagation < %s"
],
"tests": [
{
"test_name": "and_with_poison",
"test_body": "define <2 x i16> @and_with_poison(<2 x i8> %a) {\n %zext = zext <2 x i8> %a to <2 x i16>\n %res = and <2 x i16> %zext, <i16 255, i16 poison>\n ret <2 x i16> %res\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "issue_97674_getConstant",
"test_body": "define <4 x i64> @issue_97674_getConstant() {\nentry:\n %folds = add <4 x i64> zeroinitializer, zeroinitializer\n ret <4 x i64> %folds\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "issue_97674_getConstantOnEdge",
"test_body": "define <4 x i64> @issue_97674_getConstantOnEdge(i1 %cond) {\nentry:\n br i1 %cond, label %if.then, label %if.end\n\nif.then: ; preds = %entry\n %folds = add <4 x i64> zeroinitializer, splat (i64 1)\n br label %if.end\n\nif.end: ; preds = %if.then, %entry\n %r = phi <4 x i64> [ %folds, %if.then ], [ zeroinitializer, %entry ]\n ret <4 x i64> %r\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "A/F: `getType() == V->getType() && \"All operands to PHI node must be the same type as the PHI node !\"' after 1eec81a",
"body": "We have an internal test which started to hit an assertion failure when compiled which I bisected back to 1eec81a.\r\n\r\nConsider the following code:\r\n```c++\r\ntemplate <bool, class, class> using c = int;\r\ntypedef long cb __attribute__((__vector_size__(16)));\r\ncb d(cb);\r\ntypedef long e __attribute__((__vector_size__(32)));\r\nenum { f };\r\nstruct g {\r\n enum { h };\r\n};\r\ntemplate <typename> struct i;\r\ntemplate <typename> struct aa;\r\ntemplate <typename> struct j;\r\ntemplate <typename> class k;\r\ntemplate <typename, int l, int m, int = 0, int = l, int = m> class n;\r\ntemplate <typename, typename> class o;\r\ntemplate <typename, int l, int m, int = 0, int = l, int = m> class p;\r\ntemplate <typename> struct q;\r\ntemplate <typename> struct r;\r\ntemplate <typename s> struct t { typedef q<s>::ab ab; };\r\ntemplate <typename ac> struct ad { typedef k<ac> ab; };\r\ntemplate <typename s> struct u {\r\n operator s() { return ae; }\r\n u(s v) : ae(v) {}\r\n s ae;\r\n};\r\ntemplate <typename w> w x(const typename r<w>::ab &);\r\ntemplate <> struct q<int> { typedef u<e> ab; };\r\ntemplate <> struct r<u<e>> {\r\n typedef int ab;\r\n enum { af = 8 };\r\n};\r\ntemplate <> u<e> x(const int &) {\r\n e y{};\r\n return y;\r\n}\r\ne z;\r\ne ag(e a, u<e> b) {\r\n __attribute__((__vector_size__(4 * sizeof(long)))) long ah = b;\r\n z = a + ah;\r\n return z;\r\n}\r\nstruct ai {\r\n u<__attribute__((__vector_size__(4 * sizeof(long)))) long>\r\n aj(u<__attribute__((__vector_size__(4 * sizeof(long)))) long> a,\r\n const u<__attribute__((__vector_size__(4 * sizeof(long)))) long> &b) {\r\n __attribute__((__vector_size__(4 * sizeof(long)))) long ak = a;\r\n return ag(ak, b);\r\n }\r\n};\r\nstruct al {\r\n template <typename am> am aj() { return x<am>(an); }\r\n int an;\r\n};\r\ntemplate <typename ac> long ao(ac);\r\ntemplate <typename ac> class k : j<ac> {\r\npublic:\r\n typedef i<ac>::ap ap;\r\n using j<ac>::aq;\r\n static o<int, c<g::h, ac, p<ac, i<ac>::ar, i<ac>::as>>> at(long, long);\r\n ap au() const;\r\n template <typename av> ap aw(const av &) const;\r\n};\r\ntemplate <typename ac> struct j { ac aq() const; };\r\nstruct ax {\r\n template <typename s, typename ay> s aj(al az, ay) { return az.aj<s>(); }\r\n};\r\ntemplate <typename ba, typename bb> struct aa<o<ba, bb>> {\r\n aa(o<ba, bb>);\r\n template <int, typename am, typename ay> am bc(ay) {\r\n return be.aj<am>(bf, d);\r\n }\r\n ba bf;\r\n ax be;\r\n};\r\ntemplate <typename ac> class bg : public ad<ac>::ab {};\r\ntemplate <typename bh, int l, int m, int bi, int bj, int bk>\r\nstruct i<n<bh, l, m, bi, bj, bk>> {\r\n typedef bh ap;\r\n enum { ar, as };\r\n};\r\ntemplate <typename bh, int l, int m, int bi, int bj, int bk>\r\nstruct i<p<bh, l, m, bi, bj, bk>> : i<n<bh, bj, bk>> {};\r\ntemplate <typename, int, int, int, int bj, int bk>\r\nclass p : public bg<p<int, bj, bk>> {};\r\ntemplate <typename ba, typename bb> struct i<o<ba, bb>> : i<bb> {};\r\ntemplate <typename, typename>\r\nclass o : public ad<o<al, p<int, 0, -1, 1, 0, 1>>>::ab {};\r\ntemplate <typename bl> struct bm {\r\n typedef t<typename bl::ap>::ab am;\r\n enum { bn = r<am>::af };\r\n enum { bo };\r\n};\r\ntemplate <typename, typename bl, int = bm<bl>::bo> struct M;\r\ntemplate <typename bp, typename bl> struct M<bp, bl, f> {\r\n typedef bm<bl>::am bq;\r\n template <typename br> static bl bs(bl bt, bp bu, br bv) {\r\n enum { alignment };\r\n long bw = ao(bv);\r\n bq bx = bt.template bc<alignment, bq>(bw);\r\n if (bw > bm<bl>::bn) {\r\n bq by = bt.template bc<alignment, bq>(bm<bl>::bn);\r\n for (long bd; bd; bd += bm<bl>::bn) {\r\n bx = bu.aj(bx, bt.template bc<alignment, bq>(d));\r\n u bz = bt.template bc<alignment, bq>(bm<bl>::bn);\r\n by = bu.aj(by, bz);\r\n }\r\n bx = bu.aj(bx, by);\r\n }\r\n __attribute__((__vector_size__(4 * sizeof(int)))) int ca =\r\n __builtin_ia32_vextractf128_si256(bx, 0);\r\n __attribute__((__vector_size__(2 * sizeof(long)))) long b = d(ca);\r\n }\r\n};\r\nclass cc : public aa<o<al, p<int, 0, -1, 1, 0, 1>>> {\r\npublic:\r\n typedef int ap;\r\n};\r\ntemplate <typename ac>\r\ntemplate <typename bp>\r\ni<ac>::ap k<ac>::aw(const bp &bu) const {\r\n cc cd(aq());\r\n o<int, int> ce;\r\n M<bp, cc>::bs(cd, bu, ce);\r\n}\r\ntemplate <typename ac> i<ac>::ap k<ac>::au() const { aw(ai()); }\r\nvoid cf() { p<int, 1, 1>::at(0, 0).au(); }\r\n```\r\n\r\nWhen compiled with optimizations and AVX support with a compiler before 1eec81a, the compilation succeeds:\r\n```\r\n$ ~/src/upstream/b76dd4edbfbba5593b691ef92b755f25cf63f445-linux/bin/clang -c -O2 -mavx -Wno-return-type -std=c++20 repro.cpp\r\n$\r\n```\r\n\r\nWhen compiled with the same arguments but with a compiler built from 1eec81a, the compiler hits an assertion failure:\r\n```\r\n$ ~/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang -c -O2 -mavx -Wno-return-type -std=c++20 repro.cpp\r\nclang: /home/dyung/src/upstream/llvm_clean_git/llvm/include/llvm/IR/Instructions.h:2582: void llvm::PHINode::setIncomingValue(unsigned int, llvm::Value*): Assertion `getType() == V->getType() && \"All operands to PHI node must be the same type as the PHI node\r\n!\"' failed. \r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script. \r\nStack dump:\r\n0. Program arguments: /home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang -c -O2 -mavx -Wno-return-type -std=c++20 repro.cpp\r\n1. <eof> parser at end of file\r\n2. Optimizer\r\n3. Running pass \"require<globals-aa>,function(invalidate<aa>),require<profile-summary>,cgscc(devirt<4>(inline,function-attrs<skip-non-recursive-function-attrs>,openmp-opt-cgscc,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,speculative-\r\nexecution<only-if-divergent-target>,jump-threading,correlated-propagation,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-\r\nbranch>,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,aggressive-instcombine,libcalls-shrinkwrap,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-in\r\nsts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,reassociate,constraint-elimination,loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-un\r\nswitch<no-nontrivial;trivial>),simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,instcombine<max-iterations=1;no-use\r\n-loop-info;no-verify-fixpoint>,loop(loop-idiom,indvars,simple-loop-unswitch<no-nontrivial;trivial>,loop-deletion,loop-unroll-full),sroa<modify-cfg>,vector-combine,mldst-motion<no-split-footer-bb>,gvn<>,sccp,bdce,instcombine<max-iterations=1;no-use-loop-info;\r\nno-verify-fixpoint>,jump-threading,correlated-propagation,adce,memcpyopt,dse,move-auto-init,loop-mssa(licm<allowspeculation>),coro-elide,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-commo\r\nn-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>),function-attrs,function(require<should-not-run-function-passes>),coro-split)),function(invalidate<should-not-run-function-pass\r\nes>),cgscc(devirt<4>())\" on module \"repro.cpp\"\r\n4. Running pass \"cgscc(devirt<4>(inline,function-attrs<skip-non-recursive-function-attrs>,openmp-opt-cgscc,function<eager-inv;no-rerun>(sroa<modify-cfg>,early-cse<memssa>,speculative-execution<only-if-divergent-target>,jump-threading,correlated-propagat\r\nion,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoi\r\nnt>,aggressive-instcombine,libcalls-shrinkwrap,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,reasso\r\nciate,constraint-elimination,loop-mssa(loop-instsimplify,loop-simplifycfg,licm<no-allowspeculation>,loop-rotate<header-duplication;no-prepare-for-lto>,licm<allowspeculation>,simple-loop-unswitch<no-nontrivial;trivial>),simplifycfg<bonus-inst-threshold=1;no-f\r\norward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,loop(loop-idiom,indvars,simple-loop-uns\r\nwitch<no-nontrivial;trivial>,loop-deletion,loop-unroll-full),sroa<modify-cfg>,vector-combine,mldst-motion<no-split-footer-bb>,gvn<>,sccp,bdce,instcombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>,jump-threading,correlated-propagation,adce,memcpyo\r\npt,dse,move-auto-init,loop-mssa(licm<allowspeculation>),coro-elide,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>,instc\r\nombine<max-iterations=1;no-use-loop-info;no-verify-fixpoint>),function-attrs,function(require<should-not-run-function-passes>),coro-split))\" on module \"repro.cpp\"\r\n5. Running pass \"correlated-propagation\" on function \"_ZN1MI2ai2ccLi0EE2bsI1oIiiEEES1_S1_S0_T_\"\r\n #0 0x000056411be676af llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x41856af)\r\n #1 0x000056411be6520c llvm::sys::CleanupOnSignal(unsigned long) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x418320c)\r\n #2 0x000056411bdaa728 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\r\n #3 0x00007f29a8886420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\r\n #4 0x00007f29a835300b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #5 0x00007f29a8332859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7\r\n #6 0x00007f29a8332729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #7 0x00007f29a8332729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #8 0x00007f29a8343fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #9 0x00005641200199a5 processPHI(llvm::PHINode*, llvm::LazyValueInfo*, llvm::DominatorTree*, llvm::SimplifyQuery const&) CorrelatedValuePropagation.cpp:0:0\r\n#10 0x000056412002131e runImpl(llvm::Function&, llvm::LazyValueInfo*, llvm::DominatorTree*, llvm::SimplifyQuery const&) CorrelatedValuePropagation.cpp:0:0\r\n#11 0x0000564120022b4b llvm::CorrelatedValuePropagationPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x8340b4b)\r\n#12 0x000056411d2b9866 llvm::detail::PassModel<llvm::Function, llvm::CorrelatedValuePropagationPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x55d7866)\r\n#13 0x000056411b80daf1 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x3b2baf1)\r\n#14 0x00005641193e3d86 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x1701d86)\r\n#15 0x000056411acf6e91 llvm::CGSCCToFunctionPassAdaptor::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x3014e91)\r\n#16 0x00005641193e5326 llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::CGSCCToFunctionPassAdaptor, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x1703326)\r\n#17 0x000056411aceef7f llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x300cf7f)\r\n#18 0x000056411d2b71b6 llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x55d51b6)\r\n#19 0x000056411acf370d llvm::DevirtSCCRepeatedPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x301170d)\r\n#20 0x000056411d2b7206 llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::DevirtSCCRepeatedPass, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x55d5206)\r\n#21 0x000056411acf150c llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x300f50c)\r\n#22 0x000056411d2b7166 llvm::detail::PassModel<llvm::Module, llvm::ModuleToPostOrderCGSCCPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x55d5166)\r\n#23 0x000056411b80a601 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x3b28601)\r\n#24 0x000056411d4afdb5 llvm::ModuleInlinerWrapperPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x57cddb5)\r\n#25 0x000056411d2b68f6 llvm::detail::PassModel<llvm::Module, llvm::ModuleInlinerWrapperPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x55d48f6)\r\n#26 0x000056411b80a601 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x3b28601)\r\n#27 0x000056411c11c4d8 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\r\n#28 0x000056411c11f855 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) BackendUtil.cpp:0:0\r\n#29 0x000056411c11fef6 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x443def6)\r\n#30 0x000056411c792bea clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x4ab0bea)\r\n#31 0x000056411e56cb8c clang::ParseAST(clang::Sema&, bool, bool) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x688ab8c)\r\n#32 0x000056411c793078 clang::CodeGenAction::ExecuteAction() (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x4ab1078)\r\n#33 0x000056411ca26e79 clang::FrontendAction::Execute() (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x4d44e79)\r\n#34 0x000056411c9aa76e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x4cc876e)\r\n#35 0x000056411cb12366 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x4e30366)\r\n#36 0x0000564118fcc89f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x12ea89f)\r\n#37 0x0000564118fc594a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#38 0x000056411c7d833d void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\r\n#39 0x000056411bdaac30 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x40c8c30)\r\n#40 0x000056411c7d895f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\r\n#41 0x000056411c79cdbc clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x4abadbc)\r\n#42 0x000056411c79d84d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x4abb84d)\r\n#43 0x000056411c7a5925 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x4ac3925)\r\n#44 0x0000564118fc9bab clang_main(int, char**, llvm::ToolContext const&) (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x12e7bab)\r\n#45 0x0000564118ebcc0b main (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x11dac0b)\r\n#46 0x00007f29a8334083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#47 0x0000564118fc53de _start (/home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin/clang+0x12e33de)\r\nclang: error: clang frontend command failed with exit code 134 (use -v to see invocation)\r\nclang version 19.0.0 (https://github.com/llvm/llvm-project.git 1eec81a831dcf925c0c86c153e8dce019a5b5436)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /home/dyung/src/upstream/1eec81a831dcf925c0c86c153e8dce019a5b5436-linux/bin\r\n```",
"author": "dyung",
"labels": [
"crash",
"llvm:analysis"
],
"comments": [
{
"author": "goldsteinn",
"body": "Seems like when `CVP` finds a constant, its returning the scalar, not the VEC type.\r\n\r\nReducer of exact error:\r\n```\r\ndefine <4 x i64> @reduce(i1 %cond) {\r\nentry:\r\n br i1 %cond, label %if.then, label %if.end\r\n\r\nif.then:\r\n %folds = add <4 x i64> zeroinitializer, <i64 1, i64 1, i64 1, i64 1>\r\n br label %if.end\r\n\r\nif.end:\r\n %r = phi <4 x i64> [ %folds, %if.then ], [ zeroinitializer, %entry ]\r\n ret <4 x i64> %r\r\n}\r\n```\r\nRepro with: `opt -passes=correlated-propagation`\r\n\r\nOr an even simpler version (different assert location):\r\n```\r\ndefine <4 x i64> @reduce() {\r\nentry:\r\n %folds = add <4 x i64> zeroinitializer, zeroinitializer\r\n ret <4 x i64> %folds\r\n}\r\n \r\n```\r\n\r\nSame command as above.\r\n"
},
{
"author": "goldsteinn",
"body": "Ill have a fix up shortly."
},
{
"author": "goldsteinn",
"body": "Fix at: https://github.com/llvm/llvm-project/pull/97682"
}
]
} | true | null |
115465 | https://github.com/llvm/llvm-project/issues/115465 | miscompilation | d822c099eeacc69f6bf834a6373a41d0c9f84a3e | 2024-11-08T11:25:34 | [
"llvm/test/Transforms/InstCombine"
] | {
"fix_commit": "27bf45aa36386136db179c494358670a994a98a5",
"components": [
"InstCombine"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": [
[
2904,
2910
]
],
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": [
"InstCombinerImpl::visitShuffleVectorInst"
],
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 27bf45aa36386136db179c494358670a994a98a5
Author: Yingwei Zheng <[email protected]>
Date: Sun Nov 10 17:07:25 2024 +0800
[InstCombine] Fix poison safety of folding shufflevector into select (#115483)
We are allowed to fold shufflevector into select iff the condition is
guaranteed not to be poison or the RHS is a poison.
Alive2: https://alive2.llvm.org/ce/z/28zEWR
Closes https://github.com/llvm/llvm-project/issues/115465.
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index 454fe5a91d37..ede89b099e8d 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2904,7 +2904,9 @@ Instruction *InstCombinerImpl::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
if (auto *SI = dyn_cast<SelectInst>(LHS)) {
// We cannot do this fold for elementwise select since ShuffleVector is
// not elementwise.
- if (SI->getCondition()->getType()->isIntegerTy()) {
+ if (SI->getCondition()->getType()->isIntegerTy() &&
+ (isa<PoisonValue>(RHS) ||
+ isGuaranteedNotToBePoison(SI->getCondition()))) {
if (Instruction *I = FoldOpIntoSelect(SVI, SI))
return I;
}
| [
{
"file": "llvm/test/Transforms/InstCombine/vec_shuffle.ll",
"commands": [
"opt < %s -passes=instcombine -S"
],
"tests": [
{
"test_name": "shuf_cmp_may_be_poison",
"test_body": "define <4 x i8> @shuf_cmp_may_be_poison(<4 x i8> %x, <4 x i8> %y, i1 %cmp) {\n %sel = select i1 %cmp, <4 x i8> %y, <4 x i8> <i8 0, i8 poison, i8 0, i8 poison>\n %shuf = shufflevector <4 x i8> %sel, <4 x i8> <i8 poison, i8 1, i8 poison, i8 3>, <4 x i32> <i32 0, i32 5, i32 2, i32 7>\n ret <4 x i8> %shuf\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "shuf_same_length_vec_select",
"test_body": "define <4 x i32> @shuf_same_length_vec_select(<4 x i1> %cond) {\n %sel = select <4 x i1> %cond, <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32> <i32 4, i32 5, i32 6, i32 7>\n %shuf = shufflevector <4 x i32> %sel, <4 x i32> <i32 8, i32 9, i32 10, i32 11>, <4 x i32> <i32 2, i32 1, i32 3, i32 5>\n ret <4 x i32> %shuf\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[InstCombine] folded select produces different result on a blended vector",
"body": "Alive2 report: https://alive2.llvm.org/ce/z/73v-ug\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine <4 x i8> @sel_shuf_commute3.2(<4 x i8> %x, <4 x i8> %y, i1 %cmp) {\r\n#0:\r\n %blend = shufflevector <4 x i8> { 0, 0, 0, 0 }, <4 x i8> %y, 0, 5, 2, 3\r\n %r = select i1 %cmp, <4 x i8> %y, <4 x i8> %blend\r\n %#1 = select <4 x i1> { 0, 1, 0, 1 }, <4 x i8> { 0, 1, 2, 3 }, <4 x i8> %r\r\n ret <4 x i8> %#1\r\n}\r\n=>\r\ndefine <4 x i8> @sel_shuf_commute3.2(<4 x i8> %x, <4 x i8> %y, i1 %cmp) {\r\n#0:\r\n %#1 = shufflevector <4 x i8> %y, <4 x i8> { poison, 1, poison, 3 }, 0, 5, 2, 7\r\n %#2 = select i1 %cmp, <4 x i8> %#1, <4 x i8> { 0, 1, 0, 3 }\r\n ret <4 x i8> %#2\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\n<4 x i8> %x = < poison, poison, poison, poison >\r\n<4 x i8> %y = < poison, poison, poison, poison >\r\ni1 %cmp = poison\r\n\r\nSource:\r\n<4 x i8> %blend = < #x00 (0), poison, #x00 (0), #x00 (0) >\r\n<4 x i8> %r = < poison, poison, poison, poison >\r\n<4 x i8> %#1 = < poison, #x01 (1), poison, #x03 (3) >\r\n\r\nTarget:\r\n<4 x i8> %#1 = < poison, #x01 (1), poison, #x03 (3) >\r\n<4 x i8> %#2 = < poison, poison, poison, poison >\r\nSource value: < poison, #x01 (1), poison, #x03 (3) >\r\nTarget value: < poison, poison, poison, poison >\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```\r\n",
"author": "bongjunj",
"labels": [
"miscompilation",
"llvm:instcombine"
],
"comments": []
} | true | null |
113986 | https://github.com/llvm/llvm-project/issues/113986 | crash | 0c1c37bfbed08c9d4e414a10f46cbed9a3e4c870 | 2024-10-29T00:38:49 | [
"llvm/test/Transforms/InstCombine"
] | {
"fix_commit": "18311093abe6481388a0d963d58438d743b47569",
"components": [
"InstCombine"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": [
[
2902,
2909
]
],
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": [
"InstCombinerImpl::visitShuffleVectorInst"
],
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 18311093abe6481388a0d963d58438d743b47569
Author: Yingwei Zheng <[email protected]>
Date: Tue Oct 29 10:39:07 2024 +0800
[InstCombine] Do not fold `shufflevector(select)` if the select condition is a vector (#113993)
Since `shufflevector` is not element-wise, we cannot do fold it into
select when the select condition is a vector.
For shufflevector that doesn't change the length, it doesn't crash, but
it is still a miscompilation: https://alive2.llvm.org/ce/z/s8saCx
Fixes https://github.com/llvm/llvm-project/issues/113986.
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index 75e7c1c97018..454fe5a91d37 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2902,8 +2902,12 @@ Instruction *InstCombinerImpl::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
if (match(RHS, m_Constant())) {
if (auto *SI = dyn_cast<SelectInst>(LHS)) {
- if (Instruction *I = FoldOpIntoSelect(SVI, SI))
- return I;
+ // We cannot do this fold for elementwise select since ShuffleVector is
+ // not elementwise.
+ if (SI->getCondition()->getType()->isIntegerTy()) {
+ if (Instruction *I = FoldOpIntoSelect(SVI, SI))
+ return I;
+ }
}
if (auto *PN = dyn_cast<PHINode>(LHS)) {
if (Instruction *I = foldOpIntoPhi(SVI, PN))
| [
{
"file": "llvm/test/Transforms/InstCombine/vec_shuffle.ll",
"commands": [
"opt < %s -passes=instcombine -S"
],
"tests": [
{
"test_name": "foldselect0",
"test_body": "define <2 x i32> @foldselect0(i1 %c) {\n %sel = select i1 %c, <2 x i32> <i32 42, i32 7>, <2 x i32> <i32 0, i32 1>\n %shuf = shufflevector <2 x i32> %sel, <2 x i32> poison, <2 x i32> <i32 1, i32 0>\n ret <2 x i32> %shuf\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "shuf_larger_length_vec_select",
"test_body": "define <4 x float> @shuf_larger_length_vec_select(<2 x i1> %cond) {\n %sel = select <2 x i1> %cond, <2 x float> zeroinitializer, <2 x float> splat (float 1.000000e+00)\n %shuf = shufflevector <2 x float> %sel, <2 x float> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3>\n ret <4 x float> %shuf\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "shuf_same_length_vec_select",
"test_body": "define <4 x i32> @shuf_same_length_vec_select(<4 x i1> %cond) {\n %sel = select <4 x i1> %cond, <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32> <i32 4, i32 5, i32 6, i32 7>\n %shuf = shufflevector <4 x i32> %sel, <4 x i32> <i32 8, i32 9, i32 10, i32 11>, <4 x i32> <i32 2, i32 1, i32 3, i32 5>\n ret <4 x i32> %shuf\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[InstCombine] Assertion `!areInvalidOperands(C, S1, S2) && \"Invalid operands for select\"' failed.",
"body": "Reproducer: \r\n```\r\n; bin/opt -passes=instcombine reduced.ll -S\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-pc-linux-gnu\"\r\n\r\ndefine <32 x float> @process(<8 x i1> %0) {\r\n %3 = select <8 x i1> %0, <8 x float> zeroinitializer, <8 x float> <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>\r\n %4 = shufflevector <8 x float> %3, <8 x float> zeroinitializer, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>\r\n %5 = shufflevector <16 x float> %4, <16 x float> zeroinitializer, <32 x i32> <i32 0, i32 8, i32 16, i32 24, i32 1, i32 9, i32 17, i32 25, i32 2, i32 10, i32 18, i32 26, i32 3, i32 11, i32 19, i32 27, i32 4, i32 12, i32 20, i32 28, i32 5, i32 13, i32 21, i32 29, i32 6, i32 14, i32 22, i32 30, i32 7, i32 15, i32 23, i32 31>\r\n ret <32 x float> %5\r\n}\r\n```\r\n```\r\nopt: /home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/llvm/include/llvm/IR/Instructions.h:1614: void llvm::SelectInst::init(llvm::Value*, llvm::Value*, llvm::Value*): Assertion `!areInvalidOperands(C, S1, S2) && \"Invalid operands for select\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: bin/opt -passes=instcombine reduced.ll\r\n1. Running pass \"function(instcombine<max-iterations=1;verify-fixpoint>)\" on module \"reduced.ll\"\r\n2. Running pass \"instcombine<max-iterations=1;verify-fixpoint>\" on function \"process\"\r\n #0 0x00007ffff7e15b02 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x215b02)\r\n #1 0x00007ffff7e129af llvm::sys::RunSignalHandlers() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x2129af)\r\n #2 0x00007ffff7e12af5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007ffff7842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007ffff78969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007ffff78969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007ffff78969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007ffff7842476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007ffff78287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007ffff782871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007ffff7839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00007ffff1272963 llvm::InstCombinerImpl::FoldOpIntoSelect(llvm::Instruction&, llvm::SelectInst*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMInstCombine.so.20.0git+0x60963)\r\n#12 0x00007ffff13a09d1 llvm::InstCombinerImpl::visitShuffleVectorInst(llvm::ShuffleVectorInst&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMInstCombine.so.20.0git+0x18e9d1)\r\n#13 0x00007ffff1275da8 llvm::InstCombinerImpl::run() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMInstCombine.so.20.0git+0x63da8)\r\n#14 0x00007ffff1276f09 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::BranchProbabilityInfo*, llvm::ProfileSummaryInfo*, llvm::InstCombineOptions const&) InstructionCombining.cpp:0:0\r\n#15 0x00007ffff1277dfb llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMInstCombine.so.20.0git+0x65dfb)\r\n#16 0x00007ffff30d9955 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMPasses.so.20.0git+0xd9955)\r\n#17 0x00007ffff01678bd llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x3678bd)\r\n#18 0x00007ffff68d9e65 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.20.0git+0xd9e65)\r\n#19 0x00007ffff01659f6 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x3659f6)\r\n#20 0x00007ffff68da825 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.20.0git+0xda825)\r\n#21 0x00007ffff016657a llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x36657a)\r\n#22 0x00007ffff7f95051 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x2d051)\r\n#23 0x00007ffff7fa073f optMain (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x3873f)\r\n#24 0x00007ffff7829d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#25 0x00007ffff7829e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#26 0x00007ffff7829e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#27 0x0000555555555095 _start (bin/opt+0x1095)\r\nAborted (core dumped)\r\n```\r\n\r\nIt is caused by https://github.com/llvm/llvm-project/pull/113746. We cannot do this fold if the output and input operands don't have the exact same type. It was reported by llvm-opt-benchmark pre-commit test https://github.com/dtcxzyw/llvm-opt-benchmark/pull/1543. I am sorry I didn't notice about this. Fortunately this issue was captured by a post-commit test https://github.com/dtcxzyw/llvm-opt-benchmark/issues/1560.\r\n\r\ncc @MatzeB @RKSimon @goldsteinn \r\n\r\nI will post a fix later.\r\n\r\n\r\n",
"author": "dtcxzyw",
"labels": [
"llvm:instcombine",
"crash-on-valid"
],
"comments": []
} | true | null |
119893 | https://github.com/llvm/llvm-project/issues/119893 | crash | cd093c2e1bac35dd2c6b914d0b64ce56683cb50a | 2024-12-13T16:00:39 | [
"llvm/test/Transforms/EarlyCSE"
] | {
"fix_commit": "5528388e3664c6d7d292f20a739f1bf1c8ef768d",
"components": [
"EarlyCSE",
"IR"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": [
[
71,
83
]
],
"llvm/lib/IR/Instructions.cpp": [
[
3946,
3955
]
],
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": [
[
290,
296
]
],
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": [
"CmpPredicate::getSwapped",
"llvm::hash_value"
],
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": [
"getHashValueImpl"
],
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 5528388e3664c6d7d292f20a739f1bf1c8ef768d
Author: Ramkumar Ramachandra <[email protected]>
Date: Fri Dec 13 22:06:39 2024 +0000
EarlyCSE: fix CmpPredicate duplicate-hashing (#119902)
Strip hash_value() for CmpPredicate, as different callers have different
hashing use-cases. In this case, there is just one caller, namely
EarlyCSE, which calls hash_combine() on a CmpPredicate, which used to
call hash_combine() on a CmpInst::Predicate prior to 4a0d53a
(PatternMatch: migrate to CmpPredicate). This has uncovered a bug where
two icmp instructions differing in just the fact that one of them has
the samesign flag on it are hashed differently, leading to divergent
hashing, and a crash. Fix this crash by dropping samesign information on
icmp instructions before hashing them, preserving the former behavior.
Fixes #119893.
diff --git a/llvm/include/llvm/IR/CmpPredicate.h b/llvm/include/llvm/IR/CmpPredicate.h
index ce78e4311f9f..9aa1449465f5 100644
--- a/llvm/include/llvm/IR/CmpPredicate.h
+++ b/llvm/include/llvm/IR/CmpPredicate.h
@@ -71,13 +71,7 @@ public:
/// Get the swapped predicate of a CmpInst.
static CmpPredicate getSwapped(const CmpInst *Cmp);
-
- /// Provided to facilitate storing a CmpPredicate in data structures that
- /// require hashing.
- friend hash_code hash_value(const CmpPredicate &Arg); // NOLINT
};
-
-[[nodiscard]] hash_code hash_value(const CmpPredicate &Arg);
} // namespace llvm
#endif
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index d1da02c744f1..2d6fe40f4c1d 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -3946,10 +3946,6 @@ CmpPredicate CmpPredicate::getSwapped(const CmpInst *Cmp) {
return getSwapped(get(Cmp));
}
-hash_code llvm::hash_value(const CmpPredicate &Arg) { // NOLINT
- return hash_combine(Arg.Pred, Arg.HasSameSign);
-}
-
//===----------------------------------------------------------------------===//
// SwitchInst Implementation
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
index 682c5c3d8c63..3a0ae6b01a11 100644
--- a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
+++ b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
@@ -290,7 +290,8 @@ static unsigned getHashValueImpl(SimpleValue Val) {
Pred = CmpInst::getInversePredicate(Pred);
std::swap(A, B);
}
- return hash_combine(Inst->getOpcode(), Pred, X, Y, A, B);
+ return hash_combine(Inst->getOpcode(),
+ static_cast<CmpInst::Predicate>(Pred), X, Y, A, B);
}
if (CastInst *CI = dyn_cast<CastInst>(Inst))
| [
{
"file": "llvm/test/Transforms/EarlyCSE/pr119893.ll",
"commands": [
"opt -passes=early-cse -S %s"
],
"tests": [
{
"test_name": "samesign_hash_bug",
"test_body": "define i32 @samesign_hash_bug(i16 %v) {\n %zext = zext i16 %v to i32\n %icmp.samesign = icmp samesign ugt i32 %zext, 31\n %select.icmp.samesign = select i1 %icmp.samesign, i32 0, i32 1\n %ashr = ashr i32 0, %select.icmp.samesign\n %icmp = icmp ugt i32 %zext, 31\n %select.icmp = select i1 %icmp, i32 1, i32 0\n %ret = add i32 %ashr, %select.icmp\n ret i32 %ret\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[EarlyCSE] Assertion `!FoundVal && \"Key already in new map?\"' failed.",
"body": "Reproducer:\n```\n; bin/opt -passes=early-cse reduced.ll -S\n\ndefine i32 @func_207(i16 %p_208.coerce, i32 %conv, i32 %0, i64 %1, ptr %p) {\nentry:\n %conv1 = zext i16 %p_208.coerce to i32\n %conv31 = sext i32 %conv to i64\n %cmp.i = icmp eq i64 %conv31, 0\n %xor = xor i32 %conv, 1\n store i32 %xor, ptr %p, align 4\n %cmp2.i = icmp samesign ugt i32 %conv1, 31\n %shr.i601 = select i1 %cmp2.i, i32 0, i32 %conv1\n %cond.i602 = ashr i32 1, %shr.i601\n %conv6.i603 = trunc i32 %cond.i602 to i16\n %conv245 = trunc i16 %p_208.coerce to i8\n %mul.i628 = mul i8 -107, %conv245\n %conv247 = sext i8 %mul.i628 to i64\n %cond.i629 = call i64 @llvm.smin.i64(i64 0, i64 %conv247)\n %cmp249 = icmp slt i64 %cond.i629, 0\n %conv251 = zext i1 %cmp249 to i64\n %cmp1.i630 = icmp ugt i32 %conv1, 31\n %narrow.i631 = select i1 %cmp1.i630, i32 0, i32 %conv1\n %shr.i632 = zext i32 %narrow.i631 to i64\n %cond.i633 = lshr i64 %conv251, %shr.i632\n %cmp258 = icmp slt i16 %p_208.coerce, 0\n %2 = zext i1 %cmp258 to i16\n %cmp261 = icmp ugt i16 1, %2\n %conv263 = zext i1 %cmp261 to i64\n %cmp344 = icmp eq i16 %p_208.coerce, 0\n %conv345 = zext i1 %cmp344 to i32\n store i32 %conv345, ptr %p, align 4\n %conv351 = sext i32 %0 to i64\n %sub.i641 = call i64 @llvm.ucmp.i64.i64(i64 0, i64 %conv351)\n %conv353 = trunc i64 %sub.i641 to i16\n %3 = mul i16 %conv353, -1\n %conv355 = zext i16 %3 to i64\n %cmp356 = icmp sle i64 1, %conv355\n %conv357 = zext i1 %cmp356 to i32\n %conv359 = trunc i32 %conv357 to i8\n %conv.i650 = sext i8 %conv359 to i32\n %4 = icmp ugt i32 %conv, 0\n %shr.i652 = lshr i32 1, %conv\n %cmp9.i = icmp slt i32 %shr.i652, 1\n %or.cond.i = select i1 %4, i1 false, i1 %cmp9.i\n %shl.i653 = shl i32 %conv.i650, 1\n %5 = trunc i32 %shl.i653 to i8\n %cond.i654 = select i1 %or.cond.i, i8 0, i8 %5\n %conv3612 = sext i8 %cond.i654 to i32\n %conv3623 = trunc i64 %1 to i32\n %6 = or i32 1, %conv3612\n %or.cond.i655 = icmp slt i32 %6, 0\n %cmp3.i = icmp sgt i32 %conv3623, 0\n %or.cond4.i = or i1 %cmp3.i, %or.cond.i655\n %shr.i656 = select i1 %or.cond4.i, i32 0, i32 1\n %cond.i657 = ashr i32 %conv, %shr.i656\n %cmp.i658 = icmp slt i32 %cond.i657, 0\n %shr.i660 = select i1 %cmp.i658, i32 0, i32 1\n %cond.i661 = ashr i32 1, %shr.i660\n %conv365 = trunc i32 %cond.i661 to i16\n %add.i662 = or i16 1, %conv365\n %conv368 = sext i16 %add.i662 to i32\n ret i32 %conv368\n}\n```\n```\nopt: /data/zyw/llvm-project/llvm/include/llvm/ADT/DenseMap.h:419: void llvm::DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT>::moveFromOldBuckets(BucketT*, BucketT*) [with DerivedT = llvm::DenseMap<{anonymous}::SimpleValue, llvm::ScopedHashTableVal<{anonymous}::SimpleValue, llvm::Value*>*, llvm::DenseMapInfo<{anonymous}::SimpleValue>, llvm::detail::DenseMapPair<{anonymous}::SimpleValue, llvm::ScopedHashTableVal<{anonymous}::SimpleValue, llvm::Value*>*> >; KeyT = {anonymous}::SimpleValue; ValueT = llvm::ScopedHashTableVal<{anonymous}::SimpleValue, llvm::Value*>*; KeyInfoT = llvm::DenseMapInfo<{anonymous}::SimpleValue>; BucketT = llvm::detail::DenseMapPair<{anonymous}::SimpleValue, llvm::ScopedHashTableVal<{anonymous}::SimpleValue, llvm::Value*>*>]: Assertion `!FoundVal && \"Key already in new map?\"' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0. Program arguments: /data/zyw/llvm-build/bin/opt -passes=early-cse reduced.ll\n1. Running pass \"function(early-cse<>)\" on module \"reduced.ll\"\n2. Running pass \"early-cse<>\" on function \"func_207\"\n #0 0x00007ffff7def832 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/zyw/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x1ef832)\n #1 0x00007ffff7dec9ef llvm::sys::RunSignalHandlers() (/data/zyw/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x1ec9ef)\n #2 0x00007ffff7decb35 SignalHandler(int) 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 0x00007ffff4efa75e llvm::DenseMap<(anonymous namespace)::SimpleValue, llvm::ScopedHashTableVal<(anonymous namespace)::SimpleValue, llvm::Value*>*, llvm::DenseMapInfo<(anonymous namespace)::SimpleValue, void>, llvm::detail::DenseMapPair<(anonymous namespace)::SimpleValue, llvm::ScopedHashTableVal<(anonymous namespace)::SimpleValue, llvm::Value*>*>>::grow(unsigned int) EarlyCSE.cpp:0:0\n#10 0x00007ffff4efbd5a llvm::ScopedHashTable<(anonymous namespace)::SimpleValue, llvm::Value*, llvm::DenseMapInfo<(anonymous namespace)::SimpleValue, void>, llvm::RecyclingAllocator<llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul, 128ul>, llvm::ScopedHashTableVal<(anonymous namespace)::SimpleValue, llvm::Value*>, 32ul, 8ul>>::insertIntoScope(llvm::ScopedHashTableScope<(anonymous namespace)::SimpleValue, llvm::Value*, llvm::DenseMapInfo<(anonymous namespace)::SimpleValue, void>, llvm::RecyclingAllocator<llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, 4096ul, 4096ul, 128ul>, llvm::ScopedHashTableVal<(anonymous namespace)::SimpleValue, llvm::Value*>, 32ul, 8ul>>*, (anonymous namespace)::SimpleValue const&, llvm::Value* const&) EarlyCSE.cpp:0:0\n#11 0x00007ffff4efdf19 (anonymous namespace)::EarlyCSE::processNode(llvm::DomTreeNodeBase<llvm::BasicBlock>*) (.isra.0) EarlyCSE.cpp:0:0\n#12 0x00007ffff4efeef5 (anonymous namespace)::EarlyCSE::run() EarlyCSE.cpp:0:0\n#13 0x00007ffff4f00796 llvm::EarlyCSEPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMScalarOpts.so.20.0git+0x100796)\n#14 0x00007ffff6684345 llvm::detail::PassModel<llvm::Function, llvm::EarlyCSEPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMPasses.so.20.0git+0x84345)\n#15 0x00007ffff38ee63d llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x2ee63d)\n#16 0x00007ffff70a9445 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.20.0git+0xa9445)\n#17 0x00007ffff38ec628 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x2ec628)\n#18 0x00007ffff70a9e05 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.20.0git+0xa9e05)\n#19 0x00007ffff38ed28d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/data/zyw/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x2ed28d)\n#20 0x00007ffff7f9b1eb 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.20.0git+0x241eb)\n#21 0x00007ffff7fa5619 optMain (/data/zyw/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x2e619)\n#22 0x00007ffff7829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#23 0x00007ffff7829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#24 0x0000555555555095 _start (/data/zyw/llvm-build/bin/opt+0x1095)\nAborted (core dumped)\n```",
"author": "dtcxzyw",
"labels": [
"crash-on-valid",
"llvm:transforms"
],
"comments": [
{
"author": "dtcxzyw",
"body": "Reverting 4a0d53a0b0a58a3c6980a7c551357ac71ba3db10 fixes this issue.\ncc @artagnon @nikic Can you double check the implementation of `hash_value(const CmpPredicate&)`?\n"
},
{
"author": "nikic",
"body": "Yeah, the implementation is incorrect for EarlyCSE (which should not take into account poison generating flags). I think we should remove the hash_value implementation and make the caller handler it appropriately."
},
{
"author": "artagnon",
"body": "Not sure I understand. The backtrace points to EarlyCSE.cpp:1558, and the Instruction it crashes on is an `or`. With surrounding context it is:\n\nhttps://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Scalar/EarlyCSE.cpp#L1392-L1560"
},
{
"author": "artagnon",
"body": "So I think this would fix the issue, although I'm not sure I understand the underlying issue:\n\n```diff\ndiff --git a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp\nindex 682c5c3d8c63..8e87f8b9a457 100644\n--- a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp\n+++ b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp\n@@ -290,7 +290,7 @@ static unsigned getHashValueImpl(SimpleValue Val) {\n Pred = CmpInst::getInversePredicate(Pred);\n std::swap(A, B);\n }\n- return hash_combine(Inst->getOpcode(), Pred, X, Y, A, B);\n+ return hash_combine(Inst->getOpcode(), static_cast<CmpInst::Predicate>(Pred), X, Y, A, B);\n }\n\n if (CastInst *CI = dyn_cast<CastInst>(Inst))\n```"
},
{
"author": "artagnon",
"body": "We hash two equal predicates, one with with samesign information (leading to a divergent hash), leading to a divergent hash_combine call, and hence a duplicate insertion into DenseMap:\n\n```cpp\n SelectPatternFlavor SPF;\n Value *Cond, *A, *B;\n if (matchSelectWithOptionalNotCond(Inst, Cond, A, B, SPF)) {\n // Hash min/max (cmp + select) to allow for commuted operands.\n // Min/max may also have non-canonical compare predicate (eg, the compare for\n // smin may use 'sgt' rather than 'slt'), and non-canonical operands in the\n // compare.\n // TODO: We should also detect FP min/max.\n if (SPF == SPF_SMIN || SPF == SPF_SMAX ||\n SPF == SPF_UMIN || SPF == SPF_UMAX) {\n if (A > B)\n std::swap(A, B);\n return hash_combine(Inst->getOpcode(), SPF, A, B);\n }\n\n // Hash general selects to allow matching commuted true/false operands.\n\n // If we do not have a compare as the condition, just hash in the condition.\n CmpPredicate Pred;\n Value *X, *Y;\n if (!match(Cond, m_Cmp(Pred, m_Value(X), m_Value(Y))))\n return hash_combine(Inst->getOpcode(), Cond, A, B);\n\n // Similar to cmp normalization (above) - canonicalize the predicate value:\n // select (icmp Pred, X, Y), A, B --> select (icmp InvPred, X, Y), B, A\n if (CmpInst::getInversePredicate(Pred) < Pred) {\n Pred = CmpInst::getInversePredicate(Pred);\n std::swap(A, B);\n }\n return hash_combine(Inst->getOpcode(), static_cast<CmpInst::Predicate>(Pred), X, Y, A, B); /// fixed\n }\n```\n\nThese are the duplicates:\n\n```llvm\n %cmp2.i = icmp samesign ugt i32 %conv1, 31\n %cmp1.i630 = icmp ugt i32 %conv1, 31\n```"
}
]
} | true | null |
90900 | https://github.com/llvm/llvm-project/issues/90900 | crash | 311339e25cd4d431902f93b1cbc6b67ac3fd2abf | 2024-05-02T19:52:37 | [
"llvm/test/Transforms/Reg2Mem"
] | {
"fix_commit": "fdaad738753cde2bba6480c2ee5d1e9fb45064b9",
"components": [
"DemoteRegToStack"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": [
[
50,
55
],
[
102,
110
]
],
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": [
"llvm::DemoteRegToStack"
],
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit fdaad738753cde2bba6480c2ee5d1e9fb45064b9
Author: XChy <[email protected]>
Date: Thu May 16 20:13:39 2024 +0800
[Reg2Mem] Handle CallBr instructions (#90953)
Fixes #90900
diff --git a/llvm/lib/Transforms/Utils/DemoteRegToStack.cpp b/llvm/lib/Transforms/Utils/DemoteRegToStack.cpp
index b2a88eadd3de..f03de2f25a41 100644
--- a/llvm/lib/Transforms/Utils/DemoteRegToStack.cpp
+++ b/llvm/lib/Transforms/Utils/DemoteRegToStack.cpp
@@ -50,6 +50,15 @@ AllocaInst *llvm::DemoteRegToStack(Instruction &I, bool VolatileLoads,
assert(BB && "Unable to split critical edge.");
(void)BB;
}
+ } else if (CallBrInst *CBI = dyn_cast<CallBrInst>(&I)) {
+ for (int i = 0; i < CBI->getNumSuccessors(); i++) {
+ auto *Succ = CBI->getSuccessor(i);
+ if (!Succ->getSinglePredecessor()) {
+ assert(isCriticalEdge(II, i) && "Expected a critical edge!");
+ BasicBlock *BB = SplitCriticalEdge(II, i);
+ assert(BB && "Unable to split critical edge.");
+ }
+ }
}
// Change all of the users of the instruction to read from the stack slot.
@@ -102,9 +111,14 @@ AllocaInst *llvm::DemoteRegToStack(Instruction &I, bool VolatileLoads,
new StoreInst(&I, Slot, Handler->getFirstInsertionPt());
return Slot;
}
+ } else if (InvokeInst *II = dyn_cast<InvokeInst>(&I)) {
+ InsertPt = II->getNormalDest()->getFirstInsertionPt();
+ } else if (CallBrInst *CBI = dyn_cast<CallBrInst>(&I)) {
+ for (BasicBlock *Succ : successors(CBI))
+ new StoreInst(CBI, Slot, Succ->getFirstInsertionPt());
+ return Slot;
} else {
- InvokeInst &II = cast<InvokeInst>(I);
- InsertPt = II.getNormalDest()->getFirstInsertionPt();
+ llvm_unreachable("Unsupported terminator for Reg2Mem");
}
new StoreInst(&I, Slot, InsertPt);
| [
{
"file": "llvm/test/Transforms/Reg2Mem/callbr-crash.ll",
"commands": [
"opt -passes=reg2mem -S < %s"
],
"tests": [
{
"test_name": "<module>",
"test_body": "\ndefine void @crash() {\n;\nentry:\n %a = callbr i64 asm \"\", \"=r,r,!i\"(i64 0)\n to label %then [label %else]\n\nthen:\n %b = inttoptr i64 %a to ptr\n br label %else\n\nelse:\n ret void\n}",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "Reg2Mem pass triggered assertion `isa<To>(V al) && \"cast<Ty>() argument of incompatible type!\"",
"body": "https://godbolt.org/z/oxW8zbKr6\r\n`opt --passes=reg2mem reduced.ll`\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%struct.__large_struct = type { [100 x i64] }\r\n\r\ndefine fastcc i64 @__se_sys_pselect6() {\r\n %1 = callbr i64 asm sideeffect \"\\0A1:\\09movq $1,$0\\0A .pushsection \\22__ex_table\\22,\\22a\\22\\0A .balign 4\\0A .long (1b) - .\\0A .long (${2:l}) - .\\0A .long 3 \\0A .popsection\\0A\", \"=r,*m,!i,~{dirflag},~{fpsr},~{flags}\"(ptr elementtype(%struct.__large_struct) null)\r\n to label %2 [label %common.ret]\r\n\r\n2: ; preds = %0\r\n %3 = inttoptr i64 %1 to ptr\r\n %4 = callbr i64 asm sideeffect \"\\0A1:\\09movq $1,$0\\0A .pushsection \\22__ex_table\\22,\\22a\\22\\0A .balign 4\\0A .long (1b) - .\\0A .long (${2:l}) - .\\0A .long 3 \\0A .popsection\\0A\", \"=r,*m,!i,~{dirflag},~{fpsr},~{flags}\"(ptr elementtype(%struct.__large_struct) null)\r\n to label %common.ret [label %common.ret]\r\n\r\ncommon.ret: ; preds = %2, %2, %0\r\n ret i64 0\r\n}\r\n```",
"author": "XChy",
"labels": [
"crash",
"llvm:transforms"
],
"comments": []
} | true | null |
114947 | https://github.com/llvm/llvm-project/issues/114947 | miscompilation | 1e5bfac933ea90ec4361446398551dd6b967c67f | 2024-11-05T07:42:44 | [
"llvm/test/Transforms/SCCP"
] | {
"fix_commit": "cd88bfcb5906049e1387b856fc7256e5fae22e5f",
"components": [
"ConstantFold"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": [
[
1266,
1279
],
[
1298,
1344
]
],
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": [
"llvm::ConstantFoldBinaryOpOperands",
"llvm::ConstantFoldCompareInstOperands",
"llvm::ConstantFoldFPInstOperands",
"llvm::FlushFPConstant"
],
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit cd88bfcb5906049e1387b856fc7256e5fae22e5f
Author: Matt Arsenault <[email protected]>
Date: Wed Nov 13 07:43:50 2024 -0800
ConstantFolding: Do not fold fcmp of denormal without known mode (#115407)
Fixes #114947
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 88db315ffd0b..1971c28fc4c4 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1266,14 +1266,16 @@ Constant *llvm::ConstantFoldCompareInstOperands(
return ConstantFoldCompareInstOperands(Predicate, Ops1, Ops0, DL, TLI);
}
- // Flush any denormal constant float input according to denormal handling
- // mode.
- Ops0 = FlushFPConstant(Ops0, I, /* IsOutput */ false);
- if (!Ops0)
- return nullptr;
- Ops1 = FlushFPConstant(Ops1, I, /* IsOutput */ false);
- if (!Ops1)
- return nullptr;
+ if (CmpInst::isFPPredicate(Predicate)) {
+ // Flush any denormal constant float input according to denormal handling
+ // mode.
+ Ops0 = FlushFPConstant(Ops0, I, /*IsOutput=*/false);
+ if (!Ops0)
+ return nullptr;
+ Ops1 = FlushFPConstant(Ops1, I, /*IsOutput=*/false);
+ if (!Ops1)
+ return nullptr;
+ }
return ConstantFoldCompareInstruction(Predicate, Ops0, Ops1);
}
@@ -1298,47 +1300,110 @@ Constant *llvm::ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS,
return ConstantFoldBinaryInstruction(Opcode, LHS, RHS);
}
-Constant *llvm::FlushFPConstant(Constant *Operand, const Instruction *I,
- bool IsOutput) {
- if (!I || !I->getParent() || !I->getFunction())
- return Operand;
+static ConstantFP *flushDenormalConstant(Type *Ty, const APFloat &APF,
+ DenormalMode::DenormalModeKind Mode) {
+ switch (Mode) {
+ case DenormalMode::Dynamic:
+ return nullptr;
+ case DenormalMode::IEEE:
+ return ConstantFP::get(Ty->getContext(), APF);
+ case DenormalMode::PreserveSign:
+ return ConstantFP::get(
+ Ty->getContext(),
+ APFloat::getZero(APF.getSemantics(), APF.isNegative()));
+ case DenormalMode::PositiveZero:
+ return ConstantFP::get(Ty->getContext(),
+ APFloat::getZero(APF.getSemantics(), false));
+ default:
+ break;
+ }
- ConstantFP *CFP = dyn_cast<ConstantFP>(Operand);
- if (!CFP)
- return Operand;
+ llvm_unreachable("unknown denormal mode");
+}
+
+/// Return the denormal mode that can be assumed when executing a floating point
+/// operation at \p CtxI.
+static DenormalMode getInstrDenormalMode(const Instruction *CtxI, Type *Ty) {
+ if (!CtxI || !CtxI->getParent() || !CtxI->getFunction())
+ return DenormalMode::getDynamic();
+ return CtxI->getFunction()->getDenormalMode(Ty->getFltSemantics());
+}
+static ConstantFP *flushDenormalConstantFP(ConstantFP *CFP,
+ const Instruction *Inst,
+ bool IsOutput) {
const APFloat &APF = CFP->getValueAPF();
- // TODO: Should this canonicalize nans?
if (!APF.isDenormal())
- return Operand;
+ return CFP;
- Type *Ty = CFP->getType();
- DenormalMode DenormMode =
- I->getFunction()->getDenormalMode(Ty->getFltSemantics());
- DenormalMode::DenormalModeKind Mode =
- IsOutput ? DenormMode.Output : DenormMode.Input;
- switch (Mode) {
- default:
- llvm_unreachable("unknown denormal mode");
- case DenormalMode::Dynamic:
- return nullptr;
- case DenormalMode::IEEE:
+ DenormalMode Mode = getInstrDenormalMode(Inst, CFP->getType());
+ return flushDenormalConstant(CFP->getType(), APF,
+ IsOutput ? Mode.Output : Mode.Input);
+}
+
+Constant *llvm::FlushFPConstant(Constant *Operand, const Instruction *Inst,
+ bool IsOutput) {
+ if (ConstantFP *CFP = dyn_cast<ConstantFP>(Operand))
+ return flushDenormalConstantFP(CFP, Inst, IsOutput);
+
+ if (isa<ConstantAggregateZero, UndefValue, ConstantExpr>(Operand))
return Operand;
- case DenormalMode::PreserveSign:
- if (APF.isDenormal()) {
- return ConstantFP::get(
- Ty->getContext(),
- APFloat::getZero(Ty->getFltSemantics(), APF.isNegative()));
+
+ Type *Ty = Operand->getType();
+ VectorType *VecTy = dyn_cast<VectorType>(Ty);
+ if (VecTy) {
+ if (auto *Splat = dyn_cast_or_null<ConstantFP>(Operand->getSplatValue())) {
+ ConstantFP *Folded = flushDenormalConstantFP(Splat, Inst, IsOutput);
+ if (!Folded)
+ return nullptr;
+ return ConstantVector::getSplat(VecTy->getElementCount(), Folded);
}
- return Operand;
- case DenormalMode::PositiveZero:
- if (APF.isDenormal()) {
- return ConstantFP::get(Ty->getContext(),
- APFloat::getZero(Ty->getFltSemantics(), false));
+
+ Ty = VecTy->getElementType();
+ }
+
+ if (const auto *CV = dyn_cast<ConstantVector>(Operand)) {
+ SmallVector<Constant *, 16> NewElts;
+ for (unsigned i = 0, e = CV->getNumOperands(); i != e; ++i) {
+ Constant *Element = CV->getAggregateElement(i);
+ if (isa<UndefValue>(Element)) {
+ NewElts.push_back(Element);
+ continue;
+ }
+
+ ConstantFP *CFP = dyn_cast<ConstantFP>(Element);
+ if (!CFP)
+ return nullptr;
+
+ ConstantFP *Folded = flushDenormalConstantFP(CFP, Inst, IsOutput);
+ if (!Folded)
+ return nullptr;
+ NewElts.push_back(Folded);
}
- return Operand;
+
+ return ConstantVector::get(NewElts);
+ }
+
+ if (const auto *CDV = dyn_cast<ConstantDataVector>(Operand)) {
+ SmallVector<Constant *, 16> NewElts;
+ for (unsigned I = 0, E = CDV->getNumElements(); I < E; ++I) {
+ const APFloat &Elt = CDV->getElementAsAPFloat(I);
+ if (!Elt.isDenormal()) {
+ NewElts.push_back(ConstantFP::get(Ty, Elt));
+ } else {
+ DenormalMode Mode = getInstrDenormalMode(Inst, Ty);
+ ConstantFP *Folded =
+ flushDenormalConstant(Ty, Elt, IsOutput ? Mode.Output : Mode.Input);
+ if (!Folded)
+ return nullptr;
+ NewElts.push_back(Folded);
+ }
+ }
+
+ return ConstantVector::get(NewElts);
}
- return Operand;
+
+ return nullptr;
}
Constant *llvm::ConstantFoldFPInstOperands(unsigned Opcode, Constant *LHS,
| [
{
"file": "llvm/test/Transforms/SCCP/no-fold-fcmp-dynamic-denormal-mode-issue114947.ll",
"commands": [
"opt -S -passes=ipsccp < %s"
],
"tests": [
{
"test_name": "no_fold_fcmp_denormal_double_ieee_dynamic_vector_nonsplat",
"test_body": "define <2 x i1> @no_fold_fcmp_denormal_double_ieee_dynamic_vector_nonsplat() #0 {\n %cmp = fcmp une <2 x double> <double 0x8000000000000, double 1.000000e+00>, zeroinitializer\n ret <2 x i1> %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "fold_fcmp_nondenormal_double_ieee_dynamic_vector_nonsplat_undef",
"test_body": "define <3 x i1> @fold_fcmp_nondenormal_double_ieee_dynamic_vector_nonsplat_undef() #0 {\n %cmp = fcmp une <3 x double> <double 2.000000e+00, double undef, double 4.000000e+00>, <double 1.000000e+00, double undef, double 4.000000e+00>\n ret <3 x i1> %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "no_fold_fcmp_denormal_double_ieee_dynamic_denormal_undef",
"test_body": "define i1 @no_fold_fcmp_denormal_double_ieee_dynamic_denormal_undef() #0 {\n %cmp = fcmp une double 0x8000000000000, undef\n ret i1 %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "fold_fcmp_nondenormal_double_ieee_dynamic_vector_nonsplat",
"test_body": "define <2 x i1> @fold_fcmp_nondenormal_double_ieee_dynamic_vector_nonsplat() #0 {\n %cmp = fcmp une <2 x double> <double 2.000000e+00, double 4.000000e+00>, <double 2.000000e+00, double 8.000000e+00>\n ret <2 x i1> %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "fold_fcmp_nondenormal_double_ieee_dynamic_vector_splat",
"test_body": "define <2 x i1> @fold_fcmp_nondenormal_double_ieee_dynamic_vector_splat() #0 {\n %cmp = fcmp une <2 x double> splat (double 2.000000e+00), zeroinitializer\n ret <2 x i1> %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "fold_fcmp_nondenormal_double_ieee_dynamic",
"test_body": "define i1 @fold_fcmp_nondenormal_double_ieee_dynamic() #0 {\n %cmp = fcmp une double 2.000000e+00, 0.000000e+00\n ret i1 %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "fold_fcmp_nondenormal_double_ieee_dynamic_zero",
"test_body": "define <2 x i1> @fold_fcmp_nondenormal_double_ieee_dynamic_zero() #0 {\n %cmp = fcmp une <2 x double> zeroinitializer, zeroinitializer\n ret <2 x i1> %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "no_fold_fcmp_denormal_double_ieee_dynamic_denormal_poison",
"test_body": "define i1 @no_fold_fcmp_denormal_double_ieee_dynamic_denormal_poison() #0 {\n %cmp = fcmp une double 0x8000000000000, poison\n ret i1 %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "no_fold_fcmp_denormal_double_ieee_dynamic_vector_splat",
"test_body": "define <2 x i1> @no_fold_fcmp_denormal_double_ieee_dynamic_vector_splat() #0 {\n %cmp = fcmp une <2 x double> splat (double 0x8000000000000), zeroinitializer\n ret <2 x i1> %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "no_fold_fcmp_denormal_double_ieee_dynamic",
"test_body": "define i1 @no_fold_fcmp_denormal_double_ieee_dynamic() #0 {\n %cmp = fcmp une double 0x8000000000000, 0.000000e+00\n ret i1 %cmp\n}\n\nattributes #0 = { \"denormal-fp-math\"=\"ieee,dynamic\" }\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "`fcmp` miscompiled to a constant",
"body": "Alive2 report: https://alive2.llvm.org/ce/z/324E7x\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine i1 @fcmp_double_dynamic_dynamic.2() denormal-fp-math=dynamic,dynamic {\r\n#0:\r\n %cmp = fcmp une double 0x0008000000000000, -0.000000\r\n ret i1 %cmp\r\n}\r\n=>\r\ndefine i1 @fcmp_double_dynamic_dynamic.2() nofree noundef willreturn denormal-fp-math=dynamic,dynamic memory(none) {\r\n#0:\r\n ret i1 1\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Value mismatch\r\n\r\nExample:\r\n\r\nSource:\r\ni1 %cmp = #x0 (0)\r\n\r\nTarget:\r\nSource value: #x0 (0)\r\nTarget value: #x1 (1)\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```\r\n",
"author": "bongjunj",
"labels": [
"miscompilation",
"floating-point",
"llvm:analysis"
],
"comments": [
{
"author": "arsenm",
"body": "I don't see the issue? Those values are in fact not equal, so this is true. Alive bug? "
},
{
"author": "jcranmer-intel",
"body": "it's comparing a denormal to 0, and the `denormal-fp-mode` is set to `dynamic`, so `fcmp` may or may not be flushing denormals to 0."
},
{
"author": "arsenm",
"body": "InstCombine doesn't fold this, IPSCCP does "
},
{
"author": "nikic",
"body": "I expect this is because we got through ValueLattice comparison, which does not have access to the denormal mode: https://github.com/llvm/llvm-project/blob/9501af5f92bb31fa9527d12a4b17b88d9fd651c4/llvm/lib/Analysis/ValueLattice.cpp#L28-L29\r\n\r\nReally, the constant folding implementation should be defaulting to the conservatively correct behavior if the denormal mode is unknown."
}
]
} | true | null |
128838 | https://github.com/llvm/llvm-project/issues/128838 | crash | 9c65e6ac115a7d8566c874537791125c3ace7c1a | 2025-02-26T07:25:33 | [
"llvm/test/Transforms/LoopVectorize"
] | {
"fix_commit": "62994c3291239f3d11f958d002319b2bd6eddbc9",
"components": [
"LoopVectorize"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
[
7691,
7701
]
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [
[
2180,
2186
],
[
2189,
2206
],
[
2210,
2219
]
],
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": [
[
189,
196
]
],
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
"LoopVectorizationPlanner::executePlan"
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": [
"VPlanTransforms::handleUncountableEarlyExit",
"VPlanTransforms::materializeLiveInBroadcasts"
],
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 62994c3291239f3d11f958d002319b2bd6eddbc9
Author: Florian Hahn <[email protected]>
Date: Wed Mar 12 22:03:18 2025 +0000
[VPlan] Also introduce explicit broadcasts for values from entry VPBB.
Update and generalize materializeBroadcasts to also introduce explicit
broadcasts for VPValues defined in the Plans Entry block.
This fixes a crash when trying to insert the broadcasts generated by
VPTransformState::get after the generating instruction, which isn't
possible after invoke instructions.
Fixes https://github.com/llvm/llvm-project/issues/128838.
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index bab2c6efd403..02bacde3f60a 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -7691,11 +7691,11 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
((VectorizingEpilogue && ExpandedSCEVs) ||
(!VectorizingEpilogue && !ExpandedSCEVs)) &&
"expanded SCEVs to reuse can only be used during epilogue vectorization");
- VPlanTransforms::materializeLiveInBroadcasts(BestVPlan);
// TODO: Move to VPlan transform stage once the transition to the VPlan-based
// cost model is complete for better cost estimates.
VPlanTransforms::runPass(VPlanTransforms::unrollByUF, BestVPlan, BestUF,
OrigLoop->getHeader()->getContext());
+ VPlanTransforms::materializeBroadcasts(BestVPlan);
VPlanTransforms::optimizeForVFAndUF(BestVPlan, BestVF, BestUF, PSE);
VPlanTransforms::simplifyRecipes(BestVPlan, *Legal->getWidestInductionType());
VPlanTransforms::removeDeadRecipes(BestVPlan);
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index ecf52673480e..f23795f87d46 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -2180,7 +2180,7 @@ void VPlanTransforms::handleUncountableEarlyExit(
LatchExitingBranch->eraseFromParent();
}
-void VPlanTransforms::materializeLiveInBroadcasts(VPlan &Plan) {
+void VPlanTransforms::materializeBroadcasts(VPlan &Plan) {
if (Plan.hasScalarVFOnly())
return;
@@ -2189,18 +2189,25 @@ void VPlanTransforms::materializeLiveInBroadcasts(VPlan &Plan) {
VPDT.recalculate(Plan);
#endif
+ SmallVector<VPValue *> VPValues;
+ append_range(VPValues, Plan.getLiveIns());
+ for (VPRecipeBase &R : *Plan.getEntry())
+ append_range(VPValues, R.definedValues());
+
auto *VectorPreheader = Plan.getVectorPreheader();
- for (VPValue *LiveIn : Plan.getLiveIns()) {
- if (all_of(LiveIn->users(),
- [LiveIn](VPUser *U) { return U->usesScalars(LiveIn); }) ||
- !LiveIn->getLiveInIRValue() ||
- isa<Constant>(LiveIn->getLiveInIRValue()))
+ for (VPValue *VPV : VPValues) {
+ if (all_of(VPV->users(),
+ [VPV](VPUser *U) { return U->usesScalars(VPV); }) ||
+ (VPV->isLiveIn() &&
+ (!VPV->getLiveInIRValue() || isa<Constant>(VPV->getLiveInIRValue()))))
continue;
// Add explicit broadcast at the insert point that dominates all users.
VPBasicBlock *HoistBlock = VectorPreheader;
VPBasicBlock::iterator HoistPoint = VectorPreheader->end();
- for (VPUser *User : LiveIn->users()) {
+ for (VPUser *User : VPV->users()) {
+ if (User->usesScalars(VPV))
+ continue;
if (cast<VPRecipeBase>(User)->getParent() == VectorPreheader)
HoistPoint = HoistBlock->begin();
else
@@ -2210,10 +2217,10 @@ void VPlanTransforms::materializeLiveInBroadcasts(VPlan &Plan) {
}
VPBuilder Builder(cast<VPBasicBlock>(HoistBlock), HoistPoint);
- auto *Broadcast = Builder.createNaryOp(VPInstruction::Broadcast, {LiveIn});
- LiveIn->replaceUsesWithIf(
- Broadcast, [LiveIn, Broadcast](VPUser &U, unsigned Idx) {
- return Broadcast != &U && !U.usesScalars(LiveIn);
- });
+ auto *Broadcast = Builder.createNaryOp(VPInstruction::Broadcast, {VPV});
+ VPV->replaceUsesWithIf(Broadcast,
+ [VPV, Broadcast](VPUser &U, unsigned Idx) {
+ return Broadcast != &U && !U.usesScalars(VPV);
+ });
}
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
index 8a9a81e00fe2..2ec07eea1ecc 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
@@ -189,8 +189,8 @@ struct VPlanTransforms {
optimizeInductionExitUsers(VPlan &Plan,
DenseMap<VPValue *, VPValue *> &EndValues);
- /// Add explicit broadcasts for live-ins used as vectors.
- static void materializeLiveInBroadcasts(VPlan &Plan);
+ /// Add explicit broadcasts for live-ins and VPValues defined in \p Plan's entry block if they are used as vectors.
+ static void materializeBroadcasts(VPlan &Plan);
};
} // namespace llvm
| [
{
"file": "llvm/test/Transforms/LoopVectorize/RISCV/illegal-type.ll",
"commands": [
"opt < %s -passes=loop-vectorize -mattr=+v -force-vector-width=4 -scalable-vectorization=on -S 2>&1"
],
"tests": [
{
"test_name": "uniform_store_i1",
"test_body": "target triple = \"riscv64-linux-gnu\"\n\ndefine void @uniform_store_i1(ptr noalias %dst, ptr noalias %start, i64 %N) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %first.sroa = phi ptr [ %incdec.ptr, %for.body ], [ %start, %entry ]\n %iv = phi i64 [ %iv.next, %for.body ], [ 0, %entry ]\n %iv.next = add i64 %iv, 1\n %incdec.ptr = getelementptr inbounds i64, ptr %first.sroa, i64 1\n %cmp.not = icmp eq ptr %incdec.ptr, %start\n store i1 %cmp.not, ptr %dst, align 1\n %cmp = icmp ult i64 %iv, %N\n br i1 %cmp, label %for.body, label %end, !llvm.loop !0\n\nend: ; preds = %for.body\n ret void\n}\n\n!0 = distinct !{!0, !1}\n!1 = !{!\"llvm.loop.vectorize.scalable.enable\", i1 true}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/X86/epilog-vectorization-inductions.ll",
"commands": [
"opt -passes=loop-vectorize -mcpu=znver2 -S %s"
],
"tests": [
{
"test_name": "test_induction_step_needs_expansion",
"test_body": "target triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @test_induction_step_needs_expansion(ptr noalias %j, ptr %k, i64 %l, i16 %off) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %p.09 = phi i16 [ 0, %entry ], [ %add, %loop ]\n %add = sub i16 %p.09, %off\n %arrayidx3 = getelementptr inbounds i16, ptr %k, i64 %iv\n store i16 %add, ptr %arrayidx3, align 2\n %iv.next = add nuw nsw i64 %iv, 1\n %ec = icmp eq i64 %iv.next, %l\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/X86/induction-step.ll",
"commands": [
"opt -passes=loop-vectorize -force-vector-width=4 -S %s"
],
"tests": [
{
"test_name": "wide_add_induction_step_live_in",
"test_body": "target triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i16 @wide_add_induction_step_live_in(ptr %dst, i64 %N, i16 %off) {\nentry:\n %o.1 = add i16 %off, 2\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.2 = phi i16 [ 0, %entry ], [ %add, %loop ]\n %add = add i16 %iv.2, %o.1\n %gep.dst = getelementptr inbounds i16, ptr %dst, i64 %iv\n store i16 %add, ptr %gep.dst, align 2\n %iv.next = add nuw nsw i64 %iv, 1\n %ec = icmp eq i64 %iv.next, %N\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i16 %add\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "wide_sub_induction_step_live_in",
"test_body": "target triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i16 @wide_sub_induction_step_live_in(ptr %dst, i64 %N, i16 %off) {\nentry:\n %o.1 = add i16 %off, 2\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.2 = phi i16 [ 0, %entry ], [ %sub, %loop ]\n %sub = sub i16 %iv.2, %o.1\n %gep.dst = getelementptr inbounds i16, ptr %dst, i64 %iv\n store i16 %sub, ptr %gep.dst, align 2\n %iv.next = add nuw nsw i64 %iv, 1\n %ec = icmp eq i64 %iv.next, %N\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret i16 %sub\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/expand-scev-after-invoke.ll",
"commands": [
"opt -p loop-vectorize -force-vector-width=4 -force-vector-interleave=2 -S %s"
],
"tests": [
{
"test_name": "<module>",
"test_body": "\ndeclare i32 @foo()\n\n; Test case for https://github.com/llvm/llvm-project/issues/128838. Make sure\n; we do not crash when expanding %step.\ndefine void @test(ptr %dst) personality ptr null {\n;\nentry:\n %step = invoke i32 @foo()\n to label %loop unwind label %lpad\n\nloop:\n %iv.1 = phi i64 [ 0, %entry ], [ %add, %loop ]\n %iv.2 = phi i32 [ 0, %entry ], [ %iv.2.next, %loop ]\n %add = add i64 %iv.1, 1\n %gep = getelementptr inbounds i32, ptr %dst, i64 %iv.1\n store i32 %iv.2, ptr %gep, align 8\n %iv.2.next = add i32 %iv.2, %step\n %ec = icmp ult i64 %iv.1, 161\n br i1 %ec, label %loop, label %exit\n\nexit:\n ret void\n\nlpad:\n %landingpad = landingpad { ptr, i32 }\n cleanup\n ret void\n}",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/float-induction.ll",
"commands": [
"opt < %s -passes=loop-vectorize,dce,instcombine -force-vector-interleave=1 -force-vector-width=4 -S",
"opt < %s -passes=loop-vectorize,dce,instcombine -force-vector-interleave=2 -force-vector-width=4 -S",
"opt < %s -passes=loop-vectorize,dce,instcombine -force-vector-interleave=2 -force-vector-width=1 -S",
"opt < %s -passes=loop-vectorize,dce,simplifycfg,instcombine,simplifycfg -force-vector-interleave=1 -force-vector-width=2 -simplifycfg-require-and-preserve-domtree=1 -keep-loops=false -S"
],
"tests": [
{
"test_name": "fp_iv_loop1_fast_FMF",
"test_body": "@fp_inc = external global float, align 4\n\ndefine void @fp_iv_loop1_fast_FMF(float %init, ptr noalias captures(none) %A, i32 %N) {\nentry:\n %cmp4 = icmp sgt i32 %N, 0\n br i1 %cmp4, label %for.body.lr.ph, label %for.end\n\nfor.body.lr.ph: ; preds = %entry\n %fpinc = load float, ptr @fp_inc, align 4\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.body.lr.ph\n %indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ]\n %x.05 = phi float [ %init, %for.body.lr.ph ], [ %add, %for.body ]\n %arrayidx = getelementptr inbounds float, ptr %A, i64 %indvars.iv\n store float %x.05, ptr %arrayidx, align 4\n %add = fsub fast float %x.05, %fpinc\n %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1\n %lftr.wideiv = trunc i64 %indvars.iv.next to i32\n %exitcond = icmp eq i32 %lftr.wideiv, %N\n br i1 %exitcond, label %for.end.loopexit, label %for.body\n\nfor.end.loopexit: ; preds = %for.body\n br label %for.end\n\nfor.end: ; preds = %for.end.loopexit, %entry\n ret void\n}\n\n!llvm.module.flags = !{!0}\n\n!0 = !{i32 2, !\"Debug Info Version\", i32 3}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "fp_iv_loop3",
"test_body": "@fp_inc = external global float, align 4\n\ndefine void @fp_iv_loop3(float %init, ptr noalias captures(none) %A, ptr noalias captures(none) %B, ptr noalias captures(none) %C, i32 %N) {\nentry:\n %cmp9 = icmp sgt i32 %N, 0\n br i1 %cmp9, label %for.body.lr.ph, label %for.end\n\nfor.body.lr.ph: ; preds = %entry\n %0 = load float, ptr @fp_inc, align 4\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.body.lr.ph\n %indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ]\n %y.012 = phi float [ 0x3FB99999A0000000, %for.body.lr.ph ], [ %conv1, %for.body ]\n %x.011 = phi float [ %init, %for.body.lr.ph ], [ %add, %for.body ]\n %arrayidx = getelementptr inbounds float, ptr %A, i64 %indvars.iv\n store float %x.011, ptr %arrayidx, align 4\n %add = fadd fast float %x.011, %0\n %conv1 = fadd fast float %y.012, -5.000000e-01\n %add2 = fadd fast float %conv1, %add\n %arrayidx4 = getelementptr inbounds float, ptr %B, i64 %indvars.iv\n store float %add2, ptr %arrayidx4, align 4\n %arrayidx6 = getelementptr inbounds float, ptr %C, i64 %indvars.iv\n store float %conv1, ptr %arrayidx6, align 4\n %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1\n %lftr.wideiv = trunc i64 %indvars.iv.next to i32\n %exitcond = icmp eq i32 %lftr.wideiv, %N\n br i1 %exitcond, label %for.end.loopexit, label %for.body\n\nfor.end.loopexit: ; preds = %for.body\n br label %for.end\n\nfor.end: ; preds = %for.end.loopexit, %entry\n ret void\n}\n\n!llvm.module.flags = !{!0}\n\n!0 = !{i32 2, !\"Debug Info Version\", i32 3}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "fp_iv_loop1_reassoc_FMF",
"test_body": "@fp_inc = external global float, align 4\n\ndefine void @fp_iv_loop1_reassoc_FMF(float %init, ptr noalias captures(none) %A, i32 %N) {\nentry:\n %cmp4 = icmp sgt i32 %N, 0\n br i1 %cmp4, label %for.body.lr.ph, label %for.end\n\nfor.body.lr.ph: ; preds = %entry\n %fpinc = load float, ptr @fp_inc, align 4\n br label %for.body\n\nfor.body: ; preds = %for.body, %for.body.lr.ph\n %indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ]\n %x.05 = phi float [ %init, %for.body.lr.ph ], [ %add, %for.body ]\n %arrayidx = getelementptr inbounds float, ptr %A, i64 %indvars.iv\n store float %x.05, ptr %arrayidx, align 4\n %add = fsub reassoc float %x.05, %fpinc\n %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1\n %lftr.wideiv = trunc i64 %indvars.iv.next to i32\n %exitcond = icmp eq i32 %lftr.wideiv, %N\n br i1 %exitcond, label %for.end.loopexit, label %for.body\n\nfor.end.loopexit: ; preds = %for.body\n br label %for.end\n\nfor.end: ; preds = %for.end.loopexit, %entry\n ret void\n}\n\n!llvm.module.flags = !{!0}\n\n!0 = !{i32 2, !\"Debug Info Version\", i32 3}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/induction-step.ll",
"commands": [
"opt < %s -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=8 -S"
],
"tests": [
{
"test_name": "wide_add_induction_step_live_in",
"test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine void @wide_add_induction_step_live_in(ptr %dst, i64 %N, i16 %off) {\nentry:\n %o.1 = add i16 %off, 2\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %iv.2 = phi i16 [ 0, %entry ], [ %add, %loop ]\n %add = add i16 %iv.2, %o.1\n %gep.dst = getelementptr inbounds i16, ptr %dst, i64 %iv\n store i16 %add, ptr %gep.dst, align 2\n %iv.next = add nuw nsw i64 %iv, 1\n %ec = icmp eq i64 %iv.next, %N\n br i1 %ec, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/LoopVectorize/induction.ll",
"commands": [
"opt < %s -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S",
"opt < %s -passes=loop-vectorize,instcombine -force-vector-interleave=1 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S",
"opt < %s -passes=loop-vectorize,instcombine -force-vector-interleave=2 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S",
"opt < %s -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=2 -force-widen-divrem-via-safe-divisor=0 -S",
"opt < %s -passes=loop-vectorize,instcombine -force-vector-interleave=2 -force-vector-width=4 -force-widen-divrem-via-safe-divisor=0 -enable-interleaved-mem-accesses -S"
],
"tests": [
{
"test_name": "test_optimized_cast_induction_feeding_first_order_recurrence",
"test_body": "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128\"\n\ndefine void @test_optimized_cast_induction_feeding_first_order_recurrence(i64 %n, i32 %step, ptr %ptr) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %for = phi i32 [ 0, %entry ], [ %iv.2.conv, %loop ]\n %iv.1 = phi i64 [ 0, %entry ], [ %iv.1.next, %loop ]\n %iv.2 = phi i32 [ 0, %entry ], [ %iv.2.next, %loop ]\n %iv.2.ext = shl i32 %iv.2, 24\n %iv.2.conv = ashr exact i32 %iv.2.ext, 24\n %gep = getelementptr inbounds i32, ptr %ptr, i64 %iv.1\n store i32 %for, ptr %gep, align 4\n %iv.2.next = add nsw i32 %iv.2.conv, %step\n %iv.1.next = add nuw nsw i64 %iv.1, 1\n %exitcond = icmp eq i64 %iv.1.next, %n\n br i1 %exitcond, label %exit, label %loop\n\nexit: ; preds = %loop\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "Assertion `!NodePtr->isKnownSentinel()' failed.",
"body": "To reproduce run opt with the test below, -passes=loop-vectorize\n```\n; ModuleID = './reduced.ll'\nsource_filename = \"./reduced.ll\"\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine void @wombat() gc \"statepoint-example\" personality ptr null {\nbb:\n %invoke = invoke i32 null(ptr addrspace(1) null, i32 0, i32 0, i32 0)\n to label %bb1 unwind label %bb5\n\nbb1: ; preds = %bb1, %bb\n %phi = phi i64 [ %add, %bb1 ], [ 0, %bb ]\n %phi2 = phi i32 [ %add3, %bb1 ], [ 0, %bb ]\n %add = add i64 %phi, 1\n %sitofp = sitofp i32 %phi2 to double\n store double %sitofp, ptr addrspace(1) null, align 8\n %add3 = add i32 %phi2, %invoke\n %icmp = icmp ult i64 %phi, 161\n br i1 %icmp, label %bb1, label %bb4\n\nbb4: ; preds = %bb1\n ret void\n\nbb5: ; preds = %bb\n %landingpad = landingpad { ptr, i32 }\n cleanup\n ret void\n}\n```\nReproducer: https://godbolt.org/z/3do96adnn\n\nStack dump:\n```\nopt: /root/llvm-project/llvm/include/llvm/ADT/ilist_iterator.h:322: llvm::ilist_iterator_w_bits<OptionsT, IsReverse, IsConst>::reference llvm::ilist_iterator_w_bits<OptionsT, IsReverse, IsConst>::operator*() const [with OptionsT = llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true, llvm::BasicBlock>; bool IsReverse = false; bool IsConst = false; llvm::ilist_iterator_w_bits<OptionsT, IsReverse, IsConst>::reference = llvm::Instruction&]: Assertion `!NodePtr->isKnownSentinel()' failed.\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\nStack dump:\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=loop-vectorize <source>\n1.\tRunning pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"<source>\"\n2.\tRunning pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"wombat\"\n #0 0x0000000005452b98 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5452b98)\n #1 0x0000000005450554 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0\n #2 0x00007b16e6242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\n #3 0x00007b16e62969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\n #4 0x00007b16e6242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\n #5 0x00007b16e62287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\n #6 0x00007b16e622871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\n #7 0x00007b16e6239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\n #8 0x00000000044f6c23 (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44f6c23)\n #9 0x000000000450ebb3 llvm::VPTransformState::get(llvm::VPValue*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x450ebb3)\n#10 0x0000000004543138 llvm::VPInstruction::generate(llvm::VPTransformState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4543138)\n#11 0x0000000004544ba4 llvm::VPInstruction::execute(llvm::VPTransformState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4544ba4)\n#12 0x00000000044f82e7 llvm::VPBasicBlock::executeRecipes(llvm::VPTransformState*, llvm::BasicBlock*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x44f82e7)\n#13 0x00000000045038f9 llvm::VPIRBasicBlock::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x45038f9)\n#14 0x0000000004510249 llvm::VPlan::execute(llvm::VPTransformState*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4510249)\n#15 0x00000000043cccce llvm::LoopVectorizationPlanner::executePlan(llvm::ElementCount, unsigned int, llvm::VPlan&, llvm::InnerLoopVectorizer&, llvm::DominatorTree*, bool, llvm::DenseMap<llvm::SCEV const*, llvm::Value*, llvm::DenseMapInfo<llvm::SCEV const*, void>, llvm::detail::DenseMapPair<llvm::SCEV const*, llvm::Value*>> const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43cccce)\n#16 0x00000000043e15d8 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43e15d8)\n#17 0x00000000043e2f49 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43e2f49)\n#18 0x00000000043e35c3 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43e35c3)\n#19 0x000000000318aaae llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x318aaae)\n#20 0x000000000524cd90 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x524cd90)\n#21 0x0000000000e6f54e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6f54e)\n#22 0x000000000524b6ab llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x524b6ab)\n#23 0x0000000000e6e83e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6e83e)\n#24 0x000000000524b0b0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x524b0b0)\n#25 0x0000000000935a3a llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x935a3a)\n#26 0x00000000009290ac optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x9290ac)\n#27 0x00007b16e6229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\n#28 0x00007b16e6229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\n#29 0x0000000000920985 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x920985)\nProgram terminated with signal: SIGSEGV\nCompiler returned: 139\n```",
"author": "TatyanaDoubts",
"labels": [
"vectorizers",
"crash-on-valid"
],
"comments": [
{
"author": "fhahn",
"body": "looking "
}
]
} | true | null |
95016 | https://github.com/llvm/llvm-project/issues/95016 | crash | 1846523bb77275de954ac573110171bd39bfa930 | 2024-06-10T18:08:58 | [
"llvm/test/Transforms/SLPVectorizer"
] | {
"fix_commit": "380beaec8633bad0148aec02f03a85d9a59b2a2d",
"components": [
"SLPVectorizer"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
[
835,
845
]
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
"getSameOpcode"
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 380beaec8633bad0148aec02f03a85d9a59b2a2d
Author: Gabriel Baraldi <[email protected]>
Date: Tue Jul 2 09:15:51 2024 -0300
Fix potential crash in SLPVectorizer caused by missing check (#95937)
I'm not super familiar with this code, but it seems that we were just
missing a check.
The original code that triggered this did not have uselistorders but
llvm-reduce created them and it reproduces the same issue in a way more
compact way.
Fixes https://github.com/llvm/llvm-project/issues/95016
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index c4876bb92a1c..868e9e2687f5 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -835,11 +835,11 @@ static InstructionsState getSameOpcode(ArrayRef<Value *> VL,
auto *CallBase = cast<CallInst>(IBase);
if (Call->getCalledFunction() != CallBase->getCalledFunction())
return InstructionsState(VL[BaseIndex], nullptr, nullptr);
- if (Call->hasOperandBundles() &&
+ if (Call->hasOperandBundles() && (!CallBase->hasOperandBundles() ||
!std::equal(Call->op_begin() + Call->getBundleOperandsStartIndex(),
Call->op_begin() + Call->getBundleOperandsEndIndex(),
CallBase->op_begin() +
- CallBase->getBundleOperandsStartIndex()))
+ CallBase->getBundleOperandsStartIndex())))
return InstructionsState(VL[BaseIndex], nullptr, nullptr);
Intrinsic::ID ID = getVectorIntrinsicIDForCall(Call, &TLI);
if (ID != BaseID)
| [
{
"file": "llvm/test/Transforms/SLPVectorizer/AArch64/uselistorder.ll",
"commands": [
"opt < %s -passes=slp-vectorizer -S -pass-remarks-missed=slp-vectorizer 2>&1"
],
"tests": [
{
"test_name": "<module>",
"test_body": "\ntarget datalayout = \"e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"aarch64-unknown-linux-gnu\"\n\n; This test has UB but the crash in #95016 only happens with it\ndefine void @uselistorder_test() {\n;\n %max1 = call double @llvm.maximum.f64(double 0.000000e+00, double 0.000000e+00) [ \"a_list\"(ptr null) ]\n %add1 = fadd double %max1, 0.000000e+00\n %mul1 = fmul double 0.000000e+00, %add1\n %mul2 = fmul double %mul1, 0.000000e+00\n %sel1 = select i1 false, double 0.000000e+00, double %mul2\n %max2 = call double @llvm.maximum.f64(double 0.000000e+00, double 0.000000e+00)\n %add2 = fadd double %max2, 0.000000e+00\n %mul3 = fmul double 0.000000e+00, %add2\n %mul4 = fmul double %mul3, 0.000000e+00\n %sel2 = select i1 false, double 0.000000e+00, double %mul4\n %mul5 = fmul double %sel2, 0.000000e+00\n %add3 = fadd double 0.000000e+00, %mul5\n %gep1 = getelementptr { double, [1 x [2 x double]] }, ptr null, i64 0, i32 1\n store double %add3, ptr %gep1, align 8\n %mul6 = fmul double %sel1, 0.000000e+00\n %add4 = fadd double %mul6, 0.000000e+00\n store double %add4, ptr null, align 8\n ret void\n}\n\ndeclare double @llvm.maximum.f64(double, double) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "SLPVectorizer (hasOperandBundles() && \"Don't call otherwise!\") assertion trigger with verified module",
"body": "SLPVectorize asserts while optimizing the following module\r\n```llvm-ir\r\ntarget datalayout = \"e-m:o-i64:64-i128:128-n32:64-S128-ni:10:11:12:13\"\r\ntarget triple = \"arm64-apple-darwin23.5.0\"\r\n\r\ndefine swiftcc void @julia_multiparameter_a_res_17823() {\r\ntop:\r\n %0 = call double @llvm.maximum.f64(double 0.000000e+00, double 0.000000e+00) [ \"jl_roots\"(ptr null) ]\r\n %1 = fadd double %0, 0.000000e+00\r\n %2 = fmul double 0.000000e+00, %1\r\n %3 = fmul double %2, 0.000000e+00\r\n %4 = select i1 false, double 0.000000e+00, double %3\r\n %5 = call double @llvm.maximum.f64(double 0.000000e+00, double 0.000000e+00)\r\n %6 = fadd double %5, 0.000000e+00\r\n %7 = fmul double 0.000000e+00, %6\r\n %8 = fmul double %7, 0.000000e+00\r\n %9 = select i1 false, double 0.000000e+00, double %8\r\n %10 = fmul double %9, 0.000000e+00\r\n %11 = fadd double 0.000000e+00, %10\r\n %12 = getelementptr { double, [1 x [2 x double]] }, ptr null, i64 0, i32 1\r\n store double %11, ptr %12, align 8\r\n %13 = fmul double %4, 0.000000e+00\r\n %14 = fadd double %13, 0.000000e+00\r\n store double %14, ptr null, align 8\r\n ret void\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare double @llvm.maximum.f64(double, double) #0\r\n\r\n; uselistorder directives\r\nuselistorder ptr @llvm.maximum.f64, { 1, 0 }\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\n\r\nThis also seems to trigger on godbolt on whatever version of trunk they have there\r\nhttps://godbolt.org/z/favErWG5K\r\n\r\n\r\nstacktrace:\r\n> #0 0x0000000004e258c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e258c8)\r\n #1 0x0000000004e2301c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007c7148042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007c71480969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007c7148042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007c71480287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007c714802871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007c7148039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000003ee5e8f (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3ee5e8f)\r\n #9 0x0000000003f5e546 getSameOpcode(llvm::ArrayRef<llvm::Value*>, llvm::TargetLibraryInfo const&, unsigned int) (.constprop.1) SLPVectorizer.cpp:0:0\r\n#10 0x0000000003f67928 llvm::slpvectorizer::BoUpSLP::LookAheadHeuristics::getShallowScore(llvm::Value*, llvm::Value*, llvm::Instruction*, llvm::Instruction*, llvm::ArrayRef<llvm::Value*>) const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f67928)\r\n#11 0x0000000003f67de0 llvm::slpvectorizer::BoUpSLP::LookAheadHeuristics::getScoreAtLevelRec(llvm::Value*, llvm::Value*, llvm::Instruction*, llvm::Instruction*, int, llvm::ArrayRef<llvm::Value*>) const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f67de0)\r\n#12 0x0000000003f6aaf5 llvm::slpvectorizer::BoUpSLP::VLOperands::getBestOperand(unsigned int, int, int, llvm::ArrayRef<llvm::slpvectorizer::BoUpSLP::VLOperands::ReorderingMode>, llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f6aaf5)\r\n#13 0x0000000003f6bfcb llvm::slpvectorizer::BoUpSLP::VLOperands::reorder() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f6bfcb)\r\n#14 0x0000000003f6c4f6 llvm::slpvectorizer::BoUpSLP::reorderInputsAccordingToOpcode(llvm::ArrayRef<llvm::Value*>, llvm::SmallVectorImpl<llvm::Value*>&, llvm::SmallVectorImpl<llvm::Value*>&, llvm::slpvectorizer::BoUpSLP const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f6c4f6)\r\n#15 0x0000000003f702f4 llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f702f4)\r\n#16 0x0000000003f70392 llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f70392)\r\n#17 0x0000000003f70362 llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f70362)\r\n#18 0x0000000003f7022b llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f7022b)\r\n#19 0x0000000003f70362 llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f70362)\r\n#20 0x0000000003f70362 llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f70362)\r\n#21 0x0000000003f6fe47 llvm::slpvectorizer::BoUpSLP::buildTree_rec(llvm::ArrayRef<llvm::Value*>, unsigned int, llvm::slpvectorizer::BoUpSLP::EdgeInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f6fe47)\r\n#22 0x0000000003f71b59 llvm::slpvectorizer::BoUpSLP::buildTree(llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f71b59)\r\n#23 0x0000000003f94622 llvm::SLPVectorizerPass::vectorizeStoreChain(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, unsigned int, unsigned int, unsigned int&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f94622)\r\n#24 0x0000000003f95fb0 llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&)::'lambda'(std::set<std::pair<unsigned int, int>, llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&)::StoreDistCompare, std::allocator<std::pair<unsigned int, int>>> const&)::operator()(std::set<std::pair<unsigned int, int>, llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&)::StoreDistCompare, std::allocator<std::pair<unsigned int, int>>> const&) const SLPVectorizer.cpp:0:0\r\n#25 0x0000000003f97e88 llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f97e88)\r\n#26 0x0000000003f985b3 llvm::SLPVectorizerPass::vectorizeStoreChains(llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f985b3)\r\n#27 0x0000000003f9970f llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\r\n#28 0x0000000003f9a163 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3f9a163)\r\n#29 0x0000000002e1013e llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2e1013e)\r\n#30 0x0000000004c2e64c llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c2e64c)\r\n#31 0x0000000000db3bce llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xdb3bce)\r\n#32 0x0000000004c2cf8e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c2cf8e)\r\n#33 0x0000000000db563e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xdb563e)\r\n#34 0x0000000004c2ae9c llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c2ae9c)\r\n#35 0x00000000008d7b32 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d7b32)\r\n#36 0x00000000008cacdc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8cacdc)\r\n#37 0x00007c7148029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#38 0x00007c7148029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#39 0x00000000008c212e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8c212e)",
"author": "gbaraldi",
"labels": [
"llvm:SLPVectorizer",
"crash"
],
"comments": []
} | true | null |
113794 | https://github.com/llvm/llvm-project/issues/113794 | crash | 21895a84cf466f0a0632cfca0175f7e617a6dd5a | 2024-10-27T05:55:32 | [
"llvm/test/Transforms/LoopVectorize"
] | {
"fix_commit": "17bad1a9da228ade0c0b9b020ee99769b188d9b3",
"components": [
"LoopVectorize"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
[
6389,
6397
]
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
"LoopVectorizationCostModel::getInstructionCost",
"LoopVectorizationCostModel::shouldConsiderInvariant"
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 17bad1a9da228ade0c0b9b020ee99769b188d9b3
Author: Florian Hahn <[email protected]>
Date: Fri Nov 1 20:51:25 2024 +0000
[LV] Bail out on header phis in shouldConsiderInvariant.
This fixes an infinite recursion in rare cases.
Fixes https://github.com/llvm/llvm-project/issues/113794.
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 659b4c30a58a..1c64bd2982d7 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -6389,9 +6389,11 @@ bool LoopVectorizationCostModel::shouldConsiderInvariant(Value *Op) {
return false;
// Consider Op invariant, if it or its operands aren't predicated
// instruction in the loop. In that case, it is not trivially hoistable.
- return !isa<Instruction>(Op) || !TheLoop->contains(cast<Instruction>(Op)) ||
- (!isPredicatedInst(cast<Instruction>(Op)) &&
- all_of(cast<Instruction>(Op)->operands(),
+ auto *OpI = dyn_cast<Instruction>(Op);
+ return !OpI || !TheLoop->contains(OpI) ||
+ (!isPredicatedInst(OpI) &&
+ (!isa<PHINode>(OpI) || OpI->getParent() != TheLoop->getHeader()) &&
+ all_of(OpI->operands(),
[this](Value *Op) { return shouldConsiderInvariant(Op); }));
}
| [
{
"file": "llvm/test/Transforms/LoopVectorize/phi-cost.ll",
"commands": [
"opt < %s -passes='function(loop-vectorize,instcombine)' -force-vector-width=2 -force-vector-interleave=1 -debug-only=loop-vectorize -disable-output -print-after=instcombine 2>&1"
],
"tests": [
{
"test_name": "red_phi_0",
"test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\n\ndefine i32 @red_phi_0(i32 %start, ptr %src) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %red = phi i32 [ %start, %entry ], [ %red.next, %loop ]\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n %red.next = add i32 0, %red\n %iv.next = add i64 %iv, 1\n %exitcond.not = icmp eq i64 %iv.next, 100\n br i1 %exitcond.not, label %exit, label %loop\n\nexit: ; preds = %loop\n %res = phi i32 [ %red.next, %loop ]\n ret i32 %res\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "phi_three_incoming_values",
"test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\n\ndefine void @phi_three_incoming_values(ptr noalias %a, ptr noalias %b, i64 %n) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %if.end, %entry\n %i = phi i64 [ %i.next, %if.end ], [ 0, %entry ]\n %tmp0 = getelementptr inbounds i32, ptr %a, i64 %i\n %tmp1 = load i32, ptr %tmp0, align 4\n %tmp2 = getelementptr inbounds i32, ptr %b, i64 %i\n %tmp3 = load i32, ptr %tmp2, align 4\n %tmp4 = icmp sgt i32 %tmp1, %tmp3\n br i1 %tmp4, label %if.then, label %if.end\n\nif.then: ; preds = %for.body\n %tmp5 = icmp sgt i32 %tmp1, 19\n br i1 %tmp5, label %if.end, label %if.else\n\nif.else: ; preds = %if.then\n %tmp6 = icmp slt i32 %tmp3, 4\n %tmp7 = select i1 %tmp6, i32 4, i32 5\n br label %if.end\n\nif.end: ; preds = %if.else, %if.then, %for.body\n %tmp8 = phi i32 [ 9, %for.body ], [ 3, %if.then ], [ %tmp7, %if.else ]\n store i32 %tmp8, ptr %tmp0, align 4\n %i.next = add i64 %i, 1\n %cond = icmp eq i64 %i, %n\n br i1 %cond, label %for.end, label %for.body\n\nfor.end: ; preds = %if.end\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "phi_two_incoming_values",
"test_body": "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\"\n\ndefine void @phi_two_incoming_values(ptr noalias %a, ptr noalias %b, i64 %n) {\nentry:\n br label %for.body\n\nfor.body: ; preds = %if.end, %entry\n %i = phi i64 [ %i.next, %if.end ], [ 0, %entry ]\n %tmp0 = getelementptr inbounds i32, ptr %a, i64 %i\n %tmp1 = load i32, ptr %tmp0, align 4\n %tmp2 = getelementptr inbounds i32, ptr %b, i64 %i\n %tmp3 = icmp sgt i32 %tmp1, 0\n br i1 %tmp3, label %if.then, label %if.end\n\nif.then: ; preds = %for.body\n %tmp4 = add i32 %tmp1, 1\n br label %if.end\n\nif.end: ; preds = %if.then, %for.body\n %tmp5 = phi i32 [ %tmp1, %for.body ], [ %tmp4, %if.then ]\n store i32 %tmp5, ptr %tmp2, align 4\n %i.next = add i64 %i, 1\n %cond = icmp eq i64 %i, %n\n br i1 %cond, label %for.end, label %for.body\n\nfor.end: ; preds = %if.end\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[clang] Segmentation fault in loop vectorization cost model during optimization pass",
"body": "When I compiled this code with -O2 flag, it crashed:\r\n\r\n```c\r\n#include <stdint.h>\r\n#define UNDEFINED(x) ((x), 0)\r\nlong b;\r\nstatic int64_t j = 1;\r\nstatic int64_t *k = &j;\r\nstatic int64_t **l = &k;\r\nint64_t m;\r\nstatic uint64_t n;\r\nint16_t ***o;\r\nstatic int64_t ***p = &l;\r\nuint64_t **q;\r\n\r\nuint16_t\r\nsafe_mod_func_uint16_t_u_u(uint16_t ui1, uint16_t ui2)\r\n{\r\n return \r\n#ifndef UNSAFE\r\n (ui2 == 0) ? \r\n (UNDEFINED(ui1)) : \r\n#endif\r\n (ui1 % ui2);\r\n}\r\n\r\nint64_t\r\nsafe_mod_func_int64_t_s_s(int64_t si1, int64_t si2)\r\n{\r\n return \r\n#ifndef UNSAFE\r\n ((si2 == 0) || ((si1 == INT64_MIN) && (si2 == (-1)))) ? \r\n (UNDEFINED(si1)) : \r\n#endif\r\n (si1 % si2);\r\n}\r\n\r\nint a(int, int, int, int, int) {}\r\nlong c(int d, int *e) {\r\n switch (d) {\r\n case 9:\r\n return b;\r\n case 8:\r\n return *e;\r\n }\r\n}\r\nlong f(int g, long, int h) {\r\n long i = c(g, &h);\r\n return i;\r\n}\r\nint32_t r() { int32_t *s[] = {&k, &m}; }\r\nint32_t t(int32_t *aa) {\r\n uint64_t ab = 2599693332;\r\n uint8_t ac = 142;\r\n for (; n <= 4; n++)\r\n *aa = (safe_mod_func_uint16_t_u_u(\r\n safe_mod_func_int64_t_s_s(a(0, 0, 0, 0, **l + 20) + **l, **q),\r\n ***o |= f(**l, 0, ***p)),\r\n **l + ac + ab - -1695273821 + *aa);\r\n}\r\n```\r\n\r\nThe crash is: clang: error: unable to execute command: Segmentation fault (core dumped)\r\nclang: error: clang frontend command failed due to signal (use -v to see invocation)\r\nCompiler returned: 254\r\n\r\nDetails can be found here: https://godbolt.org/z/3h9j7W6dG",
"author": "cardigan1008",
"labels": [
"regression",
"vectorizers",
"crash"
],
"comments": [
{
"author": "shafik",
"body": "This looks like a clang trunk regression: https://godbolt.org/z/MoKeds3ev"
}
]
} | true | null |
106667 | https://github.com/llvm/llvm-project/issues/106667 | crash | 5500e21942f7047344b6fee62d3e08c0ba2f9182 | 2024-08-30T05:59:16 | [
"llvm/test/Transforms/SLPVectorizer"
] | {
"fix_commit": "a4aa6bc8fc2130761b8db5db4748059127662785",
"components": [
"SLPVectorizer"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
[
2864,
2869
],
[
6964,
6969
],
[
7095,
7149
],
[
9362,
9383
],
[
12521,
12530
],
[
12532,
12640
]
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
"BoUpSLP::buildTree_rec",
"BoUpSLP::getOperandEntry",
"BoUpSLP::vectorizeOperand"
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit a4aa6bc8fc2130761b8db5db4748059127662785
Author: Alexey Bataev <[email protected]>
Date: Fri Aug 30 10:17:31 2024 -0700
[SLP]Fix PR106667: carefully look for operand nodes.
If the operand node has the same scalars as one of the vectorized nodes,
the compiler could miss this and incorrectly request minbitwidth data
for the wrong node. It may lead to a compiler crash, because the
vectorized node might have different minbw result.
Fixes https://github.com/llvm/llvm-project/issues/106667
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 4c0a1c4c094b..e9785ef9ded2 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -2864,6 +2864,12 @@ private:
/// avoid issues with def-use order.
Value *vectorizeTree(TreeEntry *E, bool PostponedPHIs);
+ TreeEntry *getMatchedVectorizedOperand(const TreeEntry *E, unsigned NodeIdx);
+ const TreeEntry *getMatchedVectorizedOperand(const TreeEntry *E,
+ unsigned NodeIdx) const {
+ return const_cast<BoUpSLP *>(this)->getMatchedVectorizedOperand(E, NodeIdx);
+ }
+
/// Vectorize a single entry in the tree, the \p Idx-th operand of the entry
/// \p E.
/// \param PostponedPHIs true, if need to postpone emission of phi nodes to
@@ -6964,6 +6970,55 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
}
}
+ // Check if this is a duplicate of another entry.
+ if (TreeEntry *E = getTreeEntry(S.OpValue)) {
+ LLVM_DEBUG(dbgs() << "SLP: \tChecking bundle: " << *S.OpValue << ".\n");
+ if (!E->isSame(VL)) {
+ auto It = MultiNodeScalars.find(S.OpValue);
+ if (It != MultiNodeScalars.end()) {
+ auto *TEIt = find_if(It->getSecond(),
+ [&](TreeEntry *ME) { return ME->isSame(VL); });
+ if (TEIt != It->getSecond().end())
+ E = *TEIt;
+ else
+ E = nullptr;
+ } else {
+ E = nullptr;
+ }
+ }
+ if (!E) {
+ if (!doesNotNeedToBeScheduled(S.OpValue)) {
+ LLVM_DEBUG(dbgs() << "SLP: Gathering due to partial overlap.\n");
+ if (TryToFindDuplicates(S))
+ newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx,
+ ReuseShuffleIndices);
+ return;
+ }
+ SmallPtrSet<const TreeEntry *, 4> Nodes;
+ Nodes.insert(getTreeEntry(S.OpValue));
+ for (const TreeEntry *E : MultiNodeScalars.lookup(S.OpValue))
+ Nodes.insert(E);
+ SmallPtrSet<Value *, 8> Values(VL.begin(), VL.end());
+ if (any_of(Nodes, [&](const TreeEntry *E) {
+ return all_of(E->Scalars,
+ [&](Value *V) { return Values.contains(V); });
+ })) {
+ LLVM_DEBUG(dbgs() << "SLP: Gathering due to full overlap.\n");
+ if (TryToFindDuplicates(S))
+ newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx,
+ ReuseShuffleIndices);
+ return;
+ }
+ } else {
+ // Record the reuse of the tree node. FIXME, currently this is only used
+ // to properly draw the graph rather than for the actual vectorization.
+ E->UserTreeIndices.push_back(UserTreeIdx);
+ LLVM_DEBUG(dbgs() << "SLP: Perfect diamond merge at " << *S.OpValue
+ << ".\n");
+ return;
+ }
+ }
+
// Gather if we hit the RecursionMaxDepth, unless this is a load (or z/sext of
// a load), in which case peek through to include it in the tree, without
// ballooning over-budget.
@@ -7095,55 +7150,6 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
// We now know that this is a vector of instructions of the same type from
// the same block.
- // Check if this is a duplicate of another entry.
- if (TreeEntry *E = getTreeEntry(S.OpValue)) {
- LLVM_DEBUG(dbgs() << "SLP: \tChecking bundle: " << *S.OpValue << ".\n");
- if (!E->isSame(VL)) {
- auto It = MultiNodeScalars.find(S.OpValue);
- if (It != MultiNodeScalars.end()) {
- auto *TEIt = find_if(It->getSecond(),
- [&](TreeEntry *ME) { return ME->isSame(VL); });
- if (TEIt != It->getSecond().end())
- E = *TEIt;
- else
- E = nullptr;
- } else {
- E = nullptr;
- }
- }
- if (!E) {
- if (!doesNotNeedToBeScheduled(S.OpValue)) {
- LLVM_DEBUG(dbgs() << "SLP: Gathering due to partial overlap.\n");
- if (TryToFindDuplicates(S))
- newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx,
- ReuseShuffleIndices);
- return;
- }
- SmallPtrSet<const TreeEntry *, 4> Nodes;
- Nodes.insert(getTreeEntry(S.OpValue));
- for (const TreeEntry *E : MultiNodeScalars.lookup(S.OpValue))
- Nodes.insert(E);
- SmallPtrSet<Value *, 8> Values(VL.begin(), VL.end());
- if (any_of(Nodes, [&](const TreeEntry *E) {
- return all_of(E->Scalars,
- [&](Value *V) { return Values.contains(V); });
- })) {
- LLVM_DEBUG(dbgs() << "SLP: Gathering due to full overlap.\n");
- if (TryToFindDuplicates(S))
- newTreeEntry(VL, std::nullopt /*not vectorized*/, S, UserTreeIdx,
- ReuseShuffleIndices);
- return;
- }
- } else {
- // Record the reuse of the tree node. FIXME, currently this is only used
- // to properly draw the graph rather than for the actual vectorization.
- E->UserTreeIndices.push_back(UserTreeIdx);
- LLVM_DEBUG(dbgs() << "SLP: Perfect diamond merge at " << *S.OpValue
- << ".\n");
- return;
- }
- }
-
// Check that none of the instructions in the bundle are already in the tree.
for (Value *V : VL) {
if ((!IsScatterVectorizeUserTE && !isa<Instruction>(V)) ||
@@ -9362,22 +9368,8 @@ public:
const BoUpSLP::TreeEntry *BoUpSLP::getOperandEntry(const TreeEntry *E,
unsigned Idx) const {
- Value *Op = E->getOperand(Idx).front();
- if (const TreeEntry *TE = getTreeEntry(Op)) {
- if (find_if(TE->UserTreeIndices, [&](const EdgeInfo &EI) {
- return EI.EdgeIdx == Idx && EI.UserTE == E;
- }) != TE->UserTreeIndices.end())
- return TE;
- auto MIt = MultiNodeScalars.find(Op);
- if (MIt != MultiNodeScalars.end()) {
- for (const TreeEntry *TE : MIt->second) {
- if (find_if(TE->UserTreeIndices, [&](const EdgeInfo &EI) {
- return EI.EdgeIdx == Idx && EI.UserTE == E;
- }) != TE->UserTreeIndices.end())
- return TE;
- }
- }
- }
+ if (const TreeEntry *VE = getMatchedVectorizedOperand(E, Idx))
+ return VE;
const auto *It =
find_if(VectorizableTree, [&](const std::unique_ptr<TreeEntry> &TE) {
return TE->isGather() &&
@@ -12521,10 +12513,9 @@ public:
}
};
-Value *BoUpSLP::vectorizeOperand(TreeEntry *E, unsigned NodeIdx,
- bool PostponedPHIs) {
- ValueList &VL = E->getOperand(NodeIdx);
- const unsigned VF = VL.size();
+BoUpSLP::TreeEntry *BoUpSLP::getMatchedVectorizedOperand(const TreeEntry *E,
+ unsigned NodeIdx) {
+ ArrayRef<Value *> VL = E->getOperand(NodeIdx);
InstructionsState S = getSameOpcode(VL, *TLI);
// Special processing for GEPs bundle, which may include non-gep values.
if (!S.getOpcode() && VL.front()->getType()->isPointerTy()) {
@@ -12532,109 +12523,113 @@ Value *BoUpSLP::vectorizeOperand(TreeEntry *E, unsigned NodeIdx,
if (It != VL.end())
S = getSameOpcode(*It, *TLI);
}
- if (S.getOpcode()) {
- auto CheckSameVE = [&](const TreeEntry *VE) {
- return VE->isSame(VL) &&
- (any_of(VE->UserTreeIndices,
- [E, NodeIdx](const EdgeInfo &EI) {
- return EI.UserTE == E && EI.EdgeIdx == NodeIdx;
- }) ||
- any_of(VectorizableTree,
- [E, NodeIdx, VE](const std::unique_ptr<TreeEntry> &TE) {
- return TE->isOperandGatherNode({E, NodeIdx}) &&
- VE->isSame(TE->Scalars);
- }));
+ if (!S.getOpcode())
+ return nullptr;
+ auto CheckSameVE = [&](const TreeEntry *VE) {
+ return VE->isSame(VL) &&
+ (any_of(VE->UserTreeIndices,
+ [E, NodeIdx](const EdgeInfo &EI) {
+ return EI.UserTE == E && EI.EdgeIdx == NodeIdx;
+ }) ||
+ any_of(VectorizableTree,
+ [E, NodeIdx, VE](const std::unique_ptr<TreeEntry> &TE) {
+ return TE->isOperandGatherNode(
+ {const_cast<TreeEntry *>(E), NodeIdx}) &&
+ VE->isSame(TE->Scalars);
+ }));
+ };
+ TreeEntry *VE = getTreeEntry(S.OpValue);
+ if (VE && CheckSameVE(VE))
+ return VE;
+ auto It = MultiNodeScalars.find(S.OpValue);
+ if (It != MultiNodeScalars.end()) {
+ auto *I = find_if(It->getSecond(), [&](const TreeEntry *TE) {
+ return TE != VE && CheckSameVE(TE);
+ });
+ if (I != It->getSecond().end())
+ return *I;
+ }
+ return nullptr;
+}
+
+Value *BoUpSLP::vectorizeOperand(TreeEntry *E, unsigned NodeIdx,
+ bool PostponedPHIs) {
+ ValueList &VL = E->getOperand(NodeIdx);
+ const unsigned VF = VL.size();
+ if (TreeEntry *VE = getMatchedVectorizedOperand(E, NodeIdx)) {
+ auto FinalShuffle = [&](Value *V, ArrayRef<int> Mask) {
+ // V may be affected by MinBWs.
+ // We want ShuffleInstructionBuilder to correctly support REVEC. The key
+ // factor is the number of elements, not their type.
+ Type *ScalarTy = cast<VectorType>(V->getType())->getElementType();
+ unsigned NumElements = getNumElements(VL.front()->getType());
+ ShuffleInstructionBuilder ShuffleBuilder(
+ NumElements != 1 ? FixedVectorType::get(ScalarTy, NumElements)
+ : ScalarTy,
+ Builder, *this);
+ ShuffleBuilder.add(V, Mask);
+ SmallVector<std::pair<const TreeEntry *, unsigned>> SubVectors(
+ E->CombinedEntriesWithIndices.size());
+ transform(E->CombinedEntriesWithIndices, SubVectors.begin(),
+ [&](const auto &P) {
+ return std::make_pair(VectorizableTree[P.first].get(),
+ P.second);
+ });
+ return ShuffleBuilder.finalize(std::nullopt, SubVectors);
};
- TreeEntry *VE = getTreeEntry(S.OpValue);
- bool IsSameVE = VE && CheckSameVE(VE);
- if (!IsSameVE) {
- auto It = MultiNodeScalars.find(S.OpValue);
- if (It != MultiNodeScalars.end()) {
- auto *I = find_if(It->getSecond(), [&](const TreeEntry *TE) {
- return TE != VE && CheckSameVE(TE);
- });
- if (I != It->getSecond().end()) {
- VE = *I;
- IsSameVE = true;
- }
- }
- }
- if (IsSameVE) {
- auto FinalShuffle = [&](Value *V, ArrayRef<int> Mask) {
- // V may be affected by MinBWs.
- // We want ShuffleInstructionBuilder to correctly support REVEC. The key
- // factor is the number of elements, not their type.
- Type *ScalarTy = cast<VectorType>(V->getType())->getElementType();
- unsigned NumElements = getNumElements(VL.front()->getType());
- ShuffleInstructionBuilder ShuffleBuilder(
- NumElements != 1 ? FixedVectorType::get(ScalarTy, NumElements)
- : ScalarTy,
- Builder, *this);
- ShuffleBuilder.add(V, Mask);
- SmallVector<std::pair<const TreeEntry *, unsigned>> SubVectors(
- E->CombinedEntriesWithIndices.size());
- transform(E->CombinedEntriesWithIndices, SubVectors.begin(),
- [&](const auto &P) {
- return std::make_pair(VectorizableTree[P.first].get(),
- P.second);
- });
- return ShuffleBuilder.finalize(std::nullopt, SubVectors);
- };
- Value *V = vectorizeTree(VE, PostponedPHIs);
- if (VF * getNumElements(VL[0]->getType()) !=
- cast<FixedVectorType>(V->getType())->getNumElements()) {
- if (!VE->ReuseShuffleIndices.empty()) {
- // Reshuffle to get only unique values.
- // If some of the scalars are duplicated in the vectorization
- // tree entry, we do not vectorize them but instead generate a
- // mask for the reuses. But if there are several users of the
- // same entry, they may have different vectorization factors.
- // This is especially important for PHI nodes. In this case, we
- // need to adapt the resulting instruction for the user
- // vectorization factor and have to reshuffle it again to take
- // only unique elements of the vector. Without this code the
- // function incorrectly returns reduced vector instruction with
- // the same elements, not with the unique ones.
-
- // block:
- // %phi = phi <2 x > { .., %entry} {%shuffle, %block}
- // %2 = shuffle <2 x > %phi, poison, <4 x > <1, 1, 0, 0>
- // ... (use %2)
- // %shuffle = shuffle <2 x> %2, poison, <2 x> {2, 0}
- // br %block
- SmallVector<int> Mask(VF, PoisonMaskElem);
- for (auto [I, V] : enumerate(VL)) {
- if (isa<PoisonValue>(V))
- continue;
- Mask[I] = VE->findLaneForValue(V);
- }
- V = FinalShuffle(V, Mask);
- } else {
- assert(VF < cast<FixedVectorType>(V->getType())->getNumElements() &&
- "Expected vectorization factor less "
- "than original vector size.");
- SmallVector<int> UniformMask(VF, 0);
- std::iota(UniformMask.begin(), UniformMask.end(), 0);
- V = FinalShuffle(V, UniformMask);
+ Value *V = vectorizeTree(VE, PostponedPHIs);
+ if (VF * getNumElements(VL[0]->getType()) !=
+ cast<FixedVectorType>(V->getType())->getNumElements()) {
+ if (!VE->ReuseShuffleIndices.empty()) {
+ // Reshuffle to get only unique values.
+ // If some of the scalars are duplicated in the vectorization
+ // tree entry, we do not vectorize them but instead generate a
+ // mask for the reuses. But if there are several users of the
+ // same entry, they may have different vectorization factors.
+ // This is especially important for PHI nodes. In this case, we
+ // need to adapt the resulting instruction for the user
+ // vectorization factor and have to reshuffle it again to take
+ // only unique elements of the vector. Without this code the
+ // function incorrectly returns reduced vector instruction with
+ // the same elements, not with the unique ones.
+
+ // block:
+ // %phi = phi <2 x > { .., %entry} {%shuffle, %block}
+ // %2 = shuffle <2 x > %phi, poison, <4 x > <1, 1, 0, 0>
+ // ... (use %2)
+ // %shuffle = shuffle <2 x> %2, poison, <2 x> {2, 0}
+ // br %block
+ SmallVector<int> Mask(VF, PoisonMaskElem);
+ for (auto [I, V] : enumerate(VL)) {
+ if (isa<PoisonValue>(V))
+ continue;
+ Mask[I] = VE->findLaneForValue(V);
}
- }
- // Need to update the operand gather node, if actually the operand is not a
- // vectorized node, but the buildvector/gather node, which matches one of
- // the vectorized nodes.
- if (find_if(VE->UserTreeIndices, [&](const EdgeInfo &EI) {
- return EI.UserTE == E && EI.EdgeIdx == NodeIdx;
- }) == VE->UserTreeIndices.end()) {
- auto *It = find_if(
- VectorizableTree, [&](const std::unique_ptr<TreeEntry> &TE) {
- return TE->isGather() &&
- TE->UserTreeIndices.front().UserTE == E &&
- TE->UserTreeIndices.front().EdgeIdx == NodeIdx;
- });
- assert(It != VectorizableTree.end() && "Expected gather node operand.");
- (*It)->VectorizedValue = V;
- }
- return V;
+ V = FinalShuffle(V, Mask);
+ } else {
+ assert(VF < cast<FixedVectorType>(V->getType())->getNumElements() &&
+ "Expected vectorization factor less "
+ "than original vector size.");
+ SmallVector<int> UniformMask(VF, 0);
+ std::iota(UniformMask.begin(), UniformMask.end(), 0);
+ V = FinalShuffle(V, UniformMask);
+ }
+ }
+ // Need to update the operand gather node, if actually the operand is not a
+ // vectorized node, but the buildvector/gather node, which matches one of
+ // the vectorized nodes.
+ if (find_if(VE->UserTreeIndices, [&](const EdgeInfo &EI) {
+ return EI.UserTE == E && EI.EdgeIdx == NodeIdx;
+ }) == VE->UserTreeIndices.end()) {
+ auto *It =
+ find_if(VectorizableTree, [&](const std::unique_ptr<TreeEntry> &TE) {
+ return TE->isGather() && TE->UserTreeIndices.front().UserTE == E &&
+ TE->UserTreeIndices.front().EdgeIdx == NodeIdx;
+ });
+ assert(It != VectorizableTree.end() && "Expected gather node operand.");
+ (*It)->VectorizedValue = V;
}
+ return V;
}
// Find the corresponding gather entry and vectorize it.
| [
{
"file": "llvm/test/Transforms/SLPVectorizer/X86/multi-nodes-bv-vectorized.ll",
"commands": [
"opt -passes=slp-vectorizer -S -mtriple=x86_64-unknown-linux-gnu < %s"
],
"tests": [
{
"test_name": "test",
"test_body": "define void @test(ptr %p) {\nentry:\n %conv548.2.i.13 = zext i32 0 to i64\n %and551.2.i.13 = and i64 0, %conv548.2.i.13\n %conv548.3.i.13 = zext i32 0 to i64\n %and551.3.i.13 = and i64 0, %conv548.3.i.13\n %0 = trunc i64 %and551.2.i.13 to i32\n %conv54.2.i.14 = and i32 %0, 0\n %conv548.2.i.14 = zext i32 %conv54.2.i.14 to i64\n %and551.2.i.14 = and i64 %and551.2.i.13, %conv548.2.i.14\n %1 = trunc i64 %and551.3.i.13 to i32\n %conv54.3.i.14 = and i32 %1, 0\n %conv548.3.i.14 = zext i32 %conv54.3.i.14 to i64\n %and551.3.i.14 = and i64 %and551.3.i.13, %conv548.3.i.14\n %and551.2.i.15 = and i64 %and551.2.i.14, 0\n %and551.3.i.15 = and i64 %and551.3.i.14, 0\n %and551.2.i.16 = and i64 %and551.2.i.15, 0\n %and551.3.i.16 = and i64 %and551.3.i.15, 0\n %and551.2.i.17 = and i64 %and551.2.i.16, 0\n %and551.3.i.17 = and i64 %and551.3.i.16, 0\n %and551.2.i.18 = and i64 %and551.2.i.17, 0\n %and551.3.i.18 = and i64 %and551.3.i.17, 0\n %and551.2.i.19 = and i64 %and551.2.i.18, 0\n %and551.3.i.19 = and i64 %and551.3.i.18, 0\n %and551.2.i.20 = and i64 %and551.2.i.19, 0\n %and551.3.i.20 = and i64 %and551.3.i.19, 0\n %and551.2.i.21 = and i64 %and551.2.i.20, 0\n %and551.3.i.21 = and i64 %and551.3.i.20, 0\n %gep1 = getelementptr inbounds i8, ptr %p, i64 16\n %gep2 = getelementptr inbounds i8, ptr %p, i64 24\n store i64 %and551.2.i.21, ptr %gep1, align 16\n store i64 %and551.3.i.21, ptr %gep2, align 8\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[SLPVectorizer] Assertion `CastInst::castIsValid(opc, C, Ty) && \"Invalid constantexpr cast!\"' failed.",
"body": "Reproducer: https://godbolt.org/z/PeoMv3Tsn\r\n```\r\n; bin/opt -passes=slp-vectorizer reduced.ll -S\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine void @main(ptr %p) {\r\nentry:\r\n %conv548.2.i.13 = zext i32 0 to i64\r\n %and551.2.i.13 = and i64 0, %conv548.2.i.13\r\n %conv548.3.i.13 = zext i32 0 to i64\r\n %and551.3.i.13 = and i64 0, %conv548.3.i.13\r\n %0 = trunc i64 %and551.2.i.13 to i32\r\n %conv54.2.i.14 = and i32 %0, 0\r\n %conv548.2.i.14 = zext i32 %conv54.2.i.14 to i64\r\n %and551.2.i.14 = and i64 %and551.2.i.13, %conv548.2.i.14\r\n %1 = trunc i64 %and551.3.i.13 to i32\r\n %conv54.3.i.14 = and i32 %1, 0\r\n %conv548.3.i.14 = zext i32 %conv54.3.i.14 to i64\r\n %and551.3.i.14 = and i64 %and551.3.i.13, %conv548.3.i.14\r\n %and551.2.i.15 = and i64 %and551.2.i.14, 0\r\n %and551.3.i.15 = and i64 %and551.3.i.14, 0\r\n %and551.2.i.16 = and i64 %and551.2.i.15, 0\r\n %and551.3.i.16 = and i64 %and551.3.i.15, 0\r\n %and551.2.i.17 = and i64 %and551.2.i.16, 0\r\n %and551.3.i.17 = and i64 %and551.3.i.16, 0\r\n %and551.2.i.18 = and i64 %and551.2.i.17, 0\r\n %and551.3.i.18 = and i64 %and551.3.i.17, 0\r\n %and551.2.i.19 = and i64 %and551.2.i.18, 0\r\n %and551.3.i.19 = and i64 %and551.3.i.18, 0\r\n %and551.2.i.20 = and i64 %and551.2.i.19, 0\r\n %and551.3.i.20 = and i64 %and551.3.i.19, 0\r\n %and551.2.i.21 = and i64 %and551.2.i.20, 0\r\n %and551.3.i.21 = and i64 %and551.3.i.20, 0\r\n %gep1 = getelementptr inbounds i8, ptr %p, i64 16\r\n %gep2 = getelementptr inbounds i8, ptr %p, i64 24\r\n store i64 %and551.2.i.21, ptr %gep1, align 16\r\n store i64 %and551.3.i.21, ptr %gep2, align 8\r\n ret void\r\n}\r\n```\r\n```\r\nopt: /home/dtcxzyw/WorkSpace/Projects/compilers/llvm-project/llvm/lib/IR/Constants.cpp:2202: static llvm::Constant* llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*, llvm::Type*, bool): Assertion `CastInst::castIsValid(opc, C, Ty) && \"Invalid constantexpr cast!\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: bin/opt -passes=slp-vectorizer reduced.ll -S\r\n1. Running pass \"function(slp-vectorizer)\" on module \"reduced.ll\"\r\n2. Running pass \"slp-vectorizer\" on function \"main\"\r\n #0 0x00007c5d3e8138d2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x2138d2)\r\n #1 0x00007c5d3e81079f llvm::sys::RunSignalHandlers() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMSupport.so.20.0git+0x21079f)\r\n #2 0x00007c5d3e8108e5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007c5d3e242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007c5d3e2969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007c5d3e2969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007c5d3e2969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007c5d3e242476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007c5d3e2287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007c5d3e22871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007c5d3e239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00007c5d36fb0c4d llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*, llvm::Type*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x1b0c4d)\r\n#12 0x00007c5d394573b5 llvm::IRBuilderBase::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x573b5)\r\n#13 0x00007c5d395ab173 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1ab173)\r\n#14 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#15 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#16 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#17 0x00007c5d395a7cbb llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7cbb)\r\n#18 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#19 0x00007c5d395a7a41 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a41)\r\n#20 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#21 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#22 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#23 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#24 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#25 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#26 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#27 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#28 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#29 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#30 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#31 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#32 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#33 0x00007c5d395a7a13 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a7a13)\r\n#34 0x00007c5d395acf1e llvm::slpvectorizer::BoUpSLP::vectorizeOperand(llvm::slpvectorizer::BoUpSLP::TreeEntry*, unsigned int, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1acf1e)\r\n#35 0x00007c5d395a8f65 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::slpvectorizer::BoUpSLP::TreeEntry*, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1a8f65)\r\n#36 0x00007c5d395ae278 llvm::slpvectorizer::BoUpSLP::vectorizeTree(llvm::MapVector<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u>, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, llvm::SmallVector<std::pair<llvm::Value*, llvm::SmallVector<llvm::Instruction*, 2u>>, 0u>> const&, llvm::SmallVectorImpl<std::pair<llvm::Value*, llvm::Value*>>&, llvm::Instruction*) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1ae278)\r\n#37 0x00007c5d395b207c llvm::slpvectorizer::BoUpSLP::vectorizeTree() (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1b207c)\r\n#38 0x00007c5d395c7cac llvm::SLPVectorizerPass::vectorizeStoreChain(llvm::ArrayRef<llvm::Value*>, llvm::slpvectorizer::BoUpSLP&, unsigned int, unsigned int, unsigned int&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1c7cac)\r\n#39 0x00007c5d395c9637 llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&)::'lambda'(std::set<std::pair<unsigned int, int>, llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&)::StoreDistCompare, std::allocator<std::pair<unsigned int, int>>> const&)::operator()(std::set<std::pair<unsigned int, int>, llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&)::StoreDistCompare, std::allocator<std::pair<unsigned int, int>>> const&) const SLPVectorizer.cpp:0:0\r\n#40 0x00007c5d395cb92c llvm::SLPVectorizerPass::vectorizeStores(llvm::ArrayRef<llvm::StoreInst*>, llvm::slpvectorizer::BoUpSLP&, llvm::DenseSet<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, llvm::DenseMapInfo<std::tuple<llvm::Value*, llvm::Value*, llvm::Value*, llvm::Value*, unsigned int>, void>>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1cb92c)\r\n#41 0x00007c5d395cc20f llvm::SLPVectorizerPass::vectorizeStoreChains(llvm::slpvectorizer::BoUpSLP&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1cc20f)\r\n#42 0x00007c5d395cd30f llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1cd30f)\r\n#43 0x00007c5d395cdf86 llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMVectorize.so.20.0git+0x1cdf86)\r\n#44 0x00007c5d39ed4015 llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMPasses.so.20.0git+0xd4015)\r\n#45 0x00007c5d371546ed llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x3546ed)\r\n#46 0x00007c5d3d4d7f35 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.20.0git+0xd7f35)\r\n#47 0x00007c5d37153256 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x353256)\r\n#48 0x00007c5d3d4d88f5 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMX86CodeGen.so.20.0git+0xd88f5)\r\n#49 0x00007c5d3715121a llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/../lib/libLLVMCore.so.20.0git+0x35121a)\r\n#50 0x00007c5d3eb12fc7 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x2cfc7)\r\n#51 0x00007c5d3eb1e962 optMain (/home/dtcxzyw/WorkSpace/Projects/compilers/LLVM/llvm-build/bin/../lib/libLLVMOptDriver.so.20.0git+0x38962)\r\n#52 0x00007c5d3e229d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#53 0x00007c5d3e229e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#54 0x00007c5d3e229e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#55 0x00005949b291d095 _start (bin/opt+0x1095)\r\nAborted (core dumped)\r\n```\r\n\r\ncc @alexey-bataev ",
"author": "dtcxzyw",
"labels": [
"llvm:SLPVectorizer",
"crash-on-valid"
],
"comments": [
{
"author": "dtcxzyw",
"body": "Related PR: https://github.com/llvm/llvm-project/pull/103216\r\n"
}
]
} | true | null |
87378 | https://github.com/llvm/llvm-project/issues/87378 | crash | d8db13edd60b195e6692deb04d63e633319e486a | 2024-04-02T17:38:53 | [
"llvm/test/Transforms/LoopVectorize"
] | {
"fix_commit": "6261c53c6f9c82bfca5df2ed5917876d748ed079",
"components": [
"LoopVectorize"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": [
[
913,
918
],
[
920,
928
],
[
1016,
1021
],
[
1221,
1226
]
],
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": [
[
175,
181
]
],
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": [
"GEPFlagsTy",
"VPInstruction",
"VPRecipeWithIRFlags"
],
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": [
"createOr",
"createSelect"
],
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 6261c53c6f9c82bfca5df2ed5917876d748ed079
Author: Florian Hahn <[email protected]>
Date: Tue Apr 2 21:48:35 2024 +0100
[VPlan] Make sure OR VPInstructions are treated as disjoint ops.
Make sure that VPInstructions with OR opcodes are properly registered as
disjoint ops.
Fixes https://github.com/llvm/llvm-project/issues/87378.
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
index 5d03b66b0ce3..ebca2d855a46 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h
@@ -175,7 +175,10 @@ public:
VPValue *createOr(VPValue *LHS, VPValue *RHS, DebugLoc DL = {},
const Twine &Name = "") {
- return createInstruction(Instruction::BinaryOps::Or, {LHS, RHS}, DL, Name);
+
+ return tryInsertInstruction(new VPInstruction(
+ Instruction::BinaryOps::Or, {LHS, RHS},
+ VPRecipeWithIRFlags::DisjointFlagsTy(false), DL, Name));
}
VPValue *createSelect(VPValue *Cond, VPValue *TrueVal, VPValue *FalseVal,
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 3baca43f7276..707a826ecdc2 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -913,6 +913,11 @@ public:
WrapFlagsTy(bool HasNUW, bool HasNSW) : HasNUW(HasNUW), HasNSW(HasNSW) {}
};
+ struct DisjointFlagsTy {
+ char IsDisjoint : 1;
+ DisjointFlagsTy(bool IsDisjoint) : IsDisjoint(IsDisjoint) {}
+ };
+
protected:
struct GEPFlagsTy {
char IsInBounds : 1;
@@ -920,9 +925,6 @@ protected:
};
private:
- struct DisjointFlagsTy {
- char IsDisjoint : 1;
- };
struct ExactFlagsTy {
char IsExact : 1;
};
@@ -1016,6 +1018,12 @@ public:
: VPSingleDefRecipe(SC, Operands, DL), OpType(OperationType::FPMathOp),
FMFs(FMFs) {}
+ template <typename IterT>
+ VPRecipeWithIRFlags(const unsigned char SC, IterT Operands,
+ DisjointFlagsTy DisjointFlags, DebugLoc DL = {})
+ : VPSingleDefRecipe(SC, Operands, DL), OpType(OperationType::DisjointOp),
+ DisjointFlags(DisjointFlags) {}
+
protected:
template <typename IterT>
VPRecipeWithIRFlags(const unsigned char SC, IterT Operands,
@@ -1221,6 +1229,14 @@ public:
: VPRecipeWithIRFlags(VPDef::VPInstructionSC, Operands, WrapFlags, DL),
Opcode(Opcode), Name(Name.str()) {}
+ VPInstruction(unsigned Opcode, std::initializer_list<VPValue *> Operands,
+ DisjointFlagsTy DisjointFlag, DebugLoc DL = {},
+ const Twine &Name = "")
+ : VPRecipeWithIRFlags(VPDef::VPInstructionSC, Operands, DisjointFlag, DL),
+ Opcode(Opcode), Name(Name.str()) {
+ assert(Opcode == Instruction::Or && "only OR opcodes can be disjoint");
+ }
+
VPInstruction(unsigned Opcode, std::initializer_list<VPValue *> Operands,
FastMathFlags FMFs, DebugLoc DL = {}, const Twine &Name = "");
| [
{
"file": "llvm/test/Transforms/LoopVectorize/pr87378-vpinstruction-or-drop-poison-generating-flags.ll",
"commands": [
"opt -p loop-vectorize -mattr=\"+v\" -S %s"
],
"tests": [
{
"test_name": "<module>",
"test_body": "\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\n; Test case for https://github.com/llvm/llvm-project/issues/87378.\ndefine void @pr87378_vpinstruction_or_drop_poison_generating_flags(ptr %arg, i64 %a, i64 %b, i64 %c) {\n;\nentry:\n br label %loop.header\n\nloop.header:\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n %c.1 = icmp ule i64 %iv, %a\n br i1 %c.1, label %then.1, label %else.1\n\nthen.1:\n %c.2 = icmp ule i64 %iv, %b\n br i1 %c.2, label %else.1, label %merge\n\nelse.1:\n %c.3 = icmp ule i64 %iv, %c\n br i1 %c.3, label %then.2, label %loop.latch\n\nthen.2:\n br label %merge\n\nmerge:\n %idx = phi i64 [ poison, %then.1 ], [ %iv, %then.2 ]\n %getelementptr = getelementptr i16, ptr %arg, i64 %idx\n store i16 0, ptr %getelementptr, align 2\n br label %loop.latch\n\nloop.latch:\n %iv.next = add i64 %iv, 1\n %icmp = icmp eq i64 %iv, 1000\n br i1 %icmp, label %exit, label %loop.header\n\nexit:\n ret void\n}\n;.\n;.",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[LoopVectorize] Assertion `OpType == OperationType::DisjointOp && \"recipe cannot have a disjoing flag\"' failed.",
"body": "Reduced LLVM IR:\r\n``` llvm ir\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine i32 @main() #0 {\r\nentry:\r\n br label %for.body300.us.us.i\r\n\r\nfor.body300.us.us.i: ; preds = %if.end559.us.us.i, %entry\r\n br label %for.body326.us.us.i\r\n\r\nfor.body326.us.us.i: ; preds = %if.end559.us.us.i, %for.body300.us.us.i\r\n %indvars.iv18 = phi i64 [ 0, %for.body300.us.us.i ], [ %indvars.iv.next19, %if.end559.us.us.i ]\r\n br i1 false, label %cond.end339.us.us.i, label %cond.end354.us.us.i\r\n\r\ncond.end339.us.us.i: ; preds = %for.body326.us.us.i\r\n br i1 false, label %cond.end339.us.us.i.if.then357.us.us.i_crit_edge, label %cond.end339.us.us.i.cond.end354.us.us.i_crit_edge\r\n\r\ncond.end339.us.us.i.cond.end354.us.us.i_crit_edge: ; preds = %cond.end339.us.us.i\r\n br label %cond.end354.us.us.i\r\n\r\ncond.end339.us.us.i.if.then357.us.us.i_crit_edge: ; preds = %cond.end339.us.us.i\r\n br label %if.then357.us.us.i\r\n\r\ncond.end354.us.us.i: ; preds = %cond.end339.us.us.i.cond.end354.us.us.i_crit_edge, %for.body326.us.us.i\r\n br i1 false, label %cond.end354.us.us.i.if.then357.us.us.i_crit_edge, label %if.end559.us.us.i\r\n\r\ncond.end354.us.us.i.if.then357.us.us.i_crit_edge: ; preds = %cond.end354.us.us.i\r\n br label %if.then357.us.us.i\r\n\r\nif.then357.us.us.i: ; preds = %cond.end354.us.us.i.if.then357.us.us.i_crit_edge, %cond.end339.us.us.i.if.then357.us.us.i_crit_edge\r\n %.pre1143.i7 = phi i64 [ poison, %cond.end339.us.us.i.if.then357.us.us.i_crit_edge ], [ %indvars.iv18, %cond.end354.us.us.i.if.then357.us.us.i_crit_edge ]\r\n %arrayidx429.us.us.i = getelementptr [14 x i16], ptr null, i64 0, i64 %.pre1143.i7\r\n store i16 0, ptr %arrayidx429.us.us.i, align 2\r\n br label %if.end559.us.us.i\r\n\r\nif.end559.us.us.i: ; preds = %if.then357.us.us.i, %cond.end354.us.us.i\r\n %indvars.iv.next19 = add i64 %indvars.iv18, 1\r\n %0 = trunc i64 %indvars.iv18 to i32\r\n %cmp323.us.us.i = icmp slt i32 %0, 1\r\n br i1 %cmp323.us.us.i, label %for.body326.us.us.i, label %for.body300.us.us.i\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl256b,+zvl32b,+zvl64b,-e,-experimental-smmpm,-experimental-smnpm,-experimental-ssnpm,-experimental-sspm,-experimental-ssqosid,-experimental-supm,-experimental-zaamo,-experimental-zabha,-experimental-zalasr,-experimental-zalrsc,-experimental-zcmop,-experimental-zfbfmin,-experimental-zicfilp,-experimental-zicfiss,-experimental-zimop,-experimental-ztso,-experimental-zvfbfmin,-experimental-zvfbfwma,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smepmp,-ssaia,-ssccptr,-sscofpmf,-sscounterenw,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-za128rs,-za64rs,-zacas,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmp,-zcmt,-zdinx,-zfa,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-zvbb,-zvbc,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\n```\r\n\r\nBacktrace:\r\n```\r\nopt: /scratch/tc-testing/tc-apr-2/llvm/llvm/lib/Transforms/Vectorize/VPlan.h:1131: bool llvm::VPRecipeWithIRFlags::isDisjoint() const: Assertion `OpType == OperationType::DisjointOp && \"recipe cannot have a disjoing flag\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt reduced.ll --passes=loop-vectorize\r\n #0 0x00005bd204995b60 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2d84b60)\r\n #1 0x00005bd204992f6f llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2d81f6f)\r\n #2 0x00005bd2049930c5 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x000076eef1a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x000076eef1a969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x000076eef1a969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x000076eef1a969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x000076eef1a42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x000076eef1a287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x000076eef1a2871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x000076eef1a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00005bd203b25ea2 llvm::VPlanTransforms::dropPoisonGeneratingRecipes(llvm::VPlan&, llvm::function_ref<bool (llvm::BasicBlock*)>)::'lambda'(llvm::VPRecipeBase*)::operator()(llvm::VPRecipeBase*) const VPlanTransforms.cpp:0:0\r\n#12 0x00005bd203b2c77d llvm::VPlanTransforms::dropPoisonGeneratingRecipes(llvm::VPlan&, llvm::function_ref<bool (llvm::BasicBlock*)>) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1f1b77d)\r\n#13 0x00005bd203a05435 llvm::LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(llvm::VFRange&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1df4435)\r\n#14 0x00005bd203a05c9e llvm::LoopVectorizationPlanner::buildVPlansWithVPRecipes(llvm::ElementCount, llvm::ElementCount) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1df4c9e)\r\n#15 0x00005bd203a0c319 llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1dfb319)\r\n#16 0x00005bd203a0f8a9 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1dfe8a9)\r\n#17 0x00005bd203a1273e llvm::LoopVectorizePass::runImpl(llvm::Function&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::BlockFrequencyInfo*, llvm::TargetLibraryInfo*, llvm::DemandedBits&, llvm::AssumptionCache&, llvm::LoopAccessInfoManager&, llvm::OptimizationRemarkEmitter&, llvm::ProfileSummaryInfo*) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1e0173e)\r\n#18 0x00005bd203a1388d llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x1e0288d)\r\n#19 0x00005bd20291a276 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd09276)\r\n#20 0x00005bd2047bc141 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2bab141)\r\n#21 0x00005bd202911bd6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd00bd6)\r\n#22 0x00005bd2047bae3b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2ba9e3b)\r\n#23 0x00005bd202919dc6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0xd08dc6)\r\n#24 0x00005bd2047b8cb1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x2ba7cb1)\r\n#25 0x00005bd202193ce5 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x582ce5)\r\n#26 0x00005bd202186316 optMain (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x575316)\r\n#27 0x000076eef1a29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#28 0x000076eef1a29e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#29 0x000076eef1a29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#30 0x00005bd20217bf95 _start (/scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt+0x56af95)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-apr-2/build-rv64gcv/build-llvm-linux/bin/opt reduced.l\r\n```\r\n\r\nGodbolt: https://godbolt.org/z/jj39h3z7M\r\n\r\nMinor spelling nit: `disjoing -> disjoint`\r\n\r\nFound via fuzzer.\r\n\r\nLikely caused/exposed by https://github.com/llvm/llvm-project/commit/6ef829941b38f7e8a28c4cba1ff25cd0ae9f7d3d https://github.com/llvm/llvm-project/pull/83821 @fhahn ",
"author": "patrick-rivos",
"labels": [
"vectorizers",
"crash"
],
"comments": []
} | true | null |
91417 | https://github.com/llvm/llvm-project/issues/91417 | miscompilation | d9507a3e10d1750d88dd518c14b9a9a62b9eefcd | 2024-05-08T01:40:37 | [
"llvm/test/Transforms/Reassociate"
] | {
"fix_commit": "645fb04a3389e69801d401e669eae9ee42d70217",
"components": [
"Reassociate"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": [
[
302,
399
],
[
475,
481
],
[
490,
497
],
[
509,
515
],
[
518,
525
],
[
528,
534
],
[
562,
568
],
[
625,
634
],
[
642,
648
],
[
1188,
1195
],
[
2368,
2374
]
],
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": [
"CarmichaelShift",
"IncorporateWeight",
"LinearizeExprTree",
"LowerNegateToMultiply",
"ReassociatePass::ReassociateExpression",
"ReassociatePass::RemoveFactorFromExpression"
],
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 645fb04a3389e69801d401e669eae9ee42d70217
Author: Yingwei Zheng <[email protected]>
Date: Sat Jun 8 22:28:56 2024 +0800
[Reassociate] Use uint64_t for repeat count (#94232)
This patch relands #91469 and uses `uint64_t` for repeat count to avoid
a miscompilation caused by overflow
https://github.com/llvm/llvm-project/pull/91469#discussion_r1623925158.
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp
index c73d7c8d83be..f36e21b296bd 100644
--- a/llvm/lib/Transforms/Scalar/Reassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp
@@ -302,98 +302,7 @@ static BinaryOperator *LowerNegateToMultiply(Instruction *Neg) {
return Res;
}
-/// Returns k such that lambda(2^Bitwidth) = 2^k, where lambda is the Carmichael
-/// function. This means that x^(2^k) === 1 mod 2^Bitwidth for
-/// every odd x, i.e. x^(2^k) = 1 for every odd x in Bitwidth-bit arithmetic.
-/// Note that 0 <= k < Bitwidth, and if Bitwidth > 3 then x^(2^k) = 0 for every
-/// even x in Bitwidth-bit arithmetic.
-static unsigned CarmichaelShift(unsigned Bitwidth) {
- if (Bitwidth < 3)
- return Bitwidth - 1;
- return Bitwidth - 2;
-}
-
-/// Add the extra weight 'RHS' to the existing weight 'LHS',
-/// reducing the combined weight using any special properties of the operation.
-/// The existing weight LHS represents the computation X op X op ... op X where
-/// X occurs LHS times. The combined weight represents X op X op ... op X with
-/// X occurring LHS + RHS times. If op is "Xor" for example then the combined
-/// operation is equivalent to X if LHS + RHS is odd, or 0 if LHS + RHS is even;
-/// the routine returns 1 in LHS in the first case, and 0 in LHS in the second.
-static void IncorporateWeight(APInt &LHS, const APInt &RHS, unsigned Opcode) {
- // If we were working with infinite precision arithmetic then the combined
- // weight would be LHS + RHS. But we are using finite precision arithmetic,
- // and the APInt sum LHS + RHS may not be correct if it wraps (it is correct
- // for nilpotent operations and addition, but not for idempotent operations
- // and multiplication), so it is important to correctly reduce the combined
- // weight back into range if wrapping would be wrong.
-
- // If RHS is zero then the weight didn't change.
- if (RHS.isMinValue())
- return;
- // If LHS is zero then the combined weight is RHS.
- if (LHS.isMinValue()) {
- LHS = RHS;
- return;
- }
- // From this point on we know that neither LHS nor RHS is zero.
-
- if (Instruction::isIdempotent(Opcode)) {
- // Idempotent means X op X === X, so any non-zero weight is equivalent to a
- // weight of 1. Keeping weights at zero or one also means that wrapping is
- // not a problem.
- assert(LHS == 1 && RHS == 1 && "Weights not reduced!");
- return; // Return a weight of 1.
- }
- if (Instruction::isNilpotent(Opcode)) {
- // Nilpotent means X op X === 0, so reduce weights modulo 2.
- assert(LHS == 1 && RHS == 1 && "Weights not reduced!");
- LHS = 0; // 1 + 1 === 0 modulo 2.
- return;
- }
- if (Opcode == Instruction::Add || Opcode == Instruction::FAdd) {
- // TODO: Reduce the weight by exploiting nsw/nuw?
- LHS += RHS;
- return;
- }
-
- assert((Opcode == Instruction::Mul || Opcode == Instruction::FMul) &&
- "Unknown associative operation!");
- unsigned Bitwidth = LHS.getBitWidth();
- // If CM is the Carmichael number then a weight W satisfying W >= CM+Bitwidth
- // can be replaced with W-CM. That's because x^W=x^(W-CM) for every Bitwidth
- // bit number x, since either x is odd in which case x^CM = 1, or x is even in
- // which case both x^W and x^(W - CM) are zero. By subtracting off multiples
- // of CM like this weights can always be reduced to the range [0, CM+Bitwidth)
- // which by a happy accident means that they can always be represented using
- // Bitwidth bits.
- // TODO: Reduce the weight by exploiting nsw/nuw? (Could do much better than
- // the Carmichael number).
- if (Bitwidth > 3) {
- /// CM - The value of Carmichael's lambda function.
- APInt CM = APInt::getOneBitSet(Bitwidth, CarmichaelShift(Bitwidth));
- // Any weight W >= Threshold can be replaced with W - CM.
- APInt Threshold = CM + Bitwidth;
- assert(LHS.ult(Threshold) && RHS.ult(Threshold) && "Weights not reduced!");
- // For Bitwidth 4 or more the following sum does not overflow.
- LHS += RHS;
- while (LHS.uge(Threshold))
- LHS -= CM;
- } else {
- // To avoid problems with overflow do everything the same as above but using
- // a larger type.
- unsigned CM = 1U << CarmichaelShift(Bitwidth);
- unsigned Threshold = CM + Bitwidth;
- assert(LHS.getZExtValue() < Threshold && RHS.getZExtValue() < Threshold &&
- "Weights not reduced!");
- unsigned Total = LHS.getZExtValue() + RHS.getZExtValue();
- while (Total >= Threshold)
- Total -= CM;
- LHS = Total;
- }
-}
-
-using RepeatedValue = std::pair<Value*, APInt>;
+using RepeatedValue = std::pair<Value *, uint64_t>;
/// Given an associative binary expression, return the leaf
/// nodes in Ops along with their weights (how many times the leaf occurs). The
@@ -475,7 +384,6 @@ static bool LinearizeExprTree(Instruction *I,
assert((isa<UnaryOperator>(I) || isa<BinaryOperator>(I)) &&
"Expected a UnaryOperator or BinaryOperator!");
LLVM_DEBUG(dbgs() << "LINEARIZE: " << *I << '\n');
- unsigned Bitwidth = I->getType()->getScalarType()->getPrimitiveSizeInBits();
unsigned Opcode = I->getOpcode();
assert(I->isAssociative() && I->isCommutative() &&
"Expected an associative and commutative operation!");
@@ -490,8 +398,8 @@ static bool LinearizeExprTree(Instruction *I,
// with their weights, representing a certain number of paths to the operator.
// If an operator occurs in the worklist multiple times then we found multiple
// ways to get to it.
- SmallVector<std::pair<Instruction*, APInt>, 8> Worklist; // (Op, Weight)
- Worklist.push_back(std::make_pair(I, APInt(Bitwidth, 1)));
+ SmallVector<std::pair<Instruction *, uint64_t>, 8> Worklist; // (Op, Weight)
+ Worklist.push_back(std::make_pair(I, 1));
bool Changed = false;
// Leaves of the expression are values that either aren't the right kind of
@@ -509,7 +417,7 @@ static bool LinearizeExprTree(Instruction *I,
// Leaves - Keeps track of the set of putative leaves as well as the number of
// paths to each leaf seen so far.
- using LeafMap = DenseMap<Value *, APInt>;
+ using LeafMap = DenseMap<Value *, uint64_t>;
LeafMap Leaves; // Leaf -> Total weight so far.
SmallVector<Value *, 8> LeafOrder; // Ensure deterministic leaf output order.
const DataLayout DL = I->getModule()->getDataLayout();
@@ -518,8 +426,8 @@ static bool LinearizeExprTree(Instruction *I,
SmallPtrSet<Value *, 8> Visited; // For checking the iteration scheme.
#endif
while (!Worklist.empty()) {
- std::pair<Instruction*, APInt> P = Worklist.pop_back_val();
- I = P.first; // We examine the operands of this binary operator.
+ // We examine the operands of this binary operator.
+ auto [I, Weight] = Worklist.pop_back_val();
if (isa<OverflowingBinaryOperator>(I)) {
Flags.HasNUW &= I->hasNoUnsignedWrap();
@@ -528,7 +436,6 @@ static bool LinearizeExprTree(Instruction *I,
for (unsigned OpIdx = 0; OpIdx < I->getNumOperands(); ++OpIdx) { // Visit operands.
Value *Op = I->getOperand(OpIdx);
- APInt Weight = P.second; // Number of paths to this operand.
LLVM_DEBUG(dbgs() << "OPERAND: " << *Op << " (" << Weight << ")\n");
assert(!Op->use_empty() && "No uses, so how did we get to it?!");
@@ -562,7 +469,8 @@ static bool LinearizeExprTree(Instruction *I,
"In leaf map but not visited!");
// Update the number of paths to the leaf.
- IncorporateWeight(It->second, Weight, Opcode);
+ It->second += Weight;
+ assert(It->second >= Weight && "Weight overflows");
// If we still have uses that are not accounted for by the expression
// then it is not safe to modify the value.
@@ -625,10 +533,7 @@ static bool LinearizeExprTree(Instruction *I,
// Node initially thought to be a leaf wasn't.
continue;
assert(!isReassociableOp(V, Opcode) && "Shouldn't be a leaf!");
- APInt Weight = It->second;
- if (Weight.isMinValue())
- // Leaf already output or weight reduction eliminated it.
- continue;
+ uint64_t Weight = It->second;
// Ensure the leaf is only output once.
It->second = 0;
Ops.push_back(std::make_pair(V, Weight));
@@ -642,7 +547,7 @@ static bool LinearizeExprTree(Instruction *I,
if (Ops.empty()) {
Constant *Identity = ConstantExpr::getBinOpIdentity(Opcode, I->getType());
assert(Identity && "Associative operation without identity!");
- Ops.emplace_back(Identity, APInt(Bitwidth, 1));
+ Ops.emplace_back(Identity, 1);
}
return Changed;
@@ -1188,8 +1093,7 @@ Value *ReassociatePass::RemoveFactorFromExpression(Value *V, Value *Factor) {
Factors.reserve(Tree.size());
for (unsigned i = 0, e = Tree.size(); i != e; ++i) {
RepeatedValue E = Tree[i];
- Factors.append(E.second.getZExtValue(),
- ValueEntry(getRank(E.first), E.first));
+ Factors.append(E.second, ValueEntry(getRank(E.first), E.first));
}
bool FoundFactor = false;
@@ -2368,7 +2272,7 @@ void ReassociatePass::ReassociateExpression(BinaryOperator *I) {
SmallVector<ValueEntry, 8> Ops;
Ops.reserve(Tree.size());
for (const RepeatedValue &E : Tree)
- Ops.append(E.second.getZExtValue(), ValueEntry(getRank(E.first), E.first));
+ Ops.append(E.second, ValueEntry(getRank(E.first), E.first));
LLVM_DEBUG(dbgs() << "RAIn:\t"; PrintOps(I, Ops); dbgs() << '\n');
| [
{
"file": "llvm/test/Transforms/Reassociate/repeats.ll",
"commands": [
"opt < %s -passes=reassociate -S"
],
"tests": [
{
"test_name": "foo4x11",
"test_body": "define i4 @foo4x11(i4 %x) {\n %tmp1 = mul i4 %x, %x\n %tmp2 = mul i4 %tmp1, %x\n %tmp3 = mul i4 %tmp2, %x\n %tmp4 = mul i4 %tmp3, %x\n %tmp5 = mul i4 %tmp4, %x\n %tmp6 = mul i4 %tmp5, %x\n %tmp7 = mul i4 %tmp6, %x\n %tmp8 = mul i4 %tmp7, %x\n %tmp9 = mul i4 %tmp8, %x\n %tmp10 = mul i4 %tmp9, %x\n ret i4 %tmp10\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "foo3x5_nsw",
"test_body": "define i3 @foo3x5_nsw(i3 %x) {\n %tmp1 = mul i3 %x, %x\n %tmp2 = mul i3 %tmp1, %x\n %tmp3 = mul i3 %tmp2, %x\n %tmp4 = mul nsw i3 %tmp3, %x\n ret i3 %tmp4\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "foo3x5",
"test_body": "define i3 @foo3x5(i3 %x) {\n %tmp1 = mul i3 %x, %x\n %tmp2 = mul i3 %tmp1, %x\n %tmp3 = mul i3 %tmp2, %x\n %tmp4 = mul i3 %tmp3, %x\n ret i3 %tmp4\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "foo4x10",
"test_body": "define i4 @foo4x10(i4 %x) {\n %tmp1 = mul i4 %x, %x\n %tmp2 = mul i4 %tmp1, %x\n %tmp3 = mul i4 %tmp2, %x\n %tmp4 = mul i4 %tmp3, %x\n %tmp5 = mul i4 %tmp4, %x\n %tmp6 = mul i4 %tmp5, %x\n %tmp7 = mul i4 %tmp6, %x\n %tmp8 = mul i4 %tmp7, %x\n %tmp9 = mul i4 %tmp8, %x\n ret i4 %tmp9\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "foo4x13",
"test_body": "define i4 @foo4x13(i4 %x) {\n %tmp1 = mul i4 %x, %x\n %tmp2 = mul i4 %tmp1, %x\n %tmp3 = mul i4 %tmp2, %x\n %tmp4 = mul i4 %tmp3, %x\n %tmp5 = mul i4 %tmp4, %x\n %tmp6 = mul i4 %tmp5, %x\n %tmp7 = mul i4 %tmp6, %x\n %tmp8 = mul i4 %tmp7, %x\n %tmp9 = mul i4 %tmp8, %x\n %tmp10 = mul i4 %tmp9, %x\n %tmp11 = mul i4 %tmp10, %x\n %tmp12 = mul i4 %tmp11, %x\n ret i4 %tmp12\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "foo4x8",
"test_body": "define i4 @foo4x8(i4 %x) {\n %tmp1 = mul i4 %x, %x\n %tmp2 = mul i4 %tmp1, %x\n %tmp3 = mul i4 %tmp2, %x\n %tmp4 = mul i4 %tmp3, %x\n %tmp5 = mul i4 %tmp4, %x\n %tmp6 = mul i4 %tmp5, %x\n %tmp7 = mul i4 %tmp6, %x\n ret i4 %tmp7\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "foo4x12",
"test_body": "define i4 @foo4x12(i4 %x) {\n %tmp1 = mul i4 %x, %x\n %tmp2 = mul i4 %tmp1, %x\n %tmp3 = mul i4 %tmp2, %x\n %tmp4 = mul i4 %tmp3, %x\n %tmp5 = mul i4 %tmp4, %x\n %tmp6 = mul i4 %tmp5, %x\n %tmp7 = mul i4 %tmp6, %x\n %tmp8 = mul i4 %tmp7, %x\n %tmp9 = mul i4 %tmp8, %x\n %tmp10 = mul i4 %tmp9, %x\n %tmp11 = mul i4 %tmp10, %x\n ret i4 %tmp11\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "foo4x15",
"test_body": "define i4 @foo4x15(i4 %x) {\n %tmp1 = mul i4 %x, %x\n %tmp2 = mul i4 %tmp1, %x\n %tmp3 = mul i4 %tmp2, %x\n %tmp4 = mul i4 %tmp3, %x\n %tmp5 = mul i4 %tmp4, %x\n %tmp6 = mul i4 %tmp5, %x\n %tmp7 = mul i4 %tmp6, %x\n %tmp8 = mul i4 %tmp7, %x\n %tmp9 = mul i4 %tmp8, %x\n %tmp10 = mul i4 %tmp9, %x\n %tmp11 = mul i4 %tmp10, %x\n %tmp12 = mul i4 %tmp11, %x\n %tmp13 = mul i4 %tmp12, %x\n %tmp14 = mul i4 %tmp13, %x\n ret i4 %tmp14\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "foo4x9",
"test_body": "define i4 @foo4x9(i4 %x) {\n %tmp1 = mul i4 %x, %x\n %tmp2 = mul i4 %tmp1, %x\n %tmp3 = mul i4 %tmp2, %x\n %tmp4 = mul i4 %tmp3, %x\n %tmp5 = mul i4 %tmp4, %x\n %tmp6 = mul i4 %tmp5, %x\n %tmp7 = mul i4 %tmp6, %x\n %tmp8 = mul i4 %tmp7, %x\n ret i4 %tmp8\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "foo4x14",
"test_body": "define i4 @foo4x14(i4 %x) {\n %tmp1 = mul i4 %x, %x\n %tmp2 = mul i4 %tmp1, %x\n %tmp3 = mul i4 %tmp2, %x\n %tmp4 = mul i4 %tmp3, %x\n %tmp5 = mul i4 %tmp4, %x\n %tmp6 = mul i4 %tmp5, %x\n %tmp7 = mul i4 %tmp6, %x\n %tmp8 = mul i4 %tmp7, %x\n %tmp9 = mul i4 %tmp8, %x\n %tmp10 = mul i4 %tmp9, %x\n %tmp11 = mul i4 %tmp10, %x\n %tmp12 = mul i4 %tmp11, %x\n %tmp13 = mul i4 %tmp12, %x\n ret i4 %tmp13\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "foo3x6",
"test_body": "define i3 @foo3x6(i3 %x) {\n %tmp1 = mul i3 %x, %x\n %tmp2 = mul i3 %tmp1, %x\n %tmp3 = mul i3 %tmp2, %x\n %tmp4 = mul i3 %tmp3, %x\n %tmp5 = mul i3 %tmp4, %x\n ret i3 %tmp5\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "foo3x7",
"test_body": "define i3 @foo3x7(i3 %x) {\n %tmp1 = mul i3 %x, %x\n %tmp2 = mul i3 %tmp1, %x\n %tmp3 = mul i3 %tmp2, %x\n %tmp4 = mul i3 %tmp3, %x\n %tmp5 = mul i3 %tmp4, %x\n %tmp6 = mul i3 %tmp5, %x\n ret i3 %tmp6\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "incorrect reassociation at low bitwidth",
"body": "here's a function:\r\n```llvm\r\ndefine i3 @f(i3 %0) {\r\n %2 = mul i3 %0, %0\r\n %3 = mul i3 %2, %0\r\n %4 = mul i3 %3, %0\r\n %5 = mul nsw i3 %4, %0\r\n ret i3 %5\r\n}\r\n```\r\n\r\nreassociate seems to be getting it wrong:\r\n```\r\nJohns-MacBook-Pro:reduce regehr$ ~/alive2-regehr/build/alive-tv reduced.ll -passes=reassociate\r\n\r\n----------------------------------------\r\ndefine i3 @f(i3 %#0) {\r\n#1:\r\n %#2 = mul i3 %#0, %#0\r\n %#3 = mul i3 %#2, %#0\r\n %#4 = mul i3 %#3, %#0\r\n %#5 = mul nsw i3 %#4, %#0\r\n ret i3 %#5\r\n}\r\n=>\r\ndefine i3 @f(i3 %#0) {\r\n#1:\r\n %#2 = mul i3 %#0, %#0\r\n %#3 = mul nsw i3 %#2, %#0\r\n ret i3 %#3\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\ni3 %#0 = #x6 (6, -2)\r\n\r\nSource:\r\ni3 %#2 = #x4 (4, -4)\r\ni3 %#3 = #x0 (0)\r\ni3 %#4 = #x0 (0)\r\ni3 %#5 = #x0 (0)\r\n\r\nTarget:\r\ni3 %#2 = #x4 (4, -4)\r\ni3 %#3 = poison\r\nSource value: #x0 (0)\r\nTarget value: poison\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\nJohns-MacBook-Pro:reduce regehr$ \r\n```\r\n\r\ncc @nunoplopes ",
"author": "regehr",
"labels": [
"miscompilation",
"llvm:transforms"
],
"comments": [
{
"author": "dtcxzyw",
"body": "Introduced by https://github.com/llvm/llvm-project/commit/d7aeefebd6b049f017711cd7c6ef5f217a17b673.\r\n"
}
]
} | true | null |
91078 | https://github.com/llvm/llvm-project/issues/91078 | crash | d5ca2e46ca97758de6edb9f071f2114205380d87 | 2024-05-04T18:39:13 | [
"llvm/test/Transforms/VectorCombine"
] | {
"fix_commit": "d145f40963f15e94c4aefcc406a365fbe779e934",
"components": [
"VectorCombine"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [
[
1755,
1764
]
],
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [
"VectorCombine::foldShuffleToIdentity"
],
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit d145f40963f15e94c4aefcc406a365fbe779e934
Author: David Green <[email protected]>
Date: Sun May 5 10:47:11 2024 +0100
[VectorCombine] shuffleToIdentity - guard against call instructions.
The shuffleToIdentity fold needs to be a bit more careful about the difference
between call instructions and intrinsics. The second can be handled, but the
first should result in bailing out. This patch also adds some extra intrinsic
tests from #91000.
Fixes #91078
diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index 04d2ff594bf5..bbb70134870a 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -1755,10 +1755,13 @@ bool VectorCombine::foldShuffleToIdentity(Instruction &I) {
return false;
if (IL.first->getValueID() != Item[0].first->getValueID())
return false;
+ if (isa<CallInst>(IL.first) && !isa<IntrinsicInst>(IL.first))
+ return false;
auto *II = dyn_cast<IntrinsicInst>(IL.first);
return !II ||
- II->getIntrinsicID() ==
- cast<IntrinsicInst>(Item[0].first)->getIntrinsicID();
+ (isa<IntrinsicInst>(Item[0].first) &&
+ II->getIntrinsicID() ==
+ cast<IntrinsicInst>(Item[0].first)->getIntrinsicID());
}))
return false;
| [
{
"file": "llvm/test/Transforms/VectorCombine/AArch64/shuffletoidentity.ll",
"commands": [
"opt -passes=vector-combine -S %s"
],
"tests": [
{
"test_name": "callinst",
"test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @callinst(<8 x half> %a) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x half> @othercall(<4 x half> %at)\n %abb = call <4 x half> @llvm.fabs.v4f16(<4 x half> %ab)\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n\ndeclare <4 x half> @othercall(<4 x half>)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x half> @llvm.fabs.v4f16(<4 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "callinst2",
"test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @callinst2(<8 x half> %a) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x half> @llvm.fabs.v4f16(<4 x half> %at)\n %abb = call <4 x half> @othercall(<4 x half> %ab)\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n\ndeclare <4 x half> @othercall(<4 x half>)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x half> @llvm.fabs.v4f16(<4 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "lrint",
"test_body": "target triple = \"aarch64\"\n\ndefine <8 x i32> @lrint(<8 x half> %a) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x i32> @llvm.lrint.v4i32.v4f16(<4 x half> %at)\n %abb = call <4 x i32> @llvm.lrint.v4i32.v4f16(<4 x half> %ab)\n %r = shufflevector <4 x i32> %abt, <4 x i32> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i32> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i32> @llvm.lrint.v4i32.v4f16(<4 x half>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "abs_different",
"test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @abs_different(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %at, i1 true)\n %abb = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %ab, i1 false)\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.abs.v4i8(<4 x i8>, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "powi",
"test_body": "target triple = \"aarch64\"\n\ndefine <8 x half> @powi(<8 x half> %a) {\n %ab = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x half> %a, <8 x half> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x half> @llvm.powi.v4f16.i32(<4 x half> %at, i32 10)\n %abb = call <4 x half> @llvm.powi.v4f16.i32(<4 x half> %ab, i32 10)\n %r = shufflevector <4 x half> %abt, <4 x half> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x half> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x half> @llvm.powi.v4f16.i32(<4 x half>, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "abs",
"test_body": "target triple = \"aarch64\"\n\ndefine <8 x i8> @abs(<8 x i8> %a) {\n %ab = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>\n %at = shufflevector <8 x i8> %a, <8 x i8> poison, <4 x i32> <i32 7, i32 6, i32 5, i32 4>\n %abt = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %at, i1 false)\n %abb = call <4 x i8> @llvm.abs.v4i8(<4 x i8> %ab, i1 false)\n %r = shufflevector <4 x i8> %abt, <4 x i8> %abb, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>\n ret <8 x i8> %r\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <4 x i8> @llvm.abs.v4i8(<4 x i8>, i1 immarg) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "A/F: isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\" after commit a4d1026",
"body": "A few of our internal tests started hitting an assertion failure which I bisected back to commit a4d10266d20bfe5930dfed77e17832af341ed66e. \r\n\r\nConsider the following code:\r\n```c++\r\ntemplate <typename a> a b(a);\r\ntypedef float c __attribute__((__vector_size__(32)));\r\ntypedef float __attribute__((ext_vector_type(8))) d;\r\ntypedef float __attribute__((ext_vector_type(4))) e;\r\nc f;\r\n#define g(h) (b(h))\r\nd i;\r\nvoid j() {\r\n c k = __builtin_ia32_rsqrtps256(f);\r\n d l(k);\r\n d m g(i);\r\n volatile e n = __builtin_shufflevector(l, m, 15, 2, 0, 1);\r\n}\r\n```\r\nWhen compiled with optimizations and `-mavx` it hits an assertion failure:\r\n```\r\n$ ~/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang -c -O2 -mavx repro2.cpp \r\nclang: /home/dyung/src/upstream/llvm_clean_git/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::IntrinsicInst; From = llvm::Value]: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed. \r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.\r\nStack dump:\r\n0. Program arguments: /home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang -c -O2 -mavx repro2.cpp\r\n1. <eof> parser at end of file\r\n2. Optimizer\r\n #0 0x0000557d533cfe2f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x4055e2f)\r\n #1 0x0000557d533cd96c llvm::sys::CleanupOnSignal(unsigned long) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x405396c)\r\n #2 0x0000557d5331a4e8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0\r\n #3 0x00007f0ccbb8b420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)\r\n #4 0x00007f0ccb65800b raise /build/glibc-e2p3jK/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1\r\n #5 0x00007f0ccb637859 abort /build/glibc-e2p3jK/glibc-2.31/stdlib/abort.c:81:7\r\n #6 0x00007f0ccb637729 get_sysdep_segment_value /build/glibc-e2p3jK/glibc-2.31/intl/loadmsgcat.c:509:8\r\n #7 0x00007f0ccb637729 _nl_load_domain /build/glibc-e2p3jK/glibc-2.31/intl/loadmsgcat.c:970:34\r\n #8 0x00007f0ccb648fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)\r\n #9 0x0000557d54cd0f88 (anonymous namespace)::VectorCombine::foldShuffleToIdentity(llvm::Instruction&)::'lambda3'(std::pair<llvm::Value*, int>)::operator()(std::pair<llvm::Value*, int>) const (.isra.0) VectorCombine.cpp:0:0\r\n#10 0x0000557d54cdac11 (anonymous namespace)::VectorCombine::foldShuffleToIdentity(llvm::Instruction&) VectorCombine.cpp:0:0\r\n#11 0x0000557d54ce56f1 (anonymous namespace)::VectorCombine::run()::'lambda'(llvm::Instruction&)::operator()(llvm::Instruction&) const (.isra.0) VectorCombine.cpp:0:0\r\n#12 0x0000557d54ce695d llvm::VectorCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x596c95d)\r\n#13 0x0000557d547ca386 llvm::detail::PassModel<llvm::Function, llvm::VectorCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x5450386)\r\n#14 0x0000557d50a03b4c llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x1689b4c)\r\n#15 0x0000557d52d96d0d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x3a1cd0d)\r\n#16 0x0000557d509e66d6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x166c6d6)\r\n#17 0x0000557d52d94b9d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x3a1ab9d)\r\n#18 0x0000557d5366aa28 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0\r\n#19 0x0000557d5366dd85 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) BackendUtil.cpp:0:0\r\n#20 0x0000557d5366e449 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x42f4449)\r\n#21 0x0000557d53cc97ca clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x494f7ca)\r\n#22 0x0000557d55a3f65c clang::ParseAST(clang::Sema&, bool, bool) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x66c565c)\r\n#23 0x0000557d53cc8278 clang::CodeGenAction::ExecuteAction() (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x494e278)\r\n#24 0x0000557d53f56729 clang::FrontendAction::Execute() (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x4bdc729)\r\n#25 0x0000557d53edc48e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x4b6248e)\r\n#26 0x0000557d54040e86 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x4cc6e86)\r\n#27 0x0000557d505e1bbc cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x1267bbc)\r\n#28 0x0000557d505dacca ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0\r\n#29 0x0000557d53d0d8ed void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0\r\n#30 0x0000557d5331a9f0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x3fa09f0)\r\n#31 0x0000557d53d0df0f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0\r\n#32 0x0000557d53cd2a4c clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x4958a4c)\r\n#33 0x0000557d53cd34dd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x49594dd)\r\n#34 0x0000557d53cdb8f5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x49618f5)\r\n#35 0x0000557d505defab clang_main(int, char**, llvm::ToolContext const&) (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x1264fab)\r\n#36 0x0000557d504db96b main (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x116196b)\r\n#37 0x00007f0ccb639083 __libc_start_main /build/glibc-e2p3jK/glibc-2.31/csu/../csu/libc-start.c:342:3\r\n#38 0x0000557d505da79e _start (/home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin/clang+0x126079e)\r\nclang: error: clang frontend command failed with exit code 134 (use -v to see invocation)\r\nclang version 19.0.0 (https://github.com/llvm/llvm-project.git a4d10266d20bfe5930dfed77e17832af341ed66e)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /home/dyung/src/upstream/a4d10266d20bfe5930dfed77e17832af341ed66e-linux/bin\r\nBuild config: +assertions\r\n```",
"author": "dyung",
"labels": [
"vectorizers",
"crash"
],
"comments": []
} | true | null |
113869 | https://github.com/llvm/llvm-project/issues/113869 | miscompilation | c752efbdcc1ebd81f879633d6b798248064e2ae2 | 2024-10-28T06:34:27 | [
"llvm/test/Transforms/InstCombine"
] | {
"fix_commit": "e577f14b670ee2ae6bb717133310b215be4331b3",
"components": [
"InstCombine"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [
[
1056,
1062
]
],
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [
"canonicalizeSaturatedAdd"
],
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit e577f14b670ee2ae6bb717133310b215be4331b3
Author: Yingwei Zheng <[email protected]>
Date: Fri Nov 1 22:18:44 2024 +0800
[InstCombine] Use `m_NotForbidPoison` when folding `(X u< Y) ? -1 : (~X + Y) --> uadd.sat(~X, Y)` (#114345)
Alive2: https://alive2.llvm.org/ce/z/mTGCo-
We cannot reuse `~X` if `m_AllOnes` matches a vector constant with some
poison elts. An alternative solution is to create a new not instead of
reusing `~X`. But it doesn't worth the effort because we need to add a
one-use check.
Fixes https://github.com/llvm/llvm-project/issues/113869.
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 162ebebf1b8f..999ad1adff20 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -1056,7 +1056,7 @@ static Value *canonicalizeSaturatedAdd(ICmpInst *Cmp, Value *TVal, Value *FVal,
// Strictness of the comparison is irrelevant.
X = Cmp0;
Y = Cmp1;
- if (match(FVal, m_c_Add(m_Not(m_Specific(X)), m_Specific(Y)))) {
+ if (match(FVal, m_c_Add(m_NotForbidPoison(m_Specific(X)), m_Specific(Y)))) {
// (X u< Y) ? -1 : (~X + Y) --> uadd.sat(~X, Y)
// (X u< Y) ? -1 : (Y + ~X) --> uadd.sat(Y, ~X)
BinaryOperator *BO = cast<BinaryOperator>(FVal);
| [
{
"file": "llvm/test/Transforms/InstCombine/saturating-add-sub.ll",
"commands": [
"opt < %s -passes=instcombine -S"
],
"tests": [
{
"test_name": "uadd_sat_not_commute_select",
"test_body": "define i32 @uadd_sat_not_commute_select(i32 %x, i32 %y) {\n %notx = xor i32 %x, -1\n %a = add i32 %notx, %y\n %c = icmp ult i32 %y, %x\n %r = select i1 %c, i32 %a, i32 -1\n ret i32 %r\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "uadd_sat_not_ugt_commute_add",
"test_body": "define <2 x i32> @uadd_sat_not_ugt_commute_add(<2 x i32> %x, <2 x i32> %yp) {\n %y = sdiv <2 x i32> %yp, <i32 2442, i32 4242>\n %notx = xor <2 x i32> %x, splat (i32 -1)\n %a = add <2 x i32> %y, %notx\n %c = icmp ugt <2 x i32> %y, %x\n %r = select <2 x i1> %c, <2 x i32> splat (i32 -1), <2 x i32> %a\n ret <2 x i32> %r\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "uadd_sat_not_ugt_commute_add_partial_poison",
"test_body": "define <2 x i32> @uadd_sat_not_ugt_commute_add_partial_poison(<2 x i32> %x, <2 x i32> %yp) {\n %notx = xor <2 x i32> %x, <i32 -1, i32 poison>\n %a = add nuw <2 x i32> %yp, %notx\n %c = icmp ugt <2 x i32> %yp, %x\n %r = select <2 x i1> %c, <2 x i32> splat (i32 -1), <2 x i32> %a\n ret <2 x i32> %r\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "Poison value wrongly propagates through vector operations on an optimized code",
"body": "https://github.com/llvm/llvm-project/blob/5d4a0d54b5269bad1410e6db957836fe98634069/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp#L1050-L1060\r\n\r\nAlive2 report: https://alive2.llvm.org/ce/z/6tSdhb\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine <2 x i32> @uadd_sat_not_ugt_commute_add.2(<2 x i32> %x, <2 x i32> %yp) {\r\n#0:\r\n %#1 = sdiv <2 x i32> { 2442, 4242 }, %yp\r\n %notx = xor <2 x i32> %x, { 4294967295, poison }\r\n %a = add nuw <2 x i32> %#1, %notx\r\n %c = icmp ugt <2 x i32> %#1, %x\r\n %r = select <2 x i1> %c, <2 x i32> { 4294967295, 4294967295 }, <2 x i32> %a\r\n ret <2 x i32> %r\r\n}\r\n=>\r\ndefine <2 x i32> @uadd_sat_not_ugt_commute_add.2(<2 x i32> %x, <2 x i32> %yp) {\r\n#0:\r\n %#1 = sdiv <2 x i32> { 2442, 4242 }, %yp\r\n %notx = xor <2 x i32> %x, { 4294967295, poison }\r\n %r = uadd_sat <2 x i32> %#1, %notx\r\n ret <2 x i32> %r\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\n<2 x i32> %x = < poison, #x00000000 (0) >\r\n<2 x i32> %yp = < #x00000008 (8), #x0000000e (14) >\r\n\r\nSource:\r\n<2 x i32> %#1 = < #x00000131 (305), #x0000012f (303) >\r\n<2 x i32> %notx = < poison, poison >\r\n<2 x i32> %a = < poison, poison >\r\n<2 x i1> %c = < poison, #x1 (1) >\r\n<2 x i32> %r = < poison, #xffffffff (4294967295, -1) >\r\n\r\nTarget:\r\n<2 x i32> %#1 = < #x00000131 (305), #x0000012f (303) >\r\n<2 x i32> %notx = < poison, poison >\r\n<2 x i32> %r = < poison, poison >\r\nSource value: < poison, #xffffffff (4294967295, -1) >\r\nTarget value: < poison, poison >\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```",
"author": "bongjunj",
"labels": [
"miscompilation",
"llvm:instcombine"
],
"comments": []
} | true | null |
111874 | https://github.com/llvm/llvm-project/issues/111874 | crash | 6a65e98fa7901dc1de91172d065fafb16ce89d77 | 2024-10-10T17:06:05 | [
"llvm/test/Transforms/LoopVectorize"
] | {
"fix_commit": "65da32c634a8345fcbe021f69fc6a609d074c08c",
"components": [
"LoopVectorize"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
[
6480,
6491
]
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
"LoopVectorizationCostModel::getInstructionCost"
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 65da32c634a8345fcbe021f69fc6a609d074c08c
Author: Florian Hahn <[email protected]>
Date: Fri Oct 11 11:26:57 2024 +0100
[LV] Account for any-of reduction when computing costs of blend phis.
Any-of reductions are narrowed to i1. Update the legacy cost model to
use the correct type when computing the cost of a phi that gets lowered
to selects (BLEND).
This fixes a divergence between legacy and VPlan-based cost models after
36fc291b6ec6d.
Fixes https://github.com/llvm/llvm-project/issues/111874.
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 05dc58a42249..54f57fb0b6b5 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -6480,12 +6480,32 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I,
// Phi nodes in non-header blocks (not inductions, reductions, etc.) are
// converted into select instructions. We require N - 1 selects per phi
// node, where N is the number of incoming values.
- if (VF.isVector() && Phi->getParent() != TheLoop->getHeader())
+ if (VF.isVector() && Phi->getParent() != TheLoop->getHeader()) {
+ Type *ResultTy = Phi->getType();
+
+ // All instructions in an Any-of reduction chain are narrowed to bool.
+ // Check if that is the case for this phi node.
+ auto *HeaderUser = cast_if_present<PHINode>(
+ find_singleton<User>(Phi->users(), [this](User *U, bool) -> User * {
+ auto *Phi = dyn_cast<PHINode>(U);
+ if (Phi && Phi->getParent() == TheLoop->getHeader())
+ return Phi;
+ return nullptr;
+ }));
+ if (HeaderUser) {
+ auto &ReductionVars = Legal->getReductionVars();
+ auto Iter = ReductionVars.find(HeaderUser);
+ if (Iter != ReductionVars.end() &&
+ RecurrenceDescriptor::isAnyOfRecurrenceKind(
+ Iter->second.getRecurrenceKind()))
+ ResultTy = Type::getInt1Ty(Phi->getContext());
+ }
return (Phi->getNumIncomingValues() - 1) *
TTI.getCmpSelInstrCost(
- Instruction::Select, ToVectorTy(Phi->getType(), VF),
+ Instruction::Select, ToVectorTy(ResultTy, VF),
ToVectorTy(Type::getInt1Ty(Phi->getContext()), VF),
CmpInst::BAD_ICMP_PREDICATE, CostKind);
+ }
return TTI.getCFInstrCost(Instruction::PHI, CostKind);
}
| [
{
"file": "llvm/test/Transforms/LoopVectorize/RISCV/blend-any-of-reduction-cost.ll",
"commands": [
"opt -p loop-vectorize -S %s"
],
"tests": [
{
"test_name": "any_of_reduction_used_in_blend",
"test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\ndefine i32 @any_of_reduction_used_in_blend(ptr %src, i64 %N, i1 %c.0, i1 %c.1) #0 {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %any.of.red = phi i32 [ 0, %entry ], [ %any.of.red.next, %loop.latch ]\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 %c.0, label %loop.latch, label %else.1\n\nelse.1: ; preds = %loop.header\n br i1 %c.1, label %loop.latch, label %else.2\n\nelse.2: ; preds = %else.1\n %l = load ptr, ptr %src, align 8\n %c.2 = icmp eq ptr %l, null\n %sel = select i1 %c.2, i32 0, i32 %any.of.red\n br label %loop.latch\n\nloop.latch: ; preds = %else.2, %else.1, %loop.header\n %any.of.red.next = phi i32 [ %any.of.red, %loop.header ], [ %any.of.red, %else.1 ], [ %sel, %else.2 ]\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, %N\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n %res = phi i32 [ %any.of.red.next, %loop.latch ]\n ret i32 %res\n}\n\nattributes #0 = { \"target-cpu\"=\"sifive-p670\" }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "any_of_reduction_used_in_blend_with_mutliple_phis",
"test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\ntarget triple = \"riscv64-unknown-linux-gnu\"\n\ndefine i32 @any_of_reduction_used_in_blend_with_mutliple_phis(ptr %src, i64 %N, i1 %c.0, i1 %c.1) #0 {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %any.of.red = phi i32 [ 0, %entry ], [ %any.of.red.next, %loop.latch ]\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 %c.0, label %x.1, label %else.1\n\nelse.1: ; preds = %loop.header\n br i1 %c.1, label %x.1, label %else.2\n\nelse.2: ; preds = %else.1\n %l = load ptr, ptr %src, align 8\n %c.2 = icmp eq ptr %l, null\n %sel = select i1 %c.2, i32 0, i32 %any.of.red\n br label %loop.latch\n\nx.1: ; preds = %else.1, %loop.header\n %p = phi i32 [ %any.of.red, %loop.header ], [ %any.of.red, %else.1 ]\n br label %loop.latch\n\nloop.latch: ; preds = %x.1, %else.2\n %any.of.red.next = phi i32 [ %p, %x.1 ], [ %sel, %else.2 ]\n %iv.next = add i64 %iv, 1\n %ec = icmp eq i64 %iv.next, %N\n br i1 %ec, label %exit, label %loop.header\n\nexit: ; preds = %loop.latch\n %res = phi i32 [ %any.of.red.next, %loop.latch ]\n ret i32 %res\n}\n\nattributes #0 = { \"target-cpu\"=\"sifive-p670\" }\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "Crash in LV: \"VPlan cost model and legacy cost model disagreed\"",
"body": "Loop vectorizer crash for the following reproducer:\r\n```\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine void @init_dependence_analysis(ptr %iiv_used.i.i.i.sroa.0, i64 %indvars.iv71.i.i.i, i1 %cmp104.not.i.i.i, i1 %tobool108.not.i.i.i) #0 {\r\nentry:\r\n br label %for.cond101.preheader.i.i.i\r\n\r\nfor.cond101.preheader.i.i.i: ; preds = %for.inc121.i.i.i, %entry\r\n %separability.0.i.i = phi i32 [ 0, %entry ], [ %separability.2.i.i, %for.inc121.i.i.i ]\r\n br label %for.body103.i.i.i\r\n\r\nfor.body103.i.i.i: ; preds = %for.inc121.i.i.i, %for.cond101.preheader.i.i.i\r\n %separability.1.i.i = phi i32 [ %separability.0.i.i, %for.cond101.preheader.i.i.i ], [ %separability.2.i.i, %for.inc121.i.i.i ]\r\n %indvars.iv71.i.i.i5 = phi i64 [ 0, %for.cond101.preheader.i.i.i ], [ %indvars.iv.next72.i.i.i, %for.inc121.i.i.i ]\r\n br i1 %cmp104.not.i.i.i, label %for.inc121.i.i.i, label %land.lhs.true105.i.i.i\r\n\r\nland.lhs.true105.i.i.i: ; preds = %for.body103.i.i.i\r\n br i1 %tobool108.not.i.i.i, label %for.inc121.i.i.i, label %land.lhs.true109.i.i.i\r\n\r\nland.lhs.true109.i.i.i: ; preds = %land.lhs.true105.i.i.i\r\n %0 = load ptr, ptr %iiv_used.i.i.i.sroa.0, align 8\r\n %cmp118.i.i.i = icmp eq ptr %0, null\r\n %spec.select209.i.i = select i1 %cmp118.i.i.i, i32 0, i32 %separability.1.i.i\r\n br label %for.inc121.i.i.i\r\n\r\nfor.inc121.i.i.i: ; preds = %land.lhs.true109.i.i.i, %land.lhs.true105.i.i.i, %for.body103.i.i.i\r\n %separability.2.i.i = phi i32 [ %separability.1.i.i, %for.body103.i.i.i ], [ %separability.1.i.i, %land.lhs.true105.i.i.i ], [ %spec.select209.i.i, %land.lhs.true109.i.i.i ]\r\n %indvars.iv.next72.i.i.i = add i64 %indvars.iv71.i.i.i5, 1\r\n %exitcond74.not.i.i.i = icmp eq i64 %indvars.iv71.i.i.i5, %indvars.iv71.i.i.i\r\n br i1 %exitcond74.not.i.i.i, label %for.cond101.preheader.i.i.i, label %for.body103.i.i.i\r\n\r\n; uselistorder directives\r\n uselistorder i32 %separability.2.i.i, { 1, 0 }\r\n}\r\n\r\nattributes #0 = { \"target-cpu\"=\"sifive-p670\" }\r\n```\r\n\r\nopt -S --passes=loop-vectorize ./reduced.ll\r\nLoopVectorize.cpp:7430: VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\n",
"author": "alexey-bataev",
"labels": [
"vectorizers",
"crash"
],
"comments": []
} | true | null |
77553 | https://github.com/llvm/llvm-project/issues/77553 | crash | c9c8f0c2fcf3b25ec310a75216f1d5b582ec343f | 2024-01-10T04:18:48 | [
"llvm/test/Transforms/InstCombine"
] | {
"fix_commit": "66eedd1dd370d22ddf994540c20848618d64d1a6",
"components": [
"InstCombine"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [
[
1704,
1714
]
],
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": [
"InstCombinerImpl::foldSelectInstWithICmp"
],
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 66eedd1dd370d22ddf994540c20848618d64d1a6
Author: hanbeom <[email protected]>
Date: Thu Jan 11 17:34:30 2024 +0900
[InstCombine] Fix worklist management in select fold (#77738)
`InstCombine` uses `Worklist` to manage change history. `setOperand`,
which was previously used to change the `Select` Instruction, does not,
so it is `run` twice, which causes an `LLVM ERROR`.
This problem is resolved by changing `setOperand` to `replaceOperand` as
the change history will be registered in the Worklist.
Fixes #77553.
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index ab55f235920a..21bfc91148bf 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -1704,11 +1704,11 @@ Instruction *InstCombinerImpl::foldSelectInstWithICmp(SelectInst &SI,
if (CmpRHS != CmpLHS && isa<Constant>(CmpRHS) && !isa<Constant>(CmpLHS)) {
if (CmpLHS == TrueVal && Pred == ICmpInst::ICMP_EQ) {
// Transform (X == C) ? X : Y -> (X == C) ? C : Y
- SI.setOperand(1, CmpRHS);
+ replaceOperand(SI, 1, CmpRHS);
Changed = true;
} else if (CmpLHS == FalseVal && Pred == ICmpInst::ICMP_NE) {
// Transform (X != C) ? Y : X -> (X != C) ? Y : C
- SI.setOperand(2, CmpRHS);
+ replaceOperand(SI, 2, CmpRHS);
Changed = true;
}
}
| [
{
"file": "llvm/test/Transforms/InstCombine/select.ll",
"commands": [
"opt < %s -passes=instcombine -S"
],
"tests": [
{
"test_name": "src_select_xxory_eq0_xorxy_y",
"test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine i32 @src_select_xxory_eq0_xorxy_y(i32 %x, i32 %y) {\n %xor = xor i32 %x, %y\n %xor0 = icmp eq i32 %xor, 0\n %cond = select i1 %xor0, i32 %xor, i32 %y\n ret i32 %cond\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "LLVM ERROR while InstCombine",
"body": "```\r\n$ bllvm0/bin/clang --version\r\nclang version 18.0.0git ([email protected]:ParkHanbum/llvm-project.git a9f39ff2b628e38826d5b95c1e8ae3cb7c692de9)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /home/m/bllvm0/bin\r\n```\r\nmy clang version.\r\n\r\nIR that caused the error\r\n```\r\ndefine i32 @no_trans_select_xor_eq0_xor_and(i32 %x, i32 %y) {\r\n; CHECK-LABEL: @no_trans_select_xor_eq0_xor_and(\r\n; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[X:%.*]], [[Y:%.*]]\r\n; CHECK-NEXT: [[XOR0:%.*]] = icmp eq i32 [[XOR]], 0\r\n; CHECK-NEXT: [[AND:%.*]] = and i32 [[X]], [[Y]]\r\n; CHECK-NEXT: [[COND:%.*]] = select i1 [[XOR0]], i32 [[XOR]], i32 [[AND]]\r\n; CHECK-NEXT: ret i32 [[COND]]\r\n;\r\n %xor = xor i32 %x, %y\r\n %xor0 = icmp eq i32 %xor, 0\r\n %and = and i32 %x, %y\r\n %cond = select i1 %xor0, i32 %xor, i32 %and\r\n ret i32 %cond\r\n}\r\n```\r\n\r\nand Debug message :\r\n```\r\n$ bllvm0/bin/opt -passes=instcombine temp.ll -debug\r\nINSTCOMBINE ITERATION #1 on no_trans_select_xor_eq0_xor_and\r\nADD: ret i32 %cond\r\nADD: %cond = select i1 %xor0, i32 %xor, i32 %and\r\nADD: %and = and i32 %x, %y\r\nADD: %xor0 = icmp eq i32 %xor, 0\r\nADD: %xor = xor i32 %x, %y\r\nIC: Visiting: %xor = xor i32 %x, %y\r\nIC: Visiting: %xor0 = icmp eq i32 %xor, 0\r\nIC: Visiting: %and = and i32 %x, %y\r\nIC: Visiting: %cond = select i1 %xor0, i32 %xor, i32 %and\r\nIC: Mod = %cond = select i1 %xor0, i32 %xor, i32 %and\r\n New = %cond = select i1 %xor0, i32 0, i32 %and\r\nADD: %cond = select i1 %xor0, i32 0, i32 %and\r\nIC: Visiting: %cond = select i1 %xor0, i32 0, i32 %and\r\nIC: Visiting: ret i32 %cond\r\n\r\n\r\nINSTCOMBINE ITERATION #2 on no_trans_select_xor_eq0_xor_and\r\nADD: ret i32 %cond\r\nADD: %cond = select i1 %xor0, i32 0, i32 %and\r\nADD: %and = and i32 %x, %y\r\nADD: %xor0 = icmp eq i32 %xor, 0\r\nADD: %xor = xor i32 %x, %y\r\nIC: Visiting: %xor = xor i32 %x, %y\r\nIC: Visiting: %xor0 = icmp eq i32 %xor, 0\r\nIC: Old = %xor0 = icmp eq i32 %xor, 0\r\n New = <badref> = icmp eq i32 %x, %y\r\nADD: %xor0 = icmp eq i32 %x, %y\r\nIC: ERASE %1 = icmp eq i32 %xor, 0\r\nADD DEFERRED: %xor = xor i32 %x, %y\r\nIC: ERASE %xor = xor i32 %x, %y\r\nIC: Visiting: %xor0 = icmp eq i32 %x, %y\r\nIC: Visiting: %and = and i32 %x, %y\r\nIC: Visiting: %cond = select i1 %xor0, i32 0, i32 %and\r\nIC: Visiting: ret i32 %cond\r\nLLVM ERROR: Instruction Combining did not reach a fixpoint after 1 iterations\r\n\r\n```\r\n\r\nIf time isn't tight, I'd like to take on this issue.\r\n\r\n",
"author": "ParkHanbum",
"labels": [
"llvm:instcombine",
"crash-on-valid"
],
"comments": [
{
"author": "nikic",
"body": "The problem is likely that https://github.com/llvm/llvm-project/blob/084f1c2ee074a5ac8186ea4b5b181b48bf4621b6/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp#L1704-L1714 calls setOperand() instead of replaceOperand()."
},
{
"author": "ParkHanbum",
"body": "@nikic can I try this?"
},
{
"author": "nikic",
"body": "Sure."
}
]
} | true | null |
114905 | https://github.com/llvm/llvm-project/issues/114905 | miscompilation | 1b476ecdcf4b544af1436341fc923c0b73793cbe | 2024-11-05T01:11:52 | [
"llvm/test/Transforms/SLPVectorizer"
] | {
"fix_commit": "889215a30ed60474e573f9632d1fa362dfa1b04e",
"components": [
"SLPVectorizer"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
[
19821,
19841
]
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
"tryToReduce"
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 889215a30ed60474e573f9632d1fa362dfa1b04e
Author: Alexey Bataev <[email protected]>
Date: Thu Dec 26 05:09:51 2024 -0800
[SLP]Followup fix for the poisonous logical op in reductions
If the VectorizedTree still may generate poisonous value, but it is not
the original operand of the reduction op, need to check if Res still the
operand, to generate correct code.
Fixes #114905
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 57f3016fbe1e..e9fc89fa242a 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -19821,21 +19821,21 @@ public:
Builder.SetCurrentDebugLocation(
cast<Instruction>(ReductionOps.front().front())->getDebugLoc());
if (AnyBoolLogicOp) {
-
- if (auto It = ReducedValsToOps.find(VectorizedTree);
- It == ReducedValsToOps.end() ||
+ auto It = ReducedValsToOps.find(VectorizedTree);
+ auto It1 = ReducedValsToOps.find(Res);
+ if ((It == ReducedValsToOps.end() && It1 == ReducedValsToOps.end()) ||
isGuaranteedNotToBePoison(VectorizedTree, AC) ||
- any_of(It->getSecond(), [&](Instruction *I) {
- return isBoolLogicOp(I) &&
- getRdxOperand(I, 0) == VectorizedTree;
- })) {
+ (It != ReducedValsToOps.end() &&
+ any_of(It->getSecond(), [&](Instruction *I) {
+ return isBoolLogicOp(I) &&
+ getRdxOperand(I, 0) == VectorizedTree;
+ }))) {
;
- } else if (auto It = ReducedValsToOps.find(Res);
- It == ReducedValsToOps.end() ||
- isGuaranteedNotToBePoison(Res, AC) ||
- any_of(It->getSecond(), [&](Instruction *I) {
+ } else if (isGuaranteedNotToBePoison(Res, AC) ||
+ (It1 != ReducedValsToOps.end() &&
+ any_of(It1->getSecond(), [&](Instruction *I) {
return isBoolLogicOp(I) && getRdxOperand(I, 0) == Res;
- })) {
+ }))) {
std::swap(VectorizedTree, Res);
} else {
VectorizedTree = Builder.CreateFreeze(VectorizedTree);
| [
{
"file": "llvm/test/Transforms/SLPVectorizer/X86/reduction-logical.ll",
"commands": [
"opt < %s -passes=slp-vectorizer -mtriple=x86_64-- -S",
"opt < %s -passes=slp-vectorizer -mtriple=x86_64-- -mattr=avx512vl -S"
],
"tests": [
{
"test_name": "logical_or_icmp_extra_op",
"test_body": "define i1 @logical_or_icmp_extra_op(<4 x i32> %x, <4 x i32> %y, i1 %c) {\n %x0 = extractelement <4 x i32> %x, i32 0\n %x1 = extractelement <4 x i32> %x, i32 1\n %x2 = extractelement <4 x i32> %x, i32 2\n %x3 = extractelement <4 x i32> %x, i32 3\n %y0 = extractelement <4 x i32> %y, i32 0\n %y1 = extractelement <4 x i32> %y, i32 1\n %y2 = extractelement <4 x i32> %y, i32 2\n %y3 = extractelement <4 x i32> %y, i32 3\n %d0 = icmp slt i32 %x0, %y0\n %d1 = icmp slt i32 %x1, %y1\n %d2 = icmp slt i32 %x2, %y2\n %d3 = icmp slt i32 %x3, %y3\n %s3 = select i1 %c, i1 true, i1 %c\n %s4 = select i1 %s3, i1 true, i1 %d0\n %s5 = select i1 %s4, i1 true, i1 %d1\n %s6 = select i1 %s5, i1 true, i1 %d2\n %s7 = select i1 %s6, i1 true, i1 %d3\n ret i1 %s7\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "logical_and_icmp_extra_op",
"test_body": "define i1 @logical_and_icmp_extra_op(<4 x i32> %x, <4 x i32> %y, i1 %c) {\n %x0 = extractelement <4 x i32> %x, i32 0\n %x1 = extractelement <4 x i32> %x, i32 1\n %x2 = extractelement <4 x i32> %x, i32 2\n %x3 = extractelement <4 x i32> %x, i32 3\n %y0 = extractelement <4 x i32> %y, i32 0\n %y1 = extractelement <4 x i32> %y, i32 1\n %y2 = extractelement <4 x i32> %y, i32 2\n %y3 = extractelement <4 x i32> %y, i32 3\n %d0 = icmp slt i32 %x0, %y0\n %d1 = icmp slt i32 %x1, %y1\n %d2 = icmp slt i32 %x2, %y2\n %d3 = icmp slt i32 %x3, %y3\n %s3 = select i1 %c, i1 %c, i1 false\n %s4 = select i1 %s3, i1 %d0, i1 false\n %s5 = select i1 %s4, i1 %d1, i1 false\n %s6 = select i1 %s5, i1 %d2, i1 false\n %s7 = select i1 %s6, i1 %d3, i1 false\n ret i1 %s7\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/SLPVectorizer/logical-ops-poisonous-repeated.ll",
"commands": [
"opt -S --passes=slp-vectorizer < %s"
],
"tests": [
{
"test_name": "test",
"test_body": "define i1 @test(<4 x i32> %x) {\n %x0 = extractelement <4 x i32> %x, i32 0\n %x1 = extractelement <4 x i32> %x, i32 -1\n %x2 = extractelement <4 x i32> %x, i32 2\n %x3 = extractelement <4 x i32> %x, i32 3\n %1 = icmp ugt i32 %x0, 0\n %c1 = icmp slt i32 %x1, 0\n %c2 = icmp sgt i32 %x2, 0\n %c3 = icmp slt i32 %x3, 0\n %s1 = select i1 %1, i1 %c1, i1 false\n %s2 = select i1 %s1, i1 %c3, i1 false\n %s3 = select i1 %s2, i1 %c3, i1 false\n ret i1 %s3\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "wrong folding of `select`s in slp-vectorizer",
"body": "Alive2 report: https://alive2.llvm.org/ce/z/jEopx9\r\n\r\n```llvm\r\n----------------------------------------\r\ndefine i1 @logical_and_icmp_diff_preds.2(<4 x i32> %x) {\r\n#0:\r\n %x0 = extractelement <4 x i32> %x, i32 0\r\n %x1 = extractelement <4 x i32> %x, i32 4294967295\r\n %x3 = extractelement <4 x i32> %x, i32 3\r\n %#1 = icmp ugt i32 %x0, 0\r\n %c1 = icmp slt i32 %x1, 0\r\n %c3 = icmp slt i32 %x3, 0\r\n %s1 = select i1 %#1, i1 %c1, i1 0\r\n %s2 = select i1 %s1, i1 %c3, i1 0\r\n %s3 = select i1 %s2, i1 %c3, i1 0\r\n ret i1 %s3\r\n}\r\n=>\r\ndefine i1 @logical_and_icmp_diff_preds.2(<4 x i32> %x) {\r\n#0:\r\n %x0 = extractelement <4 x i32> %x, i32 0\r\n %x1 = extractelement <4 x i32> %x, i32 4294967295\r\n %x3 = extractelement <4 x i32> %x, i32 3\r\n %#1 = icmp ugt i32 %x0, 0\r\n %c1 = icmp slt i32 %x1, 0\r\n %c3 = icmp slt i32 %x3, 0\r\n %op.rdx = select i1 %c3, i1 %c1, i1 0\r\n %op.rdx1 = select i1 %op.rdx, i1 %#1, i1 0\r\n ret i1 %op.rdx1\r\n}\r\nTransformation doesn't verify!\r\n\r\nERROR: Target is more poisonous than source\r\n\r\nExample:\r\n<4 x i32> %x = < #x00000000 (0), #x00000000 (0), #x00000000 (0), #xffffffff (4294967295, -1) >\r\n\r\nSource:\r\ni32 %x0 = #x00000000 (0)\r\ni32 %x1 = poison\r\ni32 %x3 = #xffffffff (4294967295, -1)\r\ni1 %#1 = #x0 (0)\r\ni1 %c1 = poison\r\ni1 %c3 = #x1 (1)\r\ni1 %s1 = #x0 (0)\r\ni1 %s2 = #x0 (0)\r\ni1 %s3 = #x0 (0)\r\n\r\nTarget:\r\ni32 %x0 = #x00000000 (0)\r\ni32 %x1 = poison\r\ni32 %x3 = #xffffffff (4294967295, -1)\r\ni1 %#1 = #x0 (0)\r\ni1 %c1 = poison\r\ni1 %c3 = #x1 (1)\r\ni1 %op.rdx = poison\r\ni1 %op.rdx1 = poison\r\nSource value: #x0 (0)\r\nTarget value: poison\r\n\r\nSummary:\r\n 0 correct transformations\r\n 1 incorrect transformations\r\n 0 failed-to-prove transformations\r\n 0 Alive2 errors\r\n```",
"author": "bongjunj",
"labels": [
"miscompilation",
"llvm:SLPVectorizer"
],
"comments": [
{
"author": "nunoplopes",
"body": "Alive2 is still not happy with the fix:\n```llvm\ndefine i1 @test(<4 x i32> %x) {\n %x0 = extractelement <4 x i32> %x, i32 0\n %x1 = extractelement <4 x i32> %x, i32 4294967295\n %x3 = extractelement <4 x i32> %x, i32 3\n %#1 = icmp ugt i32 %x0, 0\n %c1 = icmp slt i32 %x1, 0\n %c3 = icmp slt i32 %x3, 0\n %s1 = select i1 %#1, i1 %c1, i1 0\n %s2 = select i1 %s1, i1 %c3, i1 0\n %s3 = select i1 %s2, i1 %c3, i1 0\n ret i1 %s3\n}\n=>\ndefine i1 @test(<4 x i32> %x) {\n %x0 = extractelement <4 x i32> %x, i32 0\n %x1 = extractelement <4 x i32> %x, i32 4294967295\n %x3 = extractelement <4 x i32> %x, i32 3\n %#1 = icmp ugt i32 %x0, 0\n %c1 = icmp slt i32 %x1, 0\n %c3 = icmp slt i32 %x3, 0\n %#2 = freeze i1 %c3\n %op.rdx = select i1 %#2, i1 %c1, i1 0\n %op.rdx1 = select i1 %op.rdx, i1 %#1, i1 0\n ret i1 %op.rdx1\n}\nTransformation doesn't verify!\n\nERROR: Target is more poisonous than source\n\nExample:\n<4 x i32> %x = < #x00000000 (0), poison, poison, #xffffffff (4294967295, -1) >\n\nSource:\ni32 %x0 = #x00000000 (0)\ni32 %x1 = poison\ni32 %x3 = #xffffffff (4294967295, -1)\ni1 %#1 = #x0 (0)\ni1 %c1 = poison\ni1 %c3 = #x1 (1)\ni1 %s1 = #x0 (0)\ni1 %s2 = #x0 (0)\ni1 %s3 = #x0 (0)\n\nTarget:\ni32 %x0 = #x00000000 (0)\ni32 %x1 = poison\ni32 %x3 = #xffffffff (4294967295, -1)\ni1 %#1 = #x0 (0)\ni1 %c1 = poison\ni1 %c3 = #x1 (1)\ni1 %#2 = #x1 (1)\ni1 %op.rdx = poison\ni1 %op.rdx1 = poison\nSource value: #x0 (0)\nTarget value: poison\n```"
}
]
} | true | null |
82052 | https://github.com/llvm/llvm-project/issues/82052 | miscompilation | a45df47375e50914900dcc07abd2fa67bfa0dd3b | 2024-02-16T22:14:29 | [
"llvm/test/Transforms/InstCombine"
] | {
"fix_commit": "d2a26a7bd5fc7cc5752337b7f4f999642feb37dc",
"components": [
"InstCombine"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": [
[
1870,
1883
]
],
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": [
"InstCombinerImpl::SimplifyDemandedVectorElts"
],
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit d2a26a7bd5fc7cc5752337b7f4f999642feb37dc
Author: Antonio Frighetto <[email protected]>
Date: Sun Feb 18 18:10:41 2024 +0100
[InstCombine] Do not perform binop-of-shuffle when mask is poison
A miscompilation issue has been addressed with refined checking.
Shuffle masks operand may be turned into `poison` if this does
not lead to observable changes. This however may not guarantee
binop to binop-of-shuffle replacement to be sound anymore.
Fixes: https://github.com/llvm/llvm-project/issues/82052.
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index 5f13454089e5..97ae980a7cba 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -1870,14 +1870,16 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
Value *ShufOp = MatchShufAsOp0 ? X : Y;
Value *OtherOp = MatchShufAsOp0 ? Y : X;
for (User *U : OtherOp->users()) {
- auto Shuf = m_Shuffle(m_Specific(ShufOp), m_Value(), m_ZeroMask());
+ ArrayRef<int> Mask;
+ auto Shuf = m_Shuffle(m_Specific(ShufOp), m_Value(), m_Mask(Mask));
if (BO->isCommutative()
? match(U, m_c_BinOp(Opcode, Shuf, m_Specific(OtherOp)))
: MatchShufAsOp0
? match(U, m_BinOp(Opcode, Shuf, m_Specific(OtherOp)))
: match(U, m_BinOp(Opcode, m_Specific(OtherOp), Shuf)))
- if (DT.dominates(U, I))
- return U;
+ if (match(Mask, m_ZeroMask()) && Mask[0] != PoisonMaskElem)
+ if (DT.dominates(U, I))
+ return U;
}
return nullptr;
};
| [
{
"file": "llvm/test/Transforms/InstCombine/vec_demanded_elts.ll",
"commands": [
"opt < %s -passes=instcombine -S"
],
"tests": [
{
"test_name": "common_binop_demand_via_extelt_op0_mismatch_elt1",
"test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\n\ndeclare void @use(<2 x i4>)\n\ndefine i4 @common_binop_demand_via_extelt_op0_mismatch_elt1(<2 x i4> %x, <2 x i4> %y) {\n %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer\n %b_xshuf_y = sub <2 x i4> %xshuf, %y\n %b_xy = sub nsw <2 x i4> %x, %y\n %b_xy0 = extractelement <2 x i4> %b_xy, i32 1\n call void @use(<2 x i4> %b_xshuf_y)\n ret i4 %b_xy0\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "common_binop_demand_via_splat_mask_poison",
"test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine <2 x i8> @common_binop_demand_via_splat_mask_poison(<2 x i8> %x, <2 x i8> %y) {\n %ysplat = shufflevector <2 x i8> %y, <2 x i8> poison, <2 x i32> <i32 0, i32 poison>\n %vv = add <2 x i8> %x, %ysplat\n %m = add <2 x i8> %x, %y\n %msplat = shufflevector <2 x i8> %m, <2 x i8> poison, <2 x i32> zeroinitializer\n %res = add <2 x i8> %vv, %msplat\n ret <2 x i8> %res\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "common_binop_demand_via_splat_mask_poison_2",
"test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine <2 x i8> @common_binop_demand_via_splat_mask_poison_2(<2 x i8> %x, <2 x i8> %y) {\n %ysplat = shufflevector <2 x i8> %y, <2 x i8> poison, <2 x i32> <i32 poison, i32 0>\n %vv = add <2 x i8> %x, %ysplat\n %m = add <2 x i8> %x, %y\n %msplat = shufflevector <2 x i8> %m, <2 x i8> %y, <2 x i32> <i32 0, i32 2>\n %res = add <2 x i8> %vv, %msplat\n ret <2 x i8> %res\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "common_binop_demand_via_splat_mask_poison_3",
"test_body": "target datalayout = \"e-m:e-i64:64-f80:128-n8:16:32:64-S128\"\n\ndefine <2 x i8> @common_binop_demand_via_splat_mask_poison_3(<2 x i8> %x, <2 x i8> %y) {\n %ysplat = shufflevector <2 x i8> %y, <2 x i8> poison, <2 x i32> <i32 poison, i32 0>\n %vv = add <2 x i8> %x, %ysplat\n %m = add <2 x i8> %x, %y\n %msplat = shufflevector <2 x i8> %m, <2 x i8> poison, <2 x i32> zeroinitializer\n %res = add <2 x i8> %vv, %msplat\n ret <2 x i8> %res\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[InstCombine] Replacement of binop with binop-of-shuffle incorrectly adds extra poison value",
"body": "The following IR is a minimal repro when run with `opt -passes=instcombine`:\r\n```llvm\r\ndefine i8 @src(<2 x i8> %x, <2 x i8> %y) {\r\n %xsplat = shufflevector <2 x i8> %x, <2 x i8> poison, <2 x i32> <i32 1, i32 0>\r\n %vv = mul <2 x i8> %xsplat, %y\r\n %m = mul <2 x i8> %x, %y ; <<<< Note that %m is later replaced with %vv in the output\r\n %msplat = shufflevector <2 x i8> %m, <2 x i8> poison, <2 x i32> <i32 0, i32 0>\r\n %res = add <2 x i8> %vv, %msplat\r\n %vget_lane = extractelement <2 x i8> %res, i64 1\r\n ret i8 %vget_lane\r\n}\r\n```\r\nWhich on 17.x or trunk will give:\r\n```llvm\r\ndefine i8 @src(<2 x i8> %x, <2 x i8> %y) {\r\n %xsplat = shufflevector <2 x i8> %x, <2 x i8> poison, <2 x i32> <i32 poison, i32 0>\r\n %vv = mul <2 x i8> %xsplat, %y\r\n %msplat = shufflevector <2 x i8> %vv, <2 x i8> poison, <2 x i32> <i32 poison, i32 0>\r\n %res = add <2 x i8> %vv, %msplat\r\n %vget_lane = extractelement <2 x i8> %res, i64 1\r\n ret i8 %vget_lane\r\n}\r\n```\r\nHowever, this is not correct, because the added poisoned values end up observed in the final output. First, in InstCombine, the first element in each mask for the shuffles are first replaced with `poison` due to not being observed in the final `extractelement`. After that we run into this code in `InstCombineSimplifyDemanded.cpp`:\r\nhttps://github.com/llvm/llvm-project/blob/d8278b682386f51dfba204849c624672a3df40c7/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp#L1866-L1880\r\n\r\nThis is what replaces the `mul <2 x i8> %x, %y` with `mul <2 x i8> %xsplat, %y` (`m_ZeroMask` also matches poison). However in doing so, it introduces the extra poison from `%xsplat`, meaning that `%msplat` has both its elements poisoned, which ends up propagating to `%vget_lane`.\r\n\r\nHere is a Godbolt link showing the test case on 16.x, 17.x, and trunk:\r\nhttps://godbolt.org/z/5eeT7x4s3\r\n\r\nAnd also an Alive2 example showing the bad transformation with a counter-example:\r\nhttps://alive2.llvm.org/ce/z/RpBJEN\r\n\r\nThe code was first introduced in 3b090ff2bdb2828b53d6fec9c06b9d52fed09f42, which a bisect shows is when this first started repro'ing\r\n\r\nI have verified that this still repros on latest trunk, 2de269a641e4ffbb7a44e559c4c0a91bb66df823\r\n\r\nFor priority/triage: this bug was found by a fuzzer meant to test SIMD codegen. It was not from manually written code",
"author": "Benjins",
"labels": [
"miscompilation",
"llvm:instcombine"
],
"comments": [
{
"author": "Benjins",
"body": "A slightly smaller test case:\r\nhttps://alive2.llvm.org/ce/z/6AMPWC\r\n```llvm\r\ndefine <2 x i8> @src(<2 x i8> %x, <2 x i8> %y) {\r\n %xsplat = shufflevector <2 x i8> %x, <2 x i8> poison, <2 x i32> <i32 poison, i32 0>\r\n %vv = mul <2 x i8> %xsplat, %y\r\n %m = mul <2 x i8> %x, %y\r\n %msplat = shufflevector <2 x i8> %m, <2 x i8> poison, <2 x i32> <i32 poison, i32 0>\r\n %res = add <2 x i8> %vv, %msplat\r\n ret <2 x i8> %res\r\n}\r\n```\r\nThis doesn't extract the vector, and instead manually specifies the poisonous elements in the shuffles. As Alive notes, the output for `src(<0, 0>, <0, 0>)` goes from `<poison, 0>` to `<poison, poison>`"
}
]
} | true | null |
98838 | https://github.com/llvm/llvm-project/issues/98838 | miscompilation | 9ba9e480fa4ef1f37a2b6b51603ac8e446cca5ff | 2024-07-14T21:26:59 | [
"llvm/test/Transforms/SLPVectorizer"
] | {
"fix_commit": "beccecaacde405a3b50891c67594eccbcd1c8b08",
"components": [
"SLPVectorizer"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
[
14201,
14209
]
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
"BoUpSLP::vectorizeTree"
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit beccecaacde405a3b50891c67594eccbcd1c8b08
Author: Alexey Bataev <[email protected]>
Date: Mon Jul 15 07:03:22 2024 -0700
[SLP]Fix PR98838: do no replace condition of select-based logical op by poison.
If the reduction operation is a select-based logical op, the condition
should be replaced by the poison, better to replace by the non-poisoning
constant to prevent poison propagation in the vector code.
Fixes https://github.com/llvm/llvm-project/issues/98838
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 5c2fc0b9320e..74a16d3fbcad 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -14201,9 +14201,23 @@ Value *BoUpSLP::vectorizeTree(
for (Instruction *I : RemovedInsts) {
if (getTreeEntry(I)->Idx != 0)
continue;
+ SmallVector<SelectInst *> LogicalOpSelects;
I->replaceUsesWithIf(PoisonValue::get(I->getType()), [&](Use &U) {
+ // Do not replace condition of the logical op in form select <cond>.
+ bool IsPoisoningLogicalOp = isa<SelectInst>(U.getUser()) &&
+ (match(U.getUser(), m_LogicalAnd()) ||
+ match(U.getUser(), m_LogicalOr())) &&
+ U.getOperandNo() == 0;
+ if (IsPoisoningLogicalOp) {
+ LogicalOpSelects.push_back(cast<SelectInst>(U.getUser()));
+ return false;
+ }
return UserIgnoreList->contains(U.getUser());
});
+ // Replace conditions of the poisoning logical ops with the non-poison
+ // constant value.
+ for (SelectInst *SI : LogicalOpSelects)
+ SI->setCondition(Constant::getNullValue(SI->getCondition()->getType()));
}
}
// Retain to-be-deleted instructions for some debug-info bookkeeping and alias
| [
{
"file": "llvm/test/Transforms/SLPVectorizer/X86/select-reduction-op.ll",
"commands": [
"opt -S --passes=slp-vectorizer < %s"
],
"tests": [
{
"test_name": "src",
"test_body": "define i1 @src(i1 %cmp4.118.i) {\n %cmp4.118.i.not = xor i1 %cmp4.118.i, true\n %brmerge = select i1 %cmp4.118.i.not, i1 true, i1 poison\n %.not = xor i1 poison, true\n %brmerge2 = select i1 %brmerge, i1 true, i1 %.not\n %.not3 = xor i1 poison, true\n %brmerge4 = select i1 %brmerge2, i1 true, i1 %.not3\n %.not5 = xor i1 poison, true\n %brmerge6 = select i1 %brmerge4, i1 true, i1 %.not5\n %.not7 = xor i1 poison, true\n %brmerge8 = select i1 %brmerge6, i1 true, i1 %.not7\n ret i1 %brmerge8\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "wrong code at -O3 on x86_64-linux-gnu",
"body": "It appears to be a recent regression as it doesn't reproduce with 18.1.0 and earlier. \r\n\r\nCompiler Explorer: https://godbolt.org/z/fzsqjEPWW\r\n\r\n```\r\n[562] % clangtk -v\r\nclang version 19.0.0git (https://github.com/llvm/llvm-project.git 52139d8f9a4e3f595ca552393d62ba06b0bc082c)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /local/suz-local/software/local/clang-trunk/bin\r\nBuild config: +assertions\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nFound candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9\r\nSelected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11\r\nCandidate multilib: .;@m64\r\nSelected multilib: .;@m64\r\n[563] % \r\n[563] % clangtk -O2 -w small.c\r\n[564] % ./a.out\r\n0\r\n[565] % clangtk -O3 -w small.c\r\n[566] % ./a.out\r\n[567] % \r\n[567] % cat small.c\r\nint printf(const char *, ...);\r\nint a, b, e, g;\r\nvolatile int c;\r\nstatic int d[1] = {1}, f;\r\nint h() {\r\n for (b = 0; b < 4; b++) {\r\n for (e = 0; e < 4; e++)\r\n while (b) {\r\n if (c > 0 && d[1])\r\n break;\r\n return f;\r\n }\r\n }\r\n return 0;\r\n}\r\nvoid i() {\r\n int *j[1];\r\n j[g] = &d[0];\r\n}\r\nint main() {\r\n h();\r\n printf(\"%d\\n\", a);\r\n return 0;\r\n}\r\n```\r\n\r\n",
"author": "zhendongsu",
"labels": [
"miscompilation",
"llvm:SLPVectorizer",
"confirmed"
],
"comments": [
{
"author": "dtcxzyw",
"body": "Reproducer: https://alive2.llvm.org/ce/z/Whfr_a\r\n```\r\n; bin/opt -passes=slp-vectorizer -S test.ll\r\ndefine i1 @src(i1 %cmp4.118.i) {\r\n %cmp4.118.i.not = xor i1 %cmp4.118.i, true\r\n %brmerge = select i1 %cmp4.118.i.not, i1 true, i1 poison\r\n %.not = xor i1 poison, true\r\n %brmerge2 = select i1 %brmerge, i1 true, i1 %.not\r\n %.not3 = xor i1 poison, true\r\n %brmerge4 = select i1 %brmerge2, i1 true, i1 %.not3\r\n %.not5 = xor i1 poison, true\r\n %brmerge6 = select i1 %brmerge4, i1 true, i1 %.not5\r\n %.not7 = xor i1 poison, true\r\n %brmerge8 = select i1 %brmerge6, i1 true, i1 %.not7\r\n ret i1 %brmerge8\r\n}\r\n```\r\n```\r\ndefine i1 @tgt(i1 %cmp4.118.i) {\r\n %1 = insertelement <4 x i1> <i1 poison, i1 true, i1 true, i1 true>, i1 %cmp4.118.i, i32 0\r\n %2 = xor <4 x i1> %1, <i1 true, i1 poison, i1 poison, i1 poison>\r\n %.not7 = xor i1 poison, true\r\n %3 = freeze <4 x i1> %2\r\n %4 = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> %3)\r\n %op.rdx = select i1 %4, i1 true, i1 %.not7\r\n %op.rdx1 = select i1 poison, i1 true, i1 %op.rdx\r\n ret i1 %op.rdx1\r\n}\r\n```\r\ncc @alexey-bataev "
}
]
} | true | null |
78621 | https://github.com/llvm/llvm-project/issues/78621 | miscompilation | 90ba33099cbb17e7c159e9ebc5a512037db99d6d | 2024-01-18T20:57:06 | [
"llvm/test/Transforms/ConstraintElimination"
] | {
"fix_commit": "3d91d9613e294b242d853039209b40a0cb7853f2",
"components": [
"ConstraintElimination"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": [
[
1061,
1071
]
],
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": [
"State::addInfoFor"
],
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 3d91d9613e294b242d853039209b40a0cb7853f2
Author: Florian Hahn <[email protected]>
Date: Wed Jan 24 14:25:54 2024 +0000
[ConstraintElim] Make sure min/max intrinsic results are not poison.
The result of umin may be poison and in that case the added constraints
are not be valid in contexts where poison doesn't cause UB. Only queue
facts for min/max intrinsics if the result is guaranteed to not be
poison.
This could be improved in the future, by only adding the fact when
solving conditions using the result value.
Fixes https://github.com/llvm/llvm-project/issues/78621.
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index 8f09569d0d9c..7b672e89b67a 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -1061,11 +1061,16 @@ void State::addInfoFor(BasicBlock &BB) {
FactOrCheck::getCheck(DT.getNode(&BB), cast<CallInst>(&I)));
break;
// Enqueue the intrinsics to add extra info.
- case Intrinsic::abs:
case Intrinsic::umin:
case Intrinsic::umax:
case Intrinsic::smin:
case Intrinsic::smax:
+ // TODO: Check if it is possible to instead only added the min/max facts
+ // when simplifying uses of the min/max intrinsics.
+ if (!isGuaranteedNotToBePoison(&I))
+ break;
+ [[fallthrough]];
+ case Intrinsic::abs:
WorkList.push_back(FactOrCheck::getInstFact(DT.getNode(&BB), &I));
break;
}
| [
{
"file": "llvm/test/Transforms/ConstraintElimination/minmax.ll",
"commands": [
"opt -passes=constraint-elimination -S %s"
],
"tests": [
{
"test_name": "smin_branchless",
"test_body": "define i1 @smin_branchless(i32 %x, i32 %y) {\nentry:\n %min = call i32 @llvm.smin.i32(i32 %x, i32 %y)\n %cmp1 = icmp sle i32 %min, %x\n %cmp2 = icmp sgt i32 %min, %x\n %ret = xor i1 %cmp1, %cmp2\n ret i1 %ret\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.smin.i32(i32, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/ConstraintElimination/umin-result-may-be-poison.ll",
"commands": [
"opt -p constraint-elimination -S %s"
],
"tests": [
{
"test_name": "umin_poison_call_before_UB",
"test_body": "define i1 @umin_poison_call_before_UB(i32 %arg) {\n %icmp = icmp slt i32 %arg, 0\n %shl = shl nuw nsw i32 %arg, 3\n %min = call i32 @llvm.umin.i32(i32 %shl, i32 80)\n call void @fn()\n call void @noundef(i32 noundef %min)\n %cmp2 = shl nuw nsw i32 %arg, 3\n ret i1 %icmp\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.umin.i32(i32, i32) #0\n\ndeclare void @noundef(i32 noundef)\n\ndeclare void @fn()\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "umin_not_used",
"test_body": "define i1 @umin_not_used(i32 %arg) {\n %icmp = icmp slt i32 %arg, 0\n %shl = shl nuw nsw i32 %arg, 3\n %1 = call i32 @llvm.umin.i32(i32 %shl, i32 80)\n %cmp2 = shl nuw nsw i32 %arg, 3\n ret i1 %icmp\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.umin.i32(i32, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "umin_poison_is_UB_via_call",
"test_body": "define i1 @umin_poison_is_UB_via_call(i32 %arg) {\n %icmp = icmp slt i32 %arg, 0\n %shl = shl nuw nsw i32 %arg, 3\n %min = call i32 @llvm.umin.i32(i32 %shl, i32 80)\n call void @noundef(i32 noundef %min)\n %cmp2 = shl nuw nsw i32 %arg, 3\n ret i1 %icmp\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i32 @llvm.umin.i32(i32, i32) #0\n\ndeclare void @noundef(i32 noundef)\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[ConstraintElimination] A miscompile in presence of `shl nuw nsw` and `llvm.umin`",
"body": "The following commit: https://github.com/llvm/llvm-project/commit/71f56e49ceca75dbf82cbb9537c2545c2d2e51c9\r\nTriggered this miscompile: https://alive2.llvm.org/ce/z/oBg-u8\r\n\r\nNow `opt -passes=constraint-elimination -S` turns\r\n```\r\ndefine i1 @test(i32 %arg) {\r\n %icmp = icmp slt i32 %arg, 0\r\n %shl = shl nuw nsw i32 %arg, 3\r\n %call4 = call i32 @llvm.umin.i32(i32 %shl, i32 80)\r\n ret i1 %icmp\r\n}\r\n\r\ndeclare i32 @llvm.umin.i32(i32, i32) #0\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\ninto\r\n```\r\ndefine i1 @test(i32 %arg) {\r\n %shl = shl nuw nsw i32 %arg, 3\r\n %call4 = call i32 @llvm.umin.i32(i32 %shl, i32 80)\r\n ret i1 false\r\n}\r\n\r\ndeclare i32 @llvm.umin.i32(i32, i32) #0\r\n\r\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\n\r\nGiven this debug output:\r\n```\r\nopt -passes=constraint-elimination before-constr-elim-renamed.ll -S -debug-only=constraint-elimination,constraint-system\r\nProcessing fact to add to the system: icmp ule i32 %call4, %shl\r\nAdding 'icmp ule i32 %call4, %shl'\r\n constraint: -8 * %arg + %call4 <= 0\r\n\r\n---\r\n-1 * %arg <= 0\r\n-8 * %arg + %call4 <= 0\r\n-1 * %call4 <= 0\r\n8 * %arg <= -1\r\nunsat\r\nAdding 'icmp sge i32 %call4, 0'\r\n constraint: -1 * %call4 <= 0\r\n\r\nAdding 'icmp sle i32 %call4, %shl'\r\n constraint: -8 * %arg + %call4 <= 0\r\n\r\nProcessing fact to add to the system: icmp ule i32 %call4, 80\r\nAdding 'icmp ule i32 %call4, 80'\r\n constraint: %call4 <= 80\r\n\r\nAdding 'icmp sge i32 %call4, 0'\r\n constraint: -1 * %call4 <= 0\r\n\r\nAdding 'icmp sle i32 %call4, 80'\r\n constraint: %call4 <= 80\r\n\r\nTop of stack : 0 1\r\nCB: 0 1\r\nProcessing condition to simplify: %icmp = icmp slt i32 %arg, 0\r\nChecking %icmp = icmp slt i32 %arg, 0\r\n---\r\n-1 * %call4 <= 0\r\n-8 * %arg + %call4 <= 0\r\n-1 * %call4 <= 0\r\n%call4 <= 80\r\n-1 * %arg <= 0\r\nsat\r\n---\r\n-1 * %call4 <= 0\r\n-8 * %arg + %call4 <= 0\r\n-1 * %call4 <= 0\r\n%call4 <= 80\r\n%arg <= -1\r\nunsat\r\nCondition icmp sge i32 %arg, 0 implied by dominating constraints\r\n-1 * %call4 <= 0\r\n-8 * %arg + %call4 <= 0\r\n-1 * %call4 <= 0\r\n%call4 <= 80\r\n```\r\nI'm not 100% sure if the aforementioned patch causes the miscompile, of if it merely triggers it on this specific reproducer. The fact that something like `-1 * %call4 <= 0` is reported as a \"dominating constraint\" seems suspicious to a person who's not familiar with the logic of ConstraintElimination and it doesn't look directly related to that patch. However, if I replace the `shl nuw nsw i32 %arg, 3\r\n` with `mul nuw nsw i32 %arg, 8`, the miscompile doesn't happen: https://alive2.llvm.org/ce/z/EL2bCh.",
"author": "DaniilSuchkov",
"labels": [
"miscompilation",
"release:backport",
"llvm:transforms"
],
"comments": [
{
"author": "nikic",
"body": "From the debug log, I suspect that we're using the unsigned constraint system to prove a signed fact for some reason.\r\n\r\ncc @fhahn "
},
{
"author": "nikic",
"body": "Okay, this is an interesting case.\r\n\r\nWe are adding an `icmp ule i32 %call4, %shl` fact, which get transferred as `icmp sge i32 %call4, 0` and `icmp sle i32 %call4, %shl` to the signed system, because `%shl` is known non-negative.\r\n\r\nThen we are checking whether a solution of these constraints plus `%arg <= -1` exists, which it does not.\r\n\r\nThis is \"correct\" in the sense that *if* that umin call returns a non-poison result, then `icmp slt i32 %arg, 0` is indeed known to be false. But we obviously can't actually make that assumption.\r\n\r\n@dtcxzyw @fhahn This makes me think that the way we are currently adding facts for MinMaxIntrinsic (and I guess abs as well) is pretty fundamentally incorrect, because it effectively imposes a constraint that the umin operation returns a well-defined value. Any thoughts on how to fix this without dropping support for them entirely?"
},
{
"author": "nikic",
"body": "(The difference between shl and mul in the reproducer is because ValueTracking apparently currently doesn't know that mul nuw nsw is non-negative, but knows that shl nuw nsw is.)"
},
{
"author": "dtcxzyw",
"body": "> @dtcxzyw @fhahn This makes me think that the way we are currently adding facts for MinMaxIntrinsic (and I guess abs as well) is pretty fundamentally incorrect, because it effectively imposes a constraint that the umin operation returns a well-defined value. Any thoughts on how to fix this without dropping support for them entirely?\r\n\r\nCan we conservatively check these intrinsics using `isGuaranteedNotToBePoison`?\r\n"
},
{
"author": "nikic",
"body": "If it's not too complicated, I think a better solution would be to only add the intrinsic constraints when the result variable is added to the constraint system."
},
{
"author": "fhahn",
"body": "> If it's not too complicated, I think a better solution would be to only add the intrinsic constraints when the result variable is added to the constraint system.\r\n\r\nOne way to do that would be to check the uses of the intrinsic and find all the branches that it feeds, and add it as fact for the successors."
},
{
"author": "nikic",
"body": "@dtcxzyw Do you plan to submit a PR for this issue?"
},
{
"author": "dtcxzyw",
"body": "> @dtcxzyw Do you plan to submit a PR for this issue?\r\n\r\nI will post a patch later."
},
{
"author": "fhahn",
"body": "I've pushed a fix that only adds the facts if the result is guaranteed to not be poison so the mis-compile is fixed. I also added a TODO to improve things if possible.\r\n\r\nReopening so we can pick the fix for the release branch"
},
{
"author": "nikic",
"body": "@fhahn Why does your fix only do this for min/max but not abs? Can't it have the same problem?"
},
{
"author": "fhahn",
"body": "> @fhahn Why does your fix only do this for min/max but not abs? Can't it have the same problem?\r\n\r\nI wasn't able to come up with a problematic test case so far for `abs`, but there's a few more things to try."
},
{
"author": "DaniilSuchkov",
"body": "@fhahn I'm not familiar with how this pass works, so I have a question: will this pass still use min/max/etc. to infer facts about the arguments of those intrinsics? I'm just a bit confused by the terminology: I see that it adds \"constraints\" based on things like `icmp`, which on their own don't actually constrain anything unless you branch on the result (or do something similar)."
},
{
"author": "nikic",
"body": "> @fhahn I'm not familiar with how this pass works, so I have a question: will this pass still use min/max/etc. to infer facts about the arguments of those intrinsics? I'm just a bit confused by the terminology: I see that it adds \"constraints\" based on things like `icmp`, which on their own don't actually constrain anything unless you branch on the result (or do something similar).\r\n\r\nConstraints for icmps will only be added in branches that the icmp dominates (or code that an assume with an icmp dominates). The intrinsic handling was a bit special in that constraints are added unconditionally."
}
]
} | true | null |
77320 | https://github.com/llvm/llvm-project/issues/77320 | miscompilation | ade7ae4760a0b0e74cddd8f852830ca946295930 | 2024-01-08T14:43:50 | [
"llvm/test/Transforms/InstSimplify"
] | {
"fix_commit": "97e3220d6312ae00bcbe08673f218bd0f705776b",
"components": [
"InstructionSimplify"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": [
[
4313,
4319
]
],
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": [
"simplifyWithOpReplaced"
],
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 97e3220d6312ae00bcbe08673f218bd0f705776b
Author: Nikita Popov <[email protected]>
Date: Mon Jan 8 15:49:47 2024 +0100
[InstSimplify] Consider bitcast as potential cross-lane operation
The bitcast might change the number of vector lanes, in which case
it will be a cross-lane operation.
Fixes https://github.com/llvm/llvm-project/issues/77320.
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 241bdd81b75a..d0c27cae0dff 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4313,7 +4313,7 @@ static Value *simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
// For vector types, the simplification must hold per-lane, so forbid
// potentially cross-lane operations like shufflevector.
if (!I->getType()->isVectorTy() || isa<ShuffleVectorInst>(I) ||
- isa<CallBase>(I))
+ isa<CallBase>(I) || isa<BitCastInst>(I))
return nullptr;
}
| [
{
"file": "llvm/test/Transforms/InstSimplify/select.ll",
"commands": [
"opt < %s -passes=instsimplify -S"
],
"tests": [
{
"test_name": "select_vector_cmp_with_bitcasts",
"test_body": "define <4 x i32> @select_vector_cmp_with_bitcasts(<2 x i64> %x, <4 x i32> %y) {\n %x.bc = bitcast <2 x i64> %x to <4 x i32>\n %y.bc = bitcast <4 x i32> %y to <2 x i64>\n %sub = sub <2 x i64> %x, %y.bc\n %sub.bc = bitcast <2 x i64> %sub to <4 x i32>\n %cmp = icmp eq <4 x i32> %y, %x.bc\n %sel = select <4 x i1> %cmp, <4 x i32> %sub.bc, <4 x i32> zeroinitializer\n ret <4 x i32> %sel\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "select_or_disjoint_eq",
"test_body": "define i8 @select_or_disjoint_eq(i8 %x, i8 %y) {\n %cmp = icmp eq i8 %x, %y\n %or = or disjoint i8 %x, %y\n %sel = select i1 %cmp, i8 %x, i8 %or\n ret i8 %sel\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[InstSimplify] Miscompile with select of vectors and bitcast",
"body": "https://alive2.llvm.org/ce/z/xhCFyk\r\n\r\n```llvm\r\ndefine <4 x i32> @src(<2 x i64> %x, <4 x i32> %y) {\r\n %x.bc = bitcast <2 x i64> %x to <4 x i32>\r\n %y.bc = bitcast <4 x i32> %y to <2 x i64>\r\n %sub = sub <2 x i64> %x, %y.bc\r\n %sub.bc = bitcast <2 x i64> %sub to <4 x i32>\r\n %cmp = icmp eq <4 x i32> %y, %x.bc\r\n %sel = select <4 x i1> %cmp, <4 x i32> %sub.bc, <4 x i32> zeroinitializer\r\n ret <4 x i32> %sel\r\n}\r\n\r\ndefine <4 x i32> @tgt(<2 x i64> %x, <4 x i32> %y) {\r\n ret <4 x i32> zeroinitializer\r\n}\r\n```",
"author": "nikic",
"labels": [
"test-suite",
"miscompilation",
"llvm:instcombine"
],
"comments": []
} | true | null |
129057 | https://github.com/llvm/llvm-project/issues/129057 | miscompilation | 6a5bb4c2f1e7a48d5c8ffd7b5ab4a7addc3e661f | 2025-02-27T13:44:09 | [
"llvm/test/Transforms/SLPVectorizer"
] | {
"fix_commit": "69effe054c136defda8766688ac0de4626a0eb05",
"components": [
"SLPVectorizer"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
[
18071,
18076
]
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
"BoUpSLP::collectValuesToDemote"
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 69effe054c136defda8766688ac0de4626a0eb05
Author: Alexey Bataev <[email protected]>
Date: Thu Feb 27 08:33:07 2025 -0800
[SLP]Check for potential safety of the truncation for vectorized scalars with multi uses
If the vectorized scalars has multiple uses, need to check if it is safe
to truncate the vectorized value, before actually trying doing it.
Otherwise, the compiler may loose some important bits, which may lead to
a miscompilation.
Fixes #129057
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index e8c91ebd508c..2d343ca31f07 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -18071,6 +18071,12 @@ bool BoUpSLP::collectValuesToDemote(
(void)for_each(E.Scalars, std::bind(IsPotentiallyTruncated, _1,
std::ref(BitWidth)));
} else {
+ // Several vectorized uses? Check if we can truncate it, otherwise -
+ // exit.
+ if (any_of(E.Scalars, [&](Value *V) {
+ return !V->hasOneUse() && !IsPotentiallyTruncated(V, BitWidth);
+ }))
+ return false;
bool NeedToExit = false;
if (Checker && !AttemptCheckBitwidth(Checker, NeedToExit))
return false;
| [
{
"file": "llvm/test/Transforms/SLPVectorizer/X86/ext-used-scalar-different-bitwidth.ll",
"commands": [
"opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-100 < %s"
],
"tests": [
{
"test_name": "test",
"test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@f = global i32 zeroinitializer\[email protected] = constant [4 x i8] c\"%d\\0A\\00\"\n\ndefine i32 @main() {\nentry:\n store i32 152, ptr @f, align 4\n %agg.tmp.sroa.0.0.copyload.i = load i32, ptr @f, align 4\n %add.i.i = shl i32 %agg.tmp.sroa.0.0.copyload.i, 24\n %sext.i = add i32 %add.i.i, 83886080\n %conv2.i = ashr i32 %sext.i, 24\n %and.i = and i32 %conv2.i, 66440127\n %cmp3.i.i = icmp ugt i32 %and.i, 33554431\n %shl.i.i = select i1 %cmp3.i.i, i32 0, i32 6\n %cond.i.i = shl i32 %and.i, %shl.i.i\n %0 = trunc i32 %cond.i.i to i8\n %sext.1.i = add i32 0, 83886080\n %conv2.1.i = ashr i32 %sext.1.i, 24\n %and.1.i = and i32 %conv2.1.i, 1\n %cmp3.i.1.i = icmp ugt i32 0, 0\n %shl.i.1.i = select i1 %cmp3.i.1.i, i32 0, i32 0\n %cond.i.1.i = shl i32 %and.1.i, %shl.i.1.i\n %1 = trunc i32 %cond.i.1.i to i8\n %conv17.1.i = and i8 %0, %1\n %sext.2.i = add i32 0, 83886080\n %conv2.2.i = ashr i32 %sext.2.i, 24\n %and.2.i = and i32 %conv2.2.i, 1\n %shl.i.2.i = select i1 false, i32 0, i32 0\n %cond.i.2.i = shl i32 %and.2.i, %shl.i.2.i\n %2 = trunc i32 %cond.i.2.i to i8\n %conv17.2.i = and i8 %conv17.1.i, %2\n %sext.3.i = add i32 0, 83886080\n %conv2.3.i = ashr i32 %sext.3.i, 24\n %and.3.i = and i32 %conv2.3.i, 1\n %shl.i.3.i = select i1 false, i32 0, i32 0\n %cond.i.3.i = shl i32 %and.3.i, %shl.i.3.i\n %3 = trunc i32 %cond.i.3.i to i8\n %conv17.3.i = and i8 %conv17.2.i, %3\n %sext.4.i = add i32 0, 83886080\n %conv2.4.i = ashr i32 %sext.4.i, 24\n %and.4.i = and i32 %conv2.4.i, 1\n %shl.i.4.i = select i1 false, i32 0, i32 0\n %cond.i.4.i = shl i32 %and.4.i, %shl.i.4.i\n %4 = trunc i32 %cond.i.4.i to i8\n %conv17.4.i = and i8 %conv17.3.i, %4\n %sext.5.i = add i32 0, 83886080\n %conv2.5.i = ashr i32 %sext.5.i, 24\n %and.5.i = and i32 %conv2.5.i, 1\n %shl.i.5.i = select i1 false, i32 0, i32 0\n %cond.i.5.i = shl i32 %and.5.i, %shl.i.5.i\n %5 = trunc i32 %cond.i.5.i to i8\n %conv17.5.i = and i8 %conv17.4.i, %5\n %sext.6.i = add i32 0, 83886080\n %conv2.6.i = ashr i32 %sext.6.i, 24\n %and.6.i = and i32 %conv2.6.i, 1\n %shl.i.6.i = select i1 false, i32 0, i32 0\n %cond.i.6.i = shl i32 %and.6.i, %shl.i.6.i\n %6 = trunc i32 %cond.i.6.i to i8\n %conv17.6.i = and i8 %conv17.5.i, %6\n %sext.7.i = add i32 0, 83886080\n %conv2.7.i = ashr i32 %sext.7.i, 24\n %and.7.i = and i32 %conv2.7.i, 1\n %shl.i.7.i = select i1 false, i32 0, i32 0\n %cond.i.7.i = shl i32 %and.7.i, %shl.i.7.i\n %7 = trunc i32 %cond.i.7.i to i8\n %conv17.7.i = and i8 %conv17.6.i, %7\n %conv = zext i8 %conv17.7.i to i32\n %call1 = call i32 (ptr, ...) @printf(ptr @.str, i32 %conv)\n ret i32 0\n}\n\ndeclare i32 @printf(ptr, ...)",
"lli_expected_out": "1\n",
"additional_args": null
}
]
}
] | {
"title": "[SLPVectorizer] Miscompilation at O3",
"body": "Reproducer:\n```\n; bin/opt -passes=slp-vectorizer reduced.ll -S\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@f = global i32 zeroinitializer\[email protected] = constant [4 x i8] c\"%d\\0A\\00\"\n\ndefine i32 @main() {\nentry:\n store i32 152, ptr @f, align 4\n %agg.tmp.sroa.0.0.copyload.i = load i32, ptr @f, align 4\n %add.i.i = shl i32 %agg.tmp.sroa.0.0.copyload.i, 24\n %sext.i = add i32 %add.i.i, 83886080\n %conv2.i = ashr i32 %sext.i, 24\n %and.i = and i32 %conv2.i, 66440127\n %cmp3.i.i = icmp ugt i32 %and.i, 33554431\n %shl.i.i = select i1 %cmp3.i.i, i32 0, i32 6\n %cond.i.i = shl i32 %and.i, %shl.i.i\n %0 = trunc i32 %cond.i.i to i8\n %sext.1.i = add i32 0, 83886080\n %conv2.1.i = ashr i32 %sext.1.i, 24\n %and.1.i = and i32 %conv2.1.i, 1\n %cmp3.i.1.i = icmp ugt i32 0, 0\n %shl.i.1.i = select i1 %cmp3.i.1.i, i32 0, i32 0\n %cond.i.1.i = shl i32 %and.1.i, %shl.i.1.i\n %1 = trunc i32 %cond.i.1.i to i8\n %conv17.1.i = and i8 %0, %1\n %sext.2.i = add i32 0, 83886080\n %conv2.2.i = ashr i32 %sext.2.i, 24\n %and.2.i = and i32 %conv2.2.i, 1\n %shl.i.2.i = select i1 false, i32 0, i32 0\n %cond.i.2.i = shl i32 %and.2.i, %shl.i.2.i\n %2 = trunc i32 %cond.i.2.i to i8\n %conv17.2.i = and i8 %conv17.1.i, %2\n %sext.3.i = add i32 0, 83886080\n %conv2.3.i = ashr i32 %sext.3.i, 24\n %and.3.i = and i32 %conv2.3.i, 1\n %shl.i.3.i = select i1 false, i32 0, i32 0\n %cond.i.3.i = shl i32 %and.3.i, %shl.i.3.i\n %3 = trunc i32 %cond.i.3.i to i8\n %conv17.3.i = and i8 %conv17.2.i, %3\n %sext.4.i = add i32 0, 83886080\n %conv2.4.i = ashr i32 %sext.4.i, 24\n %and.4.i = and i32 %conv2.4.i, 1\n %shl.i.4.i = select i1 false, i32 0, i32 0\n %cond.i.4.i = shl i32 %and.4.i, %shl.i.4.i\n %4 = trunc i32 %cond.i.4.i to i8\n %conv17.4.i = and i8 %conv17.3.i, %4\n %sext.5.i = add i32 0, 83886080\n %conv2.5.i = ashr i32 %sext.5.i, 24\n %and.5.i = and i32 %conv2.5.i, 1\n %shl.i.5.i = select i1 false, i32 0, i32 0\n %cond.i.5.i = shl i32 %and.5.i, %shl.i.5.i\n %5 = trunc i32 %cond.i.5.i to i8\n %conv17.5.i = and i8 %conv17.4.i, %5\n %sext.6.i = add i32 0, 83886080\n %conv2.6.i = ashr i32 %sext.6.i, 24\n %and.6.i = and i32 %conv2.6.i, 1\n %shl.i.6.i = select i1 false, i32 0, i32 0\n %cond.i.6.i = shl i32 %and.6.i, %shl.i.6.i\n %6 = trunc i32 %cond.i.6.i to i8\n %conv17.6.i = and i8 %conv17.5.i, %6\n %sext.7.i = add i32 0, 83886080\n %conv2.7.i = ashr i32 %sext.7.i, 24\n %and.7.i = and i32 %conv2.7.i, 1\n %shl.i.7.i = select i1 false, i32 0, i32 0\n %cond.i.7.i = shl i32 %and.7.i, %shl.i.7.i\n %7 = trunc i32 %cond.i.7.i to i8\n %conv17.7.i = and i8 %conv17.6.i, %7\n %conv = zext i8 %conv17.7.i to i32\n %call1 = call i32 (ptr, ...) @printf(ptr @.str, i32 %conv)\n ret i32 0\n}\n\ndeclare i32 @printf(ptr, ...)\n```\n```\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\n@f = global i32 0\[email protected] = constant [4 x i8] c\"%d\\0A\\00\"\n\ndefine i32 @main() {\nentry:\n store i32 152, ptr @f, align 4\n %agg.tmp.sroa.0.0.copyload.i = load i32, ptr @f, align 4\n %add.i.i = shl i32 %agg.tmp.sroa.0.0.copyload.i, 24\n %0 = insertelement <8 x i32> <i32 poison, i32 83886080, i32 83886080, i32 83886080, i32 83886080, i32 83886080, i32 83886080, i32 83886080>, i32 %add.i.i, i32 0\n %1 = add <8 x i32> <i32 83886080, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0>, %0\n %2 = ashr <8 x i32> %1, splat (i32 24)\n %3 = trunc <8 x i32> %2 to <8 x i8>\n %4 = and <8 x i8> %3, <i8 -65, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>\n %5 = zext <8 x i8> %4 to <8 x i32>\n %6 = shufflevector <8 x i32> %5, <8 x i32> poison, <2 x i32> <i32 0, i32 poison>\n %7 = shufflevector <2 x i32> %6, <2 x i32> <i32 poison, i32 0>, <2 x i32> <i32 0, i32 3>\n %8 = icmp ugt <2 x i32> %7, <i32 33554431, i32 0>\n %9 = call <8 x i1> @llvm.vector.insert.v8i1.v2i1(<8 x i1> <i1 poison, i1 poison, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false>, <2 x i1> %8, i64 0)\n %10 = select <8 x i1> %9, <8 x i8> zeroinitializer, <8 x i8> <i8 6, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0>\n %11 = shl <8 x i8> %4, %10\n %12 = call i8 @llvm.vector.reduce.and.v8i8(<8 x i8> %11)\n %conv = zext i8 %12 to i32\n %call1 = call i32 (ptr, ...) @printf(ptr @.str, i32 %conv)\n ret i32 0\n}\n\ndeclare i32 @printf(ptr, ...)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare <8 x i1> @llvm.vector.insert.v8i1.v2i1(<8 x i1>, <2 x i1>, i64 immarg) #0\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i8 @llvm.vector.reduce.and.v8i8(<8 x i8>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n```\nllubi output:\nBefore SLP:\n```\nEntering function main\n store i32 152, ptr @f, align 4\n %agg.tmp.sroa.0.0.copyload.i = load i32, ptr @f, align 4 -> i32 152\n %add.i.i = shl i32 %agg.tmp.sroa.0.0.copyload.i, 24 -> i32 -1744830464\n %sext.i = add i32 %add.i.i, 83886080 -> i32 -1660944384\n %conv2.i = ashr i32 %sext.i, 24 -> i32 -99\n %and.i = and i32 %conv2.i, 66440127 -> i32 66440093\n %cmp3.i.i = icmp ugt i32 %and.i, 33554431 -> T\n %shl.i.i = select i1 %cmp3.i.i, i32 0, i32 6 -> i32 0\n %cond.i.i = shl i32 %and.i, %shl.i.i -> i32 66440093\n %0 = trunc i32 %cond.i.i to i8 -> i8 -99\n %sext.1.i = add i32 0, 83886080 -> i32 83886080\n %conv2.1.i = ashr i32 %sext.1.i, 24 -> i32 5\n %and.1.i = and i32 %conv2.1.i, 1 -> i32 1\n %cmp3.i.1.i = icmp ugt i32 0, 0 -> F\n %shl.i.1.i = select i1 %cmp3.i.1.i, i32 0, i32 0 -> i32 0\n %cond.i.1.i = shl i32 %and.1.i, %shl.i.1.i -> i32 1\n %1 = trunc i32 %cond.i.1.i to i8 -> i8 1\n %conv17.1.i = and i8 %0, %1 -> i8 1\n %sext.2.i = add i32 0, 83886080 -> i32 83886080\n %conv2.2.i = ashr i32 %sext.2.i, 24 -> i32 5\n %and.2.i = and i32 %conv2.2.i, 1 -> i32 1\n %shl.i.2.i = select i1 false, i32 0, i32 0 -> i32 0\n %cond.i.2.i = shl i32 %and.2.i, %shl.i.2.i -> i32 1\n %2 = trunc i32 %cond.i.2.i to i8 -> i8 1\n %conv17.2.i = and i8 %conv17.1.i, %2 -> i8 1\n %sext.3.i = add i32 0, 83886080 -> i32 83886080\n %conv2.3.i = ashr i32 %sext.3.i, 24 -> i32 5\n %and.3.i = and i32 %conv2.3.i, 1 -> i32 1\n %shl.i.3.i = select i1 false, i32 0, i32 0 -> i32 0\n %cond.i.3.i = shl i32 %and.3.i, %shl.i.3.i -> i32 1\n %3 = trunc i32 %cond.i.3.i to i8 -> i8 1\n %conv17.3.i = and i8 %conv17.2.i, %3 -> i8 1\n %sext.4.i = add i32 0, 83886080 -> i32 83886080\n %conv2.4.i = ashr i32 %sext.4.i, 24 -> i32 5\n %and.4.i = and i32 %conv2.4.i, 1 -> i32 1\n %shl.i.4.i = select i1 false, i32 0, i32 0 -> i32 0\n %cond.i.4.i = shl i32 %and.4.i, %shl.i.4.i -> i32 1\n %4 = trunc i32 %cond.i.4.i to i8 -> i8 1\n %conv17.4.i = and i8 %conv17.3.i, %4 -> i8 1\n %sext.5.i = add i32 0, 83886080 -> i32 83886080\n %conv2.5.i = ashr i32 %sext.5.i, 24 -> i32 5\n %and.5.i = and i32 %conv2.5.i, 1 -> i32 1\n %shl.i.5.i = select i1 false, i32 0, i32 0 -> i32 0\n %cond.i.5.i = shl i32 %and.5.i, %shl.i.5.i -> i32 1\n %5 = trunc i32 %cond.i.5.i to i8 -> i8 1\n %conv17.5.i = and i8 %conv17.4.i, %5 -> i8 1\n %sext.6.i = add i32 0, 83886080 -> i32 83886080\n %conv2.6.i = ashr i32 %sext.6.i, 24 -> i32 5\n %and.6.i = and i32 %conv2.6.i, 1 -> i32 1\n %shl.i.6.i = select i1 false, i32 0, i32 0 -> i32 0\n %cond.i.6.i = shl i32 %and.6.i, %shl.i.6.i -> i32 1\n %6 = trunc i32 %cond.i.6.i to i8 -> i8 1\n %conv17.6.i = and i8 %conv17.5.i, %6 -> i8 1\n %sext.7.i = add i32 0, 83886080 -> i32 83886080\n %conv2.7.i = ashr i32 %sext.7.i, 24 -> i32 5\n %and.7.i = and i32 %conv2.7.i, 1 -> i32 1\n %shl.i.7.i = select i1 false, i32 0, i32 0 -> i32 0\n %cond.i.7.i = shl i32 %and.7.i, %shl.i.7.i -> i32 1\n %7 = trunc i32 %cond.i.7.i to i8 -> i8 1\n %conv17.7.i = and i8 %conv17.6.i, %7 -> i8 1\n %conv = zext i8 %conv17.7.i to i32 -> i32 1\n %call1 = call i32 (ptr, ...) @printf(ptr @.str, i32 %conv)\n Printf: 1\n -> i32 2\n ret i32 0\nExiting function main\n```\nAfter SLP:\n```\nEntering function main\n store i32 152, ptr @f, align 4\n %agg.tmp.sroa.0.0.copyload.i = load i32, ptr @f, align 4 -> i32 152\n %add.i.i = shl i32 %agg.tmp.sroa.0.0.copyload.i, 24 -> i32 -1744830464\n %0 = insertelement <8 x i32> <i32 poison, i32 83886080, i32 83886080, i32 83886080, i32 83886080, i32 83886080, i32 83886080, i32 83886080>, i32 %add.i.i, i32 0 -> { i32 -1744830464, i32 83886080, i32 83886080, i32 83886080, i32 83886080, i32 83886080, i32 83886080, i32 83886080 }\n %1 = add <8 x i32> <i32 83886080, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0>, %0 -> { i32 -1660944384, i32 83886080, i32 83886080, i32 83886080, i32 83886080, i32 83886080, i32 83886080, i32 83886080 }\n %2 = ashr <8 x i32> %1, splat (i32 24) -> { i32 -99, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5 }\n %3 = trunc <8 x i32> %2 to <8 x i8> -> { i8 -99, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5 }\n %4 = and <8 x i8> %3, <i8 -65, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1> -> { i8 -99, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1 }\n %5 = zext <8 x i8> %4 to <8 x i32> -> { i32 157, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1 }\n %6 = shufflevector <8 x i32> %5, <8 x i32> poison, <2 x i32> <i32 0, i32 poison> -> { i32 157, poison }\n %7 = shufflevector <2 x i32> %6, <2 x i32> <i32 poison, i32 0>, <2 x i32> <i32 0, i32 3> -> { i32 157, i32 0 }\n %8 = icmp ugt <2 x i32> %7, <i32 33554431, i32 0> -> { F, F }\n %9 = call <8 x i1> @llvm.vector.insert.v8i1.v2i1(<8 x i1> <i1 poison, i1 poison, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false>, <2 x i1> %8, i64 0) -> { F, F, F, F, F, F, F, F }\n %10 = select <8 x i1> %9, <8 x i8> zeroinitializer, <8 x i8> <i8 6, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0> -> { i8 6, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0 }\n %11 = shl <8 x i8> %4, %10 -> { i8 64, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1 }\n %12 = call i8 @llvm.vector.reduce.and.v8i8(<8 x i8> %11) -> i8 0\n %conv = zext i8 %12 to i32 -> i32 0\n %call1 = call i32 (ptr, ...) @printf(ptr @.str, i32 %conv)\n Printf: 0\n -> i32 2\n ret i32 0\nExiting function main\n```\nllvm version: a88f4f1962b47aa8db49b8687a7f8b9097a3d13b\n\nC reproducer:\n```\n#include \"csmith.h\"\nstruct d {\n uint8_t a;\n uint16_t b\n} f;\nstatic uint64_t c[] = {66440127};\nuint64_t e;\nuint8_t h = 5;\nuint32_t g(uint8_t, struct d);\nint32_t j() {\n int16_t i = 10;\n struct d k = {152};\n for (e = 0; e < 22; ++e) {\n int32_t l[0];\n struct d *m = &f;\n h &= safe_lshift_func_int32_t_s_u(\n safe_add_func_int8_t_s_s(g(0, *m = k), 5) & c[0],\n safe_add_func_int16_t_s_s(6, (k.a > k.b) < l));\n }\n return i;\n}\nuint32_t g(uint8_t, struct d n) { return n.a; }\nint main() {\n j();\n printf(\"%d\\n\", h);\n}\n```\n```\n> gcc -w -I/usr/include/csmith -fsanitize=address,undefined test.c && ./a.out\n5\n> bin/clang -w -I/usr/include/csmith -O3 test.c && ./a.out\n0\n```\n",
"author": "dtcxzyw",
"labels": [
"miscompilation",
"llvm:SLPVectorizer"
],
"comments": []
} | true | null |
108700 | https://github.com/llvm/llvm-project/issues/108700 | crash | 4c6f313cb340c435f47ac032857030768c81c341 | 2024-09-14T13:45:54 | [
"llvm/test/Transforms/SLPVectorizer"
] | {
"fix_commit": "f564a48f0ea4d2100c0cadfa6e6f20f97244025e",
"components": [
"SLPVectorizer"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
[
7481,
7487
],
[
7492,
7506
]
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
"BoUpSLP::buildTree_rec"
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit f564a48f0ea4d2100c0cadfa6e6f20f97244025e
Author: Alexey Bataev <[email protected]>
Date: Mon Sep 16 09:19:42 2024 -0700
[SLP]Fix PR108700: correctly identify id of the operand node
If the operand node for truncs is not created during construction, but
one of the previous ones is reused instead, need to correctly identify
its index, to correctly emit the code.
Fixes https://github.com/llvm/llvm-project/issues/108700
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 5f2bf082fb87..282bb8eac7e2 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -7481,7 +7481,16 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
PrevMaxBW),
std::min<unsigned>(DL->getTypeSizeInBits(VL0->getType()),
PrevMinBW));
- ExtraBitWidthNodes.insert(VectorizableTree.size() + 1);
+ }
+ TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
+ ReuseShuffleIndices);
+ LLVM_DEBUG(dbgs() << "SLP: added a vector of casts.\n");
+
+ TE->setOperandsInOrder();
+ for (unsigned I : seq<unsigned>(0, VL0->getNumOperands()))
+ buildTree_rec(TE->getOperand(I), Depth + 1, {TE, I});
+ if (ShuffleOrOp == Instruction::Trunc) {
+ ExtraBitWidthNodes.insert(getOperandEntry(TE, 0)->Idx);
} else if (ShuffleOrOp == Instruction::SIToFP ||
ShuffleOrOp == Instruction::UIToFP) {
unsigned NumSignBits =
@@ -7492,15 +7501,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
}
if (NumSignBits * 2 >=
DL->getTypeSizeInBits(VL0->getOperand(0)->getType()))
- ExtraBitWidthNodes.insert(VectorizableTree.size() + 1);
+ ExtraBitWidthNodes.insert(getOperandEntry(TE, 0)->Idx);
}
- TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
- ReuseShuffleIndices);
- LLVM_DEBUG(dbgs() << "SLP: added a vector of casts.\n");
-
- TE->setOperandsInOrder();
- for (unsigned I : seq<unsigned>(0, VL0->getNumOperands()))
- buildTree_rec(TE->getOperand(I), Depth + 1, {TE, I});
return;
}
case Instruction::ICmp:
| [
{
"file": "llvm/test/Transforms/SLPVectorizer/X86/minbitwidth-user-not-min.ll",
"commands": [
"opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s"
],
"tests": [
{
"test_name": "test",
"test_body": "define void @test(ptr %block, ptr noalias %pixels, i1 %b) {\nentry:\n %0 = load i16, ptr %block, align 2\n %tobool.not.i78 = icmp ult i16 %0, 0\n %conv.i80 = sext i1 true to i8\n %conv1.i81 = trunc i16 %0 to i8\n %retval.0.i82 = select i1 %tobool.not.i78, i8 %conv1.i81, i8 %conv.i80\n store i8 %retval.0.i82, ptr %pixels, align 1\n %arrayidx2 = getelementptr i8, ptr %block, i64 2\n %1 = load i16, ptr %arrayidx2, align 2\n %tobool.not.i73 = icmp ult i16 %1, 0\n %conv.i75 = sext i1 %b to i8\n %conv1.i76 = trunc i16 %1 to i8\n %retval.0.i77 = select i1 %tobool.not.i73, i8 %conv1.i76, i8 %conv.i75\n %arrayidx5 = getelementptr i8, ptr %pixels, i64 1\n store i8 %retval.0.i77, ptr %arrayidx5, align 1\n %arrayidx6 = getelementptr i8, ptr %block, i64 4\n %2 = load i16, ptr %arrayidx6, align 2\n %tobool.not.i68 = icmp ult i16 %2, 0\n %conv.i70 = sext i1 false to i8\n %conv1.i71 = trunc i16 %2 to i8\n %retval.0.i72 = select i1 %tobool.not.i68, i8 %conv1.i71, i8 %conv.i70\n %arrayidx9 = getelementptr i8, ptr %pixels, i64 2\n store i8 %retval.0.i72, ptr %arrayidx9, align 1\n %arrayidx10 = getelementptr i8, ptr %block, i64 6\n %3 = load i16, ptr %arrayidx10, align 2\n %tobool.not.i63 = icmp ult i16 %3, 0\n %conv.i65 = sext i1 false to i8\n %conv1.i66 = trunc i16 %3 to i8\n %retval.0.i67 = select i1 %tobool.not.i63, i8 %conv1.i66, i8 %conv.i65\n %arrayidx13 = getelementptr i8, ptr %pixels, i64 3\n store i8 %retval.0.i67, ptr %arrayidx13, align 1\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/SLPVectorizer/X86/trunc-node-reused.ll",
"commands": [
"opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s"
],
"tests": [
{
"test_name": "test",
"test_body": "define i16 @test() {\nentry:\n %conv73 = xor i64 0, 0\n %and.i = and i64 0, 0\n %xor2.i = or i64 %and.i, 0\n %sub.i = or i64 %xor2.i, 0\n %xor3.i = xor i64 %sub.i, %conv73\n %and4.i = and i64 %xor3.i, 0\n %cmp.i = icmp slt i64 %and4.i, 0\n %0 = trunc i64 %conv73 to i16\n %1 = or i16 0, %0\n %conv73i = xor i64 0, 0\n %andi.i = and i64 0, 0\n %xor2i.i = or i64 %andi.i, 0\n %subi.i = or i64 %xor2i.i, 0\n %xor3i.i = xor i64 %subi.i, %conv73i\n %and4i.i = and i64 %xor3i.i, 0\n %cmpi.i = icmp slt i64 %and4i.i, 0\n %2 = trunc i64 %conv73i to i16\n %3 = or i16 0, %2\n %4 = select i1 %cmpi.i, i16 0, i16 %3\n %5 = select i1 %cmp.i, i16 0, i16 %1\n %6 = zext i32 0 to i64\n %add.ip = or i64 %6, 0\n %orp = or i64 %add.ip, 0\n %conv72p = shl i64 %orp, 0\n %sextp = ashr i64 %conv72p, 0\n %conv73p = xor i64 %sextp, 0\n %and.ip = and i64 0, 0\n %xor2.ip = or i64 %and.ip, 0\n %sub.ip = or i64 %xor2.ip, 0\n %xor3.ip = xor i64 %sub.ip, %conv73p\n %and4.ip = and i64 %xor3.ip, 0\n %cmp.ip = icmp slt i64 %and4.ip, 0\n %7 = trunc i64 %conv73p to i16\n %8 = or i16 0, %7\n %9 = select i1 %cmp.ip, i16 0, i16 %8\n %conv76i = and i16 %4, %5\n %conv76p = and i16 %conv76i, %9\n %10 = zext i32 0 to i64\n %add.ip1 = or i64 %10, 0\n %orp1 = or i64 %add.ip1, 0\n %conv72p1 = shl i64 %orp1, 0\n %sextp1 = ashr i64 %conv72p1, 0\n %conv73p1 = xor i64 %sextp1, 0\n %and.ip1 = and i64 0, 0\n %xor2.ip1 = or i64 %and.ip1, 0\n %sub.ip1 = or i64 %xor2.ip1, 0\n %xor3.ip1 = xor i64 %sub.ip1, %conv73p1\n %and4.ip1 = and i64 %xor3.ip1, 0\n %cmp.ip1 = icmp slt i64 %and4.ip1, 0\n %11 = trunc i64 %conv73p1 to i16\n %12 = or i16 0, %11\n %13 = select i1 %cmp.ip1, i16 0, i16 %12\n %conv76p2 = and i16 %conv76p, %13\n ret i16 %conv76p2\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[SLPVectorizer] Assertion `OpIdx < Operands.size() && \"Off bounds\"' failed.",
"body": "Reproducer: https://godbolt.org/z/8Es17cqcW\r\n```\r\n; bin/opt -passes=slp-vectorizer reduced.ll -S\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine i16 @main() {\r\nentry:\r\n %conv73.i.peel.i.i.i.i.i = xor i64 0, 0\r\n %and.i.i.peel.i.i.i.i.i = and i64 0, 0\r\n %xor2.i.i.peel.i.i.i.i.i = or i64 %and.i.i.peel.i.i.i.i.i, 0\r\n %sub.i.i.peel.i.i.i.i.i = or i64 %xor2.i.i.peel.i.i.i.i.i, 0\r\n %xor3.i.i.peel.i.i.i.i.i = xor i64 %sub.i.i.peel.i.i.i.i.i, %conv73.i.peel.i.i.i.i.i\r\n %and4.i.i.peel.i.i.i.i.i = and i64 %xor3.i.i.peel.i.i.i.i.i, 0\r\n %cmp.i.i.peel.i.i.i.i.i = icmp slt i64 %and4.i.i.peel.i.i.i.i.i, 0\r\n %0 = trunc i64 %conv73.i.peel.i.i.i.i.i to i16\r\n %1 = or i16 0, %0\r\n %conv73.i.i.i.i.i.i = xor i64 0, 0\r\n %and.i.i.i.i.i.i.i = and i64 0, 0\r\n %xor2.i.i.i.i.i.i.i = or i64 %and.i.i.i.i.i.i.i, 0\r\n %sub.i.i.i.i.i.i.i = or i64 %xor2.i.i.i.i.i.i.i, 0\r\n %xor3.i.i.i.i.i.i.i = xor i64 %sub.i.i.i.i.i.i.i, %conv73.i.i.i.i.i.i\r\n %and4.i.i.i.i.i.i.i = and i64 %xor3.i.i.i.i.i.i.i, 0\r\n %cmp.i.i.i.i.i.i.i = icmp slt i64 %and4.i.i.i.i.i.i.i, 0\r\n %2 = trunc i64 %conv73.i.i.i.i.i.i to i16\r\n %3 = or i16 0, %2\r\n %4 = select i1 %cmp.i.i.i.i.i.i.i, i16 0, i16 %3\r\n %5 = select i1 %cmp.i.i.peel.i.i.i.i.i, i16 0, i16 %1\r\n %6 = zext i32 0 to i64\r\n %add.i.i.peel.i369.i.i.i.i = or i64 %6, 0\r\n %or.i.peel.i371.i.i.i.i = or i64 %add.i.i.peel.i369.i.i.i.i, 0\r\n %conv72.i.peel.i372.i.i.i.i = shl i64 %or.i.peel.i371.i.i.i.i, 0\r\n %sext.i.peel.i373.i.i.i.i = ashr i64 %conv72.i.peel.i372.i.i.i.i, 0\r\n %conv73.i.peel.i374.i.i.i.i = xor i64 %sext.i.peel.i373.i.i.i.i, 0\r\n %and.i.i.peel.i376.i.i.i.i = and i64 0, 0\r\n %xor2.i.i.peel.i377.i.i.i.i = or i64 %and.i.i.peel.i376.i.i.i.i, 0\r\n %sub.i.i.peel.i378.i.i.i.i = or i64 %xor2.i.i.peel.i377.i.i.i.i, 0\r\n %xor3.i.i.peel.i379.i.i.i.i = xor i64 %sub.i.i.peel.i378.i.i.i.i, %conv73.i.peel.i374.i.i.i.i\r\n %and4.i.i.peel.i380.i.i.i.i = and i64 %xor3.i.i.peel.i379.i.i.i.i, 0\r\n %cmp.i.i.peel.i381.i.i.i.i = icmp slt i64 %and4.i.i.peel.i380.i.i.i.i, 0\r\n %7 = trunc i64 %conv73.i.peel.i374.i.i.i.i to i16\r\n %8 = or i16 0, %7\r\n %9 = select i1 %cmp.i.i.peel.i381.i.i.i.i, i16 0, i16 %8\r\n %conv76.i.i.i.i.i.i = and i16 %4, %5\r\n %conv76.i.peel.i384.i.i.i.i = and i16 %conv76.i.i.i.i.i.i, %9\r\n %10 = zext i32 0 to i64\r\n %add.i.i.peel.i417.i.i.i.i = or i64 %10, 0\r\n %or.i.peel.i419.i.i.i.i = or i64 %add.i.i.peel.i417.i.i.i.i, 0\r\n %conv72.i.peel.i420.i.i.i.i = shl i64 %or.i.peel.i419.i.i.i.i, 0\r\n %sext.i.peel.i421.i.i.i.i = ashr i64 %conv72.i.peel.i420.i.i.i.i, 0\r\n %conv73.i.peel.i422.i.i.i.i = xor i64 %sext.i.peel.i421.i.i.i.i, 0\r\n %and.i.i.peel.i424.i.i.i.i = and i64 0, 0\r\n %xor2.i.i.peel.i425.i.i.i.i = or i64 %and.i.i.peel.i424.i.i.i.i, 0\r\n %sub.i.i.peel.i426.i.i.i.i = or i64 %xor2.i.i.peel.i425.i.i.i.i, 0\r\n %xor3.i.i.peel.i427.i.i.i.i = xor i64 %sub.i.i.peel.i426.i.i.i.i, %conv73.i.peel.i422.i.i.i.i\r\n %and4.i.i.peel.i428.i.i.i.i = and i64 %xor3.i.i.peel.i427.i.i.i.i, 0\r\n %cmp.i.i.peel.i429.i.i.i.i = icmp slt i64 %and4.i.i.peel.i428.i.i.i.i, 0\r\n %11 = trunc i64 %conv73.i.peel.i422.i.i.i.i to i16\r\n %12 = or i16 0, %11\r\n %13 = select i1 %cmp.i.i.peel.i429.i.i.i.i, i16 0, i16 %12\r\n %conv76.i.peel.i432.i.i.i.i = and i16 %conv76.i.peel.i384.i.i.i.i, %13\r\n ret i16 %conv76.i.peel.i432.i.i.i.i\r\n}\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp:3180: llvm::slpvectorizer::BoUpSLP::ValueList& llvm::slpvectorizer::BoUpSLP::TreeEntry::getOperand(unsigned int): Assertion `OpIdx < Operands.size() && \"Off bounds\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S --passes=slp-vectorizer <source>\r\n1.\tRunning pass \"function(slp-vectorizer)\" on module \"<source>\"\r\n2.\tRunning pass \"slp-vectorizer\" on function \"main\"\r\n #0 0x0000000005016bb8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5016bb8)\r\n #1 0x00000000050142fc SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007955e2242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007955e22969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007955e2242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007955e22287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007955e222871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007955e2239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x000000000406f2b8 llvm::slpvectorizer::BoUpSLP::TreeEntry::getOperand(unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x406f2b8)\r\n #9 0x00000000040f675e llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&)::'lambda0'(llvm::function_ref<llvm::InstructionCost (unsigned int)>, llvm::function_ref<llvm::InstructionCost (llvm::InstructionCost)>)::operator()(llvm::function_ref<llvm::InstructionCost (unsigned int)>, llvm::function_ref<llvm::InstructionCost (llvm::InstructionCost)>) const SLPVectorizer.cpp:0:0\r\n#10 0x00000000040f74aa llvm::slpvectorizer::BoUpSLP::getEntryCost(llvm::slpvectorizer::BoUpSLP::TreeEntry const*, llvm::ArrayRef<llvm::Value*>, llvm::SmallPtrSetImpl<llvm::Value*>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x40f74aa)\r\n#11 0x0000000004114641 llvm::slpvectorizer::BoUpSLP::getTreeCost(llvm::ArrayRef<llvm::Value*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4114641)\r\n#12 0x00000000041198c8 (anonymous namespace)::HorizontalReduction::tryToReduce(llvm::slpvectorizer::BoUpSLP&, llvm::DataLayout const&, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo const&) SLPVectorizer.cpp:0:0\r\n#13 0x000000000411bfe1 llvm::SLPVectorizerPass::vectorizeHorReduction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*, llvm::SmallVectorImpl<llvm::WeakTrackingVH>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x411bfe1)\r\n#14 0x0000000004120876 llvm::SLPVectorizerPass::vectorizeRootInstruction(llvm::PHINode*, llvm::Instruction*, llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&, llvm::TargetTransformInfo*) (.constprop.0) SLPVectorizer.cpp:0:0\r\n#15 0x0000000004124e16 llvm::SLPVectorizerPass::vectorizeChainsInBlock(llvm::BasicBlock*, llvm::slpvectorizer::BoUpSLP&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4124e16)\r\n#16 0x000000000412b2e1 llvm::SLPVectorizerPass::runImpl(llvm::Function&, llvm::ScalarEvolution*, llvm::TargetTransformInfo*, llvm::TargetLibraryInfo*, llvm::AAResults*, llvm::LoopInfo*, llvm::DominatorTree*, llvm::AssumptionCache*, llvm::DemandedBits*, llvm::OptimizationRemarkEmitter*) (.part.0) SLPVectorizer.cpp:0:0\r\n#17 0x000000000412bf6b llvm::SLPVectorizerPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x412bf6b)\r\n#18 0x0000000002f0034e llvm::detail::PassModel<llvm::Function, llvm::SLPVectorizerPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2f0034e)\r\n#19 0x0000000004e18ff8 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e18ff8)\r\n#20 0x0000000000e06a0e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe06a0e)\r\n#21 0x0000000004e17a1e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e17a1e)\r\n#22 0x0000000000e0621e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe0621e)\r\n#23 0x0000000004e17450 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e17450)\r\n#24 0x00000000008fce52 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8fce52)\r\n#25 0x00000000008efcdc optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8efcdc)\r\n#26 0x00007955e2229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#27 0x00007955e2229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#28 0x00000000008e77ae _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8e77ae)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```",
"author": "dtcxzyw",
"labels": [
"llvm:SLPVectorizer",
"crash-on-valid"
],
"comments": []
} | true | null |
108004 | https://github.com/llvm/llvm-project/issues/108004 | crash | 512cecad4c384c84b79fea050a755cb7e46c6ac5 | 2024-09-10T11:32:26 | [
"llvm/test/Transforms/LoopVectorize"
] | {
"fix_commit": "7858e14547c509c95503b74ff8ffc7bf2fc5b110",
"components": [
"LoopVectorize"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
[
8663,
8668
]
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
"collectUsersInExitBlock"
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 7858e14547c509c95503b74ff8ffc7bf2fc5b110
Author: Hari Limaye <[email protected]>
Date: Wed Sep 11 16:43:34 2024 +0100
[LV] Amend check for IV increments in collectUsersInEntryBlock (#108020)
The check for IV increments in collectUsersInEntryBlock currently
triggers for exit-block PHIs which use the IV start value, resulting in
us failing to add the input value for the middle block to these PHIs.
Fix this by amending the check for IV increments to only include
incoming values that are instructions inside the loop.
Fixes #108004
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index b821da03c16e..640a7bf3d672 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8663,6 +8663,7 @@ static MapVector<PHINode *, VPValue *> collectUsersInExitBlock(
!cast<VPWidenIntOrFpInductionRecipe>(V)->getTruncInst()) ||
isa<VPWidenPointerInductionRecipe>(V) ||
(isa<Instruction>(IncomingValue) &&
+ OrigLoop->contains(cast<Instruction>(IncomingValue)) &&
any_of(IncomingValue->users(), [&Inductions](User *U) {
auto *P = dyn_cast<PHINode>(U);
return P && Inductions.contains(P);
| [
{
"file": "llvm/test/Transforms/LoopVectorize/use-iv-start-value.ll",
"commands": [
"opt < %s -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S"
],
"tests": [
{
"test_name": "foo",
"test_body": "define i64 @foo(ptr %p1, ptr %p2, i64 %start, i64 %end) {\nentry:\n %start2 = and i64 %start, 12345\n br label %for.body\n\nfor.body: ; preds = %for.body, %entry\n %ind = phi i64 [ %start2, %entry ], [ %ind.next, %for.body ]\n %arrayidx1 = getelementptr inbounds i32, ptr %p1, i64 %ind\n %0 = load i32, ptr %arrayidx1, align 4\n %arrayidx2 = getelementptr inbounds i32, ptr %p2, i64 %ind\n %1 = load i32, ptr %arrayidx2, align 4\n %ind.next = add i64 %ind, 1\n %cmp = icmp ne i64 %ind.next, %end\n br i1 %cmp, label %for.body, label %exit\n\nexit: ; preds = %for.body\n %use = phi i64 [ %start2, %for.body ]\n ret i64 %use\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[LoopVectorize] Assertion fails when IV start value is used by an exit block PHI",
"body": "With the following IR:\r\n```\r\ndefine i64 @foo(i64 %start, i64 %end) {\r\nentry:\r\n %p1 = alloca [1024 x i32]\r\n %p2 = alloca [1024 x i32]\r\n call void @init_mem(ptr %p1, i64 1024)\r\n call void @init_mem(ptr %p2, i64 1024)\r\n %start2 = and i64 %start, 12345\r\n br label %for.body\r\n\r\nfor.body:\r\n %ind = phi i64 [ %ind.next, %for.body ], [ %start2, %entry ]\r\n %arrayidx1 = getelementptr inbounds i32, ptr %p1, i64 %ind\r\n %0 = load i32, ptr %arrayidx1, align 4\r\n %arrayidx2 = getelementptr inbounds i32, ptr %p2, i64 %ind\r\n %1 = load i32, ptr %arrayidx2, align 4\r\n %ind.next = add i64 %ind, 1\r\n %cmp = icmp ne i64 %ind.next, %end\r\n br i1 %cmp, label %for.body, label %exit\r\n\r\nexit:\r\n %use = phi i64 [ %start2, %for.body ]\r\n ret i64 %use\r\n}\r\n\r\ndeclare void @init_mem(ptr, i64)\r\n```\r\n\r\nLV crashes due to hitting the following assertion:\r\n```\r\nLV: Vectorizing: innermost loop.\r\nPHINode should have one entry for each predecessor of its parent basic block!\r\n %bob = phi i64 [ %start2, %for.body ]\r\nopt: /work/llvm-project-wt/nuw-clang-arr/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:10244: bool llvm::LoopVectorizePass::processLoop(Loop *): Assertion `!verif\r\nyFunction(*L->getHeader()->getParent(), &dbgs())' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: ./build/bin/opt -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=4 -debug test.ll -o - -S\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"test.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"foo\"\r\n #0 0x0000aaaaaec431c0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./build/bin/opt+0x41a31c0)\r\n #1 0x0000aaaaaec4102c llvm::sys::RunSignalHandlers() (./build/bin/opt+0x41a102c)\r\n #2 0x0000aaaaaec438dc SignalHandler(int) Signals.cpp:0:0\r\n #3 0x0000fffff7ffb9d0 (linux-vdso.so.1+0x9d0)\r\n #4 0x0000fffff7b5f200 __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x0000fffff7b1a67c gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #6 0x0000fffff7b07130 abort ./stdlib/abort.c:81:7\r\n #7 0x0000fffff7b13fd0 __assert_fail_base ./assert/assert.c:89:7\r\n #8 0x0000fffff7b14040 __assert_perror_fail ./assert/assert-perr.c:31:1\r\n #9 0x0000aaaaadee375c llvm::LoopVectorizePass::processLoop(llvm::Loop*) (./build/bin/opt+0x344375c)\r\n#10 0x0000aaaaadee72d0 llvm::LoopVectorizePass::runImpl(llvm::Function&) (./build/bin/opt+0x34472d0)\r\n#11 0x0000aaaaadee7ac0 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (./build/bin/opt+0x3447ac0)\r\n#12 0x0000aaaaaea9676c llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (./bui\r\nld/bin/opt+0x3ff676c)\r\n#13 0x0000aaaaaea9a1fc llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (./build/bin/opt+0x3ffa1fc)\r\n#14 0x0000aaaaaea958cc llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (./build/bin/o\r\npt+0x3ff58cc)\r\n#15 0x0000aaaaab5b3d88 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOu\r\ntputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::Outpu\r\ntKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (./build/bin/opt+0xb13d88)\r\n#16 0x0000aaaaab5a7fc0 optMain (./build/bin/opt+0xb07fc0)\r\n#17 0x0000fffff7b073fc __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3\r\n#18 0x0000fffff7b074cc call_init ./csu/../csu/libc-start.c:128:20\r\n#19 0x0000fffff7b074cc __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#20 0x0000aaaaab5a1ef0 _start (./build/bin/opt+0xb01ef0)\r\n```\r\n\r\nSeems like we fail to properly handle fixing up the incoming value for this PHI from the middle block. ",
"author": "hazzlim",
"labels": [
"vectorizers",
"crash"
],
"comments": [
{
"author": "hazzlim",
"body": "Note: I am actively looking into this and plan to put up a fix "
}
]
} | true | null |
120361 | https://github.com/llvm/llvm-project/issues/120361 | miscompilation | c6967efe780d6cc5d70fc8cadbd227353b6768f1 | 2024-12-18T05:27:30 | [
"llvm/test/Transforms/InstCombine"
] | {
"fix_commit": "6f68010f9123aae9f6f105d7a11af22458518ad7",
"components": [
"InstCombine"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": [
[
455,
468
]
],
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": [
"foldLogOpOfMaskedICmps_NotAllZeros_BMask_Mixed"
],
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 6f68010f9123aae9f6f105d7a11af22458518ad7
Author: Yingwei Zheng <[email protected]>
Date: Wed Dec 18 20:40:33 2024 +0800
[InstCombine] Drop samesign flags in `foldLogOpOfMaskedICmps_NotAllZeros_BMask_Mixed` (#120373)
Counterexamples: https://alive2.llvm.org/ce/z/6Ks8Qz
Closes https://github.com/llvm/llvm-project/issues/120361.
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index dff9304be64d..e576eea4ca36 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -455,14 +455,20 @@ static Value *foldLogOpOfMaskedICmps_NotAllZeros_BMask_Mixed(
// RHS. For example,
// (icmp ne (A & 255), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).
// (icmp ne (A & 15), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).
- if (IsSuperSetOrEqual(BCst, DCst))
+ if (IsSuperSetOrEqual(BCst, DCst)) {
+ // We can't guarantee that samesign hold after this fold.
+ RHS->setSameSign(false);
return RHS;
+ }
// Otherwise, B is a subset of D. If B and E have a common bit set,
// ie. (B & E) != 0, then LHS is subsumed by RHS. For example.
// (icmp ne (A & 12), 0) & (icmp eq (A & 15), 8) -> (icmp eq (A & 15), 8).
assert(IsSubSetOrEqual(BCst, DCst) && "Precondition due to above code");
- if ((*BCst & ECst) != 0)
+ if ((*BCst & ECst) != 0) {
+ // We can't guarantee that samesign hold after this fold.
+ RHS->setSameSign(false);
return RHS;
+ }
// Otherwise, LHS and RHS contradict and the whole expression becomes false
// (or true if negated.) For example,
// (icmp ne (A & 7), 0) & (icmp eq (A & 15), 8) -> false.
| [
{
"file": "llvm/test/Transforms/InstCombine/icmp-logical.ll",
"commands": [
"opt -passes=instcombine -S -o - %s"
],
"tests": [
{
"test_name": "pr120361",
"test_body": "define i1 @pr120361(i8 %x, i8 %y) {\n %cmp1 = icmp samesign eq i8 %x, -1\n %cmp2 = icmp ne i8 %x, 0\n %result = select i1 %cmp2, i1 %cmp1, i1 false\n ret i1 %result\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "pr120361_v2",
"test_body": "define i1 @pr120361_v2(i32 %x) {\n %and1 = and i32 %x, 15\n %cmp1 = icmp ne i32 %and1, 0\n %and2 = and i32 %x, -113\n %cmp2 = icmp samesign eq i32 %and2, 15\n %and = select i1 %cmp1, i1 %cmp2, i1 false\n ret i1 %and\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "masked_icmps_bmask_notmixed_not_subset_notoptimized",
"test_body": "define i1 @masked_icmps_bmask_notmixed_not_subset_notoptimized(i32 %A) {\n %mask1 = and i32 %A, 254\n %tst1 = icmp ne i32 %mask1, 252\n %mask2 = and i32 %A, 253\n %tst2 = icmp ne i32 %mask2, 252\n %res = and i1 %tst1, %tst2\n ret i1 %res\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[InstCombine] `samesign` should be dropped when folding logical and of icmps",
"body": "Reproducer: https://alive2.llvm.org/ce/z/YSW_NC\n```\ndefine i1 @src(i8 %0, i8 %1) {\nstart:\n %2 = icmp samesign eq i8 %0, -1\n %3 = icmp ne i8 %0, 0\n %4 = icmp ugt i8 %0, %0\n %result = select i1 %3, i1 %2, i1 %4\n ret i1 %result\n}\n\ndefine i1 @tgt(i8 %0, i8 %1) {\nstart:\n %2 = icmp samesign eq i8 %0, -1\n ret i1 %2\n}\n```\n```\n\n----------------------------------------\ndefine i1 @src(i8 %#0, i8 %#1) {\nstart:\n %#2 = icmp samesign eq i8 %#0, 255\n %#3 = icmp ne i8 %#0, 0\n %#4 = icmp ugt i8 %#0, %#0\n %result = select i1 %#3, i1 %#2, i1 %#4\n ret i1 %result\n}\n=>\ndefine i1 @tgt(i8 %#0, i8 %#1) {\nstart:\n %#2 = icmp samesign eq i8 %#0, 255\n ret i1 %#2\n}\nTransformation doesn't verify!\n\nERROR: Target is more poisonous than source\n\nExample:\ni8 %#0 = #x00 (0)\ni8 %#1 = poison\n\nSource:\ni1 %#2 = poison\ni1 %#3 = #x0 (0)\ni1 %#4 = #x0 (0)\ni1 %result = #x0 (0)\n\nTarget:\ni1 %#2 = poison\nSource value: #x0 (0)\nTarget value: poison\n```\nReported by https://github.com/dtcxzyw/llvm-mutation-based-fuzz-service/issues/14 while reviewing https://github.com/llvm/llvm-project/pull/120177.\n\n\n",
"author": "dtcxzyw",
"labels": [
"miscompilation",
"llvm:instcombine"
],
"comments": []
} | true | null |
107473 | https://github.com/llvm/llvm-project/issues/107473 | crash | 99fb1506a869fa5e82dbd36e1a63cd21450f1502 | 2024-09-05T21:51:36 | [
"llvm/test/Transforms/LoopVectorize"
] | {
"fix_commit": "e3c537ff903af9a92ff43bab6d21c0ea759d65e5",
"components": [
"LoopVectorize"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
[
7314,
7322
]
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": [
"planContainsAdditionalSimplifications"
],
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit e3c537ff903af9a92ff43bab6d21c0ea759d65e5
Author: Florian Hahn <[email protected]>
Date: Tue Sep 10 21:37:12 2024 +0100
[VPlan] Consider non-header phis in planContainsAdditionalSimp.
Update planContainsAdditionalSimplifications to also check phis not in
the loop header. This ensures we don't miss cases where VPBlendRecipes
(which correspond to such phis) have been simplified.
Fixes https://github.com/llvm/llvm-project/issues/107473.
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 2be3b5775292..b821da03c16e 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -7314,9 +7314,10 @@ static bool planContainsAdditionalSimplifications(VPlan &Plan,
// Return true if the loop contains any instructions that are not also part of
// the VPlan or are skipped for VPlan-based cost computations. This indicates
// that the VPlan contains extra simplifications.
- return any_of(TheLoop->blocks(), [&SeenInstrs, &CostCtx](BasicBlock *BB) {
- return any_of(*BB, [&SeenInstrs, &CostCtx](Instruction &I) {
- if (isa<PHINode>(&I))
+ return any_of(TheLoop->blocks(), [&SeenInstrs, &CostCtx,
+ TheLoop](BasicBlock *BB) {
+ return any_of(*BB, [&SeenInstrs, &CostCtx, TheLoop, BB](Instruction &I) {
+ if (isa<PHINode>(&I) && BB == TheLoop->getHeader())
return false;
return !SeenInstrs.contains(&I) && !CostCtx.skipCostComputation(&I, true);
});
| [
{
"file": "llvm/test/Transforms/LoopVectorize/RISCV/dead-ops-cost.ll",
"commands": [
"opt -p loop-vectorize -mtriple riscv64-linux-gnu -mattr=+v,+f -S %s"
],
"tests": [
{
"test_name": "dead_load",
"test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine void @dead_load(ptr %p, i16 %start) {\nentry:\n %start.ext = sext i16 %start to i64\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i64 [ %start.ext, %entry ], [ %iv.next, %loop ]\n %gep = getelementptr i16, ptr %p, i64 %iv\n store i16 0, ptr %gep, align 2\n %l = load i16, ptr %gep, align 2\n %iv.next = add i64 %iv, 3\n %cmp = icmp slt i64 %iv, 111\n br i1 %cmp, label %loop, label %exit\n\nexit: ; preds = %loop\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "dead_live_out_due_to_scalar_epilogue_required",
"test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine i8 @dead_live_out_due_to_scalar_epilogue_required(ptr %src, ptr %dst) {\nentry:\n br label %loop\n\nloop: ; preds = %loop, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]\n %idxprom = sext i32 %iv to i64\n %gep.src = getelementptr i8, ptr %src, i64 %idxprom\n %l = load i8, ptr %gep.src, align 1\n %gep.dst = getelementptr i8, ptr %dst, i64 %idxprom\n store i8 0, ptr %gep.dst, align 1\n %iv.next = add i32 %iv, 4\n %cmp = icmp ult i32 %iv, 1001\n br i1 %cmp, label %loop, label %exit\n\nexit: ; preds = %loop\n %r = phi i8 [ %l, %loop ]\n ret i8 %r\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "test_phi_in_latch_redundant",
"test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\ndefine void @test_phi_in_latch_redundant(ptr %dst, i32 %a) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 false, label %loop.latch, label %then\n\nthen: ; preds = %loop.header\n %not.a = xor i32 %a, -1\n br label %loop.latch\n\nloop.latch: ; preds = %then, %loop.header\n %p = phi i32 [ %not.a, %then ], [ 0, %loop.header ]\n %gep = getelementptr i32, ptr %dst, i64 %iv\n store i32 %p, ptr %gep, align 4\n %iv.next = add i64 %iv, 9\n %ec = icmp slt i64 %iv, 322\n br i1 %ec, label %loop.header, label %exit\n\nexit: ; preds = %loop.latch\n ret void\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "cost_of_exit_branch_and_cond_insts",
"test_body": "target datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i16 @llvm.umax.i16(i16, i16) #0\n\ndefine i32 @cost_of_exit_branch_and_cond_insts(ptr %a, ptr %b, i1 %c, i16 %x) {\nentry:\n br label %loop.header\n\nloop.header: ; preds = %loop.latch, %entry\n %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]\n br i1 %c, label %then, label %loop.exiting\n\nthen: ; preds = %loop.header\n %gep = getelementptr inbounds i32, ptr %b, i32 %iv\n store i1 false, ptr %a, align 1\n store i32 0, ptr %gep, align 4\n br label %loop.exiting\n\nloop.exiting: ; preds = %then, %loop.header\n %iv.next = add i32 %iv, 1\n %umax = tail call i16 @llvm.umax.i16(i16 %x, i16 111)\n %umax.ext = zext i16 %umax to i32\n %sub = sub i32 770, %umax.ext\n %ec = icmp slt i32 %iv, %sub\n br i1 %ec, label %loop.latch, label %exit\n\nloop.latch: ; preds = %loop.exiting\n br label %loop.header\n\nexit: ; preds = %loop.exiting\n br label %return\n\nreturn: ; preds = %exit\n ret i32 0\n}\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[VPlan] Assertion \" VPlan cost model and legacy cost model disagreed\"' failed.",
"body": "Testing using 0c1500ef05e0a5b25cae79d2bd361dbc6e14e726\r\n\r\nC testcase:\r\n```\r\nint a;\r\nextern int b[][3][3][3][3][3];\r\n_Bool c;\r\nunsigned char d[1][13][13];\r\nunsigned e[1][13][13][13];\r\nint f[6];\r\nunsigned short g[1][13][13][13];\r\nunsigned h[1][13][13], i[1][13][13];\r\nshort j[1][13][13];\r\nunsigned k[3][13][13];\r\nunsigned short l[1][13];\r\nshort m[1][13];\r\nunsigned short n[1][13][13];\r\nunsigned o[1][13];\r\nvoid p(char q, int r, char s, unsigned char z[][13][13],\r\n unsigned aa[][13][13][13], int ab[], unsigned short ac[][13][13][13],\r\n unsigned ad[][13][13], short ae[][13][13], unsigned af[][13][13],\r\n unsigned short ag[][13], short ah[][13], unsigned short ai[][13][13],\r\n unsigned aj[][13][13], unsigned ak[][13]) {\r\n for (unsigned t = 0; t < q; t += 50)\r\n for (unsigned u = 0; u < 2; u = 6)\r\n for (short w = 0; w < 2; w += 42155)\r\n for (signed x = -15; x < r; x += s) {\r\n b[x][x][u][2][x][2] = ab[5] ? ~af[2][1][x] : 0;\r\n a = x ? c ? aj[2][u][x] : 0 : ae[2][w][4];\r\n }\r\n}\r\nint main() {\r\n f[5] = 8;\r\n for (long t = 0; t < 3; ++t)\r\n for (long v = 0; v < 3; ++v)\r\n for (long y = 0; y < 3; ++y)\r\n k[t][v][y] = 3004284279;\r\n p(8, 322, 9, d, e, f, g, h, j, k, l, m, n, i, o);\r\n}\r\n```\r\n\r\nLLVM IR:\r\n```llvm ir\r\n; ModuleID = 'reduced.bc'\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine i32 @main(i64 %indvars.iv) #0 {\r\nentry:\r\n br label %for.body17.us77.us.us.i\r\n\r\nfor.body17.us77.us.us.i: ; preds = %cond.end.us84.us.us.i, %entry\r\n %indvars.iv1 = phi i64 [ %indvars.iv.next, %cond.end.us84.us.us.i ], [ 0, %entry ]\r\n br i1 false, label %cond.end.us84.us.us.i, label %cond.true.us80.us.us.i\r\n\r\ncond.true.us80.us.us.i: ; preds = %for.body17.us77.us.us.i\r\n %not.us83.us.us.i = xor i32 0, 0\r\n br label %cond.end.us84.us.us.i\r\n\r\ncond.end.us84.us.us.i: ; preds = %cond.true.us80.us.us.i, %for.body17.us77.us.us.i\r\n %cond.us85.us.us.i = phi i32 [ %not.us83.us.us.i, %cond.true.us80.us.us.i ], [ 0, %for.body17.us77.us.us.i ]\r\n %arrayidx30.us87.us.us.i = getelementptr [0 x [3 x [3 x [3 x [3 x [3 x i32]]]]]], ptr null, i64 0, i64 %indvars.iv1, i64 %indvars.iv, i64 0, i64 2, i64 %indvars.iv, i64 2\r\n store i32 %cond.us85.us.us.i, ptr %arrayidx30.us87.us.us.i, align 4\r\n %indvars.iv.next = add i64 %indvars.iv1, 9\r\n %cmp14.us95.us.us.i = icmp slt i64 %indvars.iv1, 322\r\n br i1 %cmp14.us95.us.us.i, label %for.body17.us77.us.us.i, label %for.body17.us77.us.us.1.i.preheader\r\n\r\nfor.body17.us77.us.us.1.i.preheader: ; preds = %cond.end.us84.us.us.i\r\n ret i32 0\r\n}\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-b,-e,-experimental-smctr,-experimental-smmpm,-experimental-smnpm,-experimental-ssctr,-experimental-ssnpm,-experimental-sspm,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\n```\r\n\r\nCommand/backtrace:\r\n```\r\n> /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll -S\r\nopt: /scratch/tc-testing/tc-compiler-fuzz-trunk/llvm/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7400: llvm::VectorizationFactor llvm::LoopVectorizationPlanner::computeBestVF(): Assertion `(BestFactor.Width == LegacyVF.Width || planContainsAdditionalSimplifications(getPlanFor(BestFactor.Width), CostCtx, OrigLoop)) && \" VPlan cost model and legacy cost model disagreed\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt -passes=loop-vectorize reduced.ll -S\r\n1. Running pass \"function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)\" on module \"reduced.ll\"\r\n2. Running pass \"loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>\" on function \"main\"\r\n #0 0x000059162be7f6e0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x30136e0)\r\n #1 0x000059162be7caef llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x3010aef)\r\n #2 0x000059162be7cc45 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007152dd642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007152dd6969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007152dd6969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007152dd6969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007152dd642476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007152dd6287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00007152dd62871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x00007152dd639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x000059162ae52310 llvm::LoopVectorizationPlanner::computeBestVF() (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1fe6310)\r\n#12 0x000059162ae6910b llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x1ffd10b)\r\n#13 0x000059162ae6c121 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2000121)\r\n#14 0x000059162ae6c797 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2000797)\r\n#15 0x0000591629cc8756 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe5c756)\r\n#16 0x000059162bc8b67f llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e1f67f)\r\n#17 0x0000591629ccb8e6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe5f8e6)\r\n#18 0x000059162bc89a1b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e1da1b)\r\n#19 0x0000591629cc7b36 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0xe5bb36)\r\n#20 0x000059162bc8a57d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x2e1e57d)\r\n#21 0x00005916294f41b6 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x6881b6)\r\n#22 0x00005916294e5f11 optMain (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x679f11)\r\n#23 0x00007152dd629d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#24 0x00007152dd629e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#25 0x00007152dd629e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#26 0x00005916294dc2c5 _start (/scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt+0x6702c5)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-compiler-fuzz-trunk/build-gcv/build-llvm-linux/bin/opt\r\n```\r\nhttps://godbolt.org/z/qEEqe1exM\r\n\r\nFound via fuzzer\r\n\r\nRelated/prior issue: https://github.com/llvm/llvm-project/issues/107171\r\n\r\ncc @fhahn",
"author": "patrick-rivos",
"labels": [
"vectorizers",
"crash"
],
"comments": [
{
"author": "patrick-rivos",
"body": "Ping. The C fuzzer is hitting this assertion ~15 times a day since the runs starting sep 6th."
}
]
} | true | null |
121459 | https://github.com/llvm/llvm-project/issues/121459 | miscompilation | 68d265666e708bad1c63b419b6275aaba1a7dcd2 | 2025-01-02T09:03:32 | [
"llvm/test/Transforms/InstCombine"
] | {
"fix_commit": "a4d92400a6db9566d84cb4b900149e36e117f452",
"components": [
"InstCombine"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": [
[
2782,
2787
],
[
2838,
2843
],
[
2847,
2852
]
],
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": [
"foldGEPOfPhi"
],
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit a4d92400a6db9566d84cb4b900149e36e117f452
Author: Yingwei Zheng <[email protected]>
Date: Fri Jan 3 23:19:57 2025 +0800
[InstCombine] Fix GEPNoWrapFlags propagation in `foldGEPOfPhi` (#121572)
Closes https://github.com/llvm/llvm-project/issues/121459.
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 934156f04f7f..f63de1f0d410 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2782,6 +2782,7 @@ static Instruction *foldGEPOfPhi(GetElementPtrInst &GEP, PHINode *PN,
// loop iteration).
if (Op1 == &GEP)
return nullptr;
+ GEPNoWrapFlags NW = Op1->getNoWrapFlags();
int DI = -1;
@@ -2838,6 +2839,8 @@ static Instruction *foldGEPOfPhi(GetElementPtrInst &GEP, PHINode *PN,
}
}
}
+
+ NW &= Op2->getNoWrapFlags();
}
// If not all GEPs are identical we'll have to create a new PHI node.
@@ -2847,6 +2850,8 @@ static Instruction *foldGEPOfPhi(GetElementPtrInst &GEP, PHINode *PN,
return nullptr;
auto *NewGEP = cast<GetElementPtrInst>(Op1->clone());
+ NewGEP->setNoWrapFlags(NW);
+
if (DI == -1) {
// All the GEPs feeding the PHI are identical. Clone one down into our
// BB so that it can be merged with the current GEP.
| [
{
"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": "define ptr @gep_of_phi_of_gep_different_type(i1 %c, ptr %p) {\n br i1 %c, label %if, label %else\n\nif: ; preds = %0\n %gep1 = getelementptr i32, ptr %p, i64 1\n br label %join\n\nelse: ; preds = %0\n %gep2 = getelementptr i64, ptr %p, i64 2\n br label %join\n\njoin: ; preds = %else, %if\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\n %gep = getelementptr i32, ptr %phi, i64 1\n ret ptr %gep\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "gep_of_phi_of_gep_flags2",
"test_body": "define ptr @gep_of_phi_of_gep_flags2(i1 %c, ptr %p) {\n br i1 %c, label %if, label %else\n\nif: ; preds = %0\n %gep1 = getelementptr nuw i32, ptr %p, i64 1\n br label %join\n\nelse: ; preds = %0\n %gep2 = getelementptr nuw i32, ptr %p, i64 2\n br label %join\n\njoin: ; preds = %else, %if\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\n %gep = getelementptr i32, ptr %phi, i64 1\n ret ptr %gep\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "gep_of_phi_of_gep_flags1",
"test_body": "define ptr @gep_of_phi_of_gep_flags1(i1 %c, ptr %p) {\n br i1 %c, label %if, label %else\n\nif: ; preds = %0\n %gep1 = getelementptr inbounds i32, ptr %p, i64 1\n br label %join\n\nelse: ; preds = %0\n %gep2 = getelementptr i32, ptr %p, i64 2\n br label %join\n\njoin: ; preds = %else, %if\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\n %gep = getelementptr i32, ptr %phi, i64 1\n ret ptr %gep\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[InstCombine] GEPNoWrapFlags is propagated incorrectly",
"body": "Alive2: https://alive2.llvm.org/ce/z/3ME7S7\n```\ndefine ptr @src(i1 %c, ptr %p) {\n br i1 %c, label %if, label %else\n\nif:\n %gep1 = getelementptr inbounds i32, ptr %p, i64 1\n br label %join\n\nelse:\n %gep2 = getelementptr i64, ptr %p, i64 2\n br label %join\n\njoin:\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\n %gep = getelementptr i32, ptr %phi, i64 1\n ret ptr %gep\n}\n```\n```\n\n----------------------------------------\ndefine ptr @src(i1 %c, ptr %p) {\n#0:\n br i1 %c, label %if, label %else\n\nelse:\n %gep2 = gep ptr %p, 8 x i64 2\n br label %join\n\nif:\n %gep1 = gep inbounds ptr %p, 4 x i64 1\n br label %join\n\njoin:\n %phi = phi ptr [ %gep1, %if ], [ %gep2, %else ]\n %gep = gep ptr %phi, 4 x i64 1\n ret ptr %gep\n}\n=>\ndefine ptr @src(i1 %c, ptr %p) {\n#0:\n br i1 %c, label %if, label %else\n\nelse:\n br label %join\n\nif:\n br label %join\n\njoin:\n %#1 = phi i64 [ 4, %if ], [ 16, %else ]\n %#2 = gep inbounds nuw ptr %p, 1 x i64 %#1\n %gep = gep ptr %#2, 1 x i64 4\n ret ptr %gep\n}\nTransformation doesn't verify!\n\nERROR: Target is more poisonous than source\n\nExample:\ni1 %c = #x0 (0)\nptr %p = null\n\nSource:\n >> Jump to %else\nptr %gep2 = pointer(non-local, block_id=0, offset=16) / Address=#x0000000000000010\n >> Jump to %join\nptr %phi = pointer(non-local, block_id=0, offset=16) / Address=#x0000000000000010\nptr %gep = pointer(non-local, block_id=0, offset=20) / Address=#x0000000000000014\n\nSOURCE MEMORY STATE\n===================\nNON-LOCAL BLOCKS:\nBlock 0 >\tsize: 0\talign: 1\talloc type: 0\talive: false\taddress: 0\nBlock 1 >\tsize: 0\talign: 1\talloc type: 0\talive: true\taddress: 1\n\nTarget:\n >> Jump to %else\n >> Jump to %join\ni64 %#1 = #x0000000000000010 (16)\nptr %#2 = poison\nptr %gep = poison\nSource value: pointer(non-local, block_id=0, offset=20) / Address=#x0000000000000014\nTarget value: poison\n\nSummary:\n 0 correct transformations\n 1 incorrect transformations\n 0 failed-to-prove transformations\n 0 Alive2 errors\n```\n",
"author": "dtcxzyw",
"labels": [
"miscompilation",
"llvm:instcombine"
],
"comments": []
} | true | null |
82884 | https://github.com/llvm/llvm-project/issues/82884 | miscompilation | 0c7a605ada6cb392e6e8c16dbccf2b7e59017399 | 2024-02-24T15:15:12 | [
"llvm/test/Transforms/GVN"
] | {
"fix_commit": "892b4beeac50920e630f10905b2916295e2eb6d8",
"components": [
"Local"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": [
[
3369,
3379
]
],
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": [
"llvm::patchReplacementInstruction"
],
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 892b4beeac50920e630f10905b2916295e2eb6d8
Author: Yingwei Zheng <[email protected]>
Date: Mon Feb 26 15:55:56 2024 +0800
[GVN] Drop nsw/nuw flags when replacing the result of a with.overflow intrinsic with a overflowing binary operator (#82935)
Alive2: https://alive2.llvm.org/ce/z/gyL7mn
Fixes https://github.com/llvm/llvm-project/issues/82884.
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 1373f5f7f449..075eeb5b19fd 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -3369,11 +3369,17 @@ void llvm::patchReplacementInstruction(Instruction *I, Value *Repl) {
// Patch the replacement so that it is not more restrictive than the value
// being replaced.
+ WithOverflowInst *UnusedWO;
+ // When replacing the result of a llvm.*.with.overflow intrinsic with a
+ // overflowing binary operator, nuw/nsw flags may no longer hold.
+ if (isa<OverflowingBinaryOperator>(ReplInst) &&
+ match(I, m_ExtractValue<0>(m_WithOverflowInst(UnusedWO))))
+ ReplInst->dropPoisonGeneratingFlags();
// Note that if 'I' is a load being replaced by some operation,
// for example, by an arithmetic operation, then andIRFlags()
// would just erase all math flags from the original arithmetic
// operation, which is clearly not wanted and not needed.
- if (!isa<LoadInst>(I))
+ else if (!isa<LoadInst>(I))
ReplInst->andIRFlags(I);
// FIXME: If both the original and replacement value are part of the
| [
{
"file": "llvm/test/Transforms/GVN/pr82884.ll",
"commands": [
"opt -S -passes=gvn < %s"
],
"tests": [
{
"test_name": "pr82884",
"test_body": "define i32 @pr82884(i32 %x) {\n %mul = mul nuw nsw i32 %x, %x\n call void @use(i32 %mul)\n %mul2 = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 %x, i32 %x)\n %ret = extractvalue { i32, i1 } %mul2, 0\n ret i32 %ret\n}\n\ndeclare void @use(i32)\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare { i32, i1 } @llvm.smul.with.overflow.i32(i32, i32) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[GVN] GVNPass forgets to remove poison generating flags",
"body": "```llvm\r\n; ModuleID = '1851685_debug_2.e4807e3094afc004-cgu.0'\r\nsource_filename = \"1851685_debug_2.e4807e3094afc004-cgu.0\"\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\n%Adt58 = type { %Adt50 }\r\n%Adt50 = type { { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, { i16, i8, [5 x i8], i64 }, [8 x i32], { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr, [7 x i32], [3 x i32] }\r\n%Adt53 = type { { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] } }\r\n%Adt51 = type { { i64, i8, [7 x i8] }, { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, %Adt50, [8 x i32], i64, i64, [6 x i8], [10 x i8] }\r\n%Adt59 = type { { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, i64, ptr, i32, i16, [1 x i8], [1 x i8] }\r\n\r\[email protected] = private unnamed_addr constant <{ ptr, [16 x i8], ptr, ptr, ptr }> <{ ptr @\"_ZN4core3ptr85drop_in_place$LT$std..rt..lang_start$LT$$LP$$RP$$GT$..$u7b$$u7b$closure$u7d$$u7d$$GT$17he9a486ff76ea726fE\", [16 x i8] c\"\\08\\00\\00\\00\\00\\00\\00\\00\\08\\00\\00\\00\\00\\00\\00\\00\", ptr @\"_ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17h91c73705548d2f78E\", ptr @\"_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h1cb78ba075200b22E\", ptr @\"_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h1cb78ba075200b22E\" }>, align 8\r\n@alloc_2cdd8ac758b4c372b56d8683306290e0 = private unnamed_addr constant <{ [15 x i8] }> <{ [15 x i8] c\"hi:%ld lo:%ld\\0A\\00\" }>, align 1\r\n\r\n; std::sys_common::backtrace::__rust_begin_short_backtrace\r\n; Function Attrs: noinline nonlazybind uwtable\r\ndefine internal void @_ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17h176fc8086015470dE(ptr %f) unnamed_addr #0 {\r\nstart:\r\n; call core::ops::function::FnOnce::call_once\r\n call void @_ZN4core3ops8function6FnOnce9call_once17h23c7757b8dc992b5E(ptr %f)\r\n call void asm sideeffect \"\", \"~{memory}\"(), !srcloc !4\r\n ret void\r\n}\r\n\r\n; std::rt::lang_start::{{closure}}\r\n; Function Attrs: inlinehint nonlazybind uwtable\r\ndefine internal i32 @\"_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h1cb78ba075200b22E\"(ptr align 8 %_1) unnamed_addr #2 {\r\nstart:\r\n %self = alloca i8, align 1\r\n %_4 = load ptr, ptr %_1, align 8, !nonnull !5, !noundef !5\r\n; call std::sys_common::backtrace::__rust_begin_short_backtrace\r\n call void @_ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17h176fc8086015470dE(ptr %_4)\r\n; call <() as std::process::Termination>::report\r\n %0 = call i8 @\"_ZN54_$LT$$LP$$RP$$u20$as$u20$std..process..Termination$GT$6report17hb8b4bfb25c4e0e48E\"()\r\n store i8 %0, ptr %self, align 1\r\n %_6 = load i8, ptr %self, align 1, !noundef !5\r\n %_0 = zext i8 %_6 to i32\r\n ret i32 %_0\r\n}\r\n\r\n; core::ops::function::FnOnce::call_once{{vtable.shim}}\r\n; Function Attrs: inlinehint nonlazybind uwtable\r\ndefine internal i32 @\"_ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17h91c73705548d2f78E\"(ptr %_1) unnamed_addr #2 {\r\nstart:\r\n %_2 = alloca {}, align 1\r\n %0 = load ptr, ptr %_1, align 8, !nonnull !5, !noundef !5\r\n; call core::ops::function::FnOnce::call_once\r\n %_0 = call i32 @_ZN4core3ops8function6FnOnce9call_once17ha42f99eeb4429a31E(ptr %0)\r\n ret i32 %_0\r\n}\r\n\r\n; core::ops::function::FnOnce::call_once\r\n; Function Attrs: inlinehint nonlazybind uwtable\r\ndefine internal void @_ZN4core3ops8function6FnOnce9call_once17h23c7757b8dc992b5E(ptr %_1) unnamed_addr #2 {\r\nstart:\r\n %_2 = alloca {}, align 1\r\n call void %_1()\r\n ret void\r\n}\r\n\r\n; core::ops::function::FnOnce::call_once\r\n; Function Attrs: inlinehint nonlazybind uwtable\r\ndefine internal i32 @_ZN4core3ops8function6FnOnce9call_once17ha42f99eeb4429a31E(ptr %0) unnamed_addr #2 personality ptr @rust_eh_personality {\r\nstart:\r\n %1 = alloca { ptr, i32, [1 x i32] }, align 8\r\n %_2 = alloca {}, align 1\r\n %_1 = alloca ptr, align 8\r\n store ptr %0, ptr %_1, align 8\r\n; invoke std::rt::lang_start::{{closure}}\r\n %_0 = invoke i32 @\"_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h1cb78ba075200b22E\"(ptr align 8 %_1)\r\n to label %bb1 unwind label %cleanup\r\n\r\nbb3: ; preds = %cleanup\r\n %2 = load ptr, ptr %1, align 8, !noundef !5\r\n %3 = getelementptr inbounds i8, ptr %1, i64 8\r\n %4 = load i32, ptr %3, align 8, !noundef !5\r\n %5 = insertvalue { ptr, i32 } poison, ptr %2, 0\r\n %6 = insertvalue { ptr, i32 } %5, i32 %4, 1\r\n resume { ptr, i32 } %6\r\n\r\ncleanup: ; preds = %start\r\n %7 = landingpad { ptr, i32 }\r\n cleanup\r\n %8 = extractvalue { ptr, i32 } %7, 0\r\n %9 = extractvalue { ptr, i32 } %7, 1\r\n store ptr %8, ptr %1, align 8\r\n %10 = getelementptr inbounds i8, ptr %1, i64 8\r\n store i32 %9, ptr %10, align 8\r\n br label %bb3\r\n\r\nbb1: ; preds = %start\r\n ret i32 %_0\r\n}\r\n\r\n; core::ptr::drop_in_place<std::rt::lang_start<()>::{{closure}}>\r\n; Function Attrs: inlinehint nonlazybind uwtable\r\ndefine internal void @\"_ZN4core3ptr85drop_in_place$LT$std..rt..lang_start$LT$$LP$$RP$$GT$..$u7b$$u7b$closure$u7d$$u7d$$GT$17he9a486ff76ea726fE\"(ptr align 8 %_1) unnamed_addr #2 {\r\nstart:\r\n ret void\r\n}\r\n\r\n; core::hint::black_box\r\n; Function Attrs: inlinehint nonlazybind uwtable\r\ndefine internal void @_ZN4core4hint9black_box17h7d48bc7feb0af96eE(ptr sret({ i16, i8, [5 x i8], i64 }) align 8 %_0, ptr align 8 %dummy) unnamed_addr #2 {\r\nstart:\r\n call void @llvm.memcpy.p0.p0.i64(ptr align 8 %_0, ptr align 8 %dummy, i64 16, i1 false)\r\n call void asm sideeffect \"\", \"r,~{memory}\"(ptr %_0), !srcloc !4\r\n ret void\r\n}\r\n\r\n; core::hint::black_box\r\n; Function Attrs: inlinehint nonlazybind uwtable\r\ndefine internal void @_ZN4core4hint9black_box17ha89c3f9cb79c398cE() unnamed_addr #2 {\r\nstart:\r\n call void asm sideeffect \"\", \"~{memory}\"(), !srcloc !4\r\n ret void\r\n}\r\n\r\n; <() as std::process::Termination>::report\r\n; Function Attrs: inlinehint nonlazybind uwtable\r\ndefine internal i8 @\"_ZN54_$LT$$LP$$RP$$u20$as$u20$std..process..Termination$GT$6report17hb8b4bfb25c4e0e48E\"() unnamed_addr #2 {\r\nstart:\r\n ret i8 0\r\n}\r\n\r\n; _1851685_debug_2::enter\r\n; Function Attrs: nonlazybind uwtable\r\ndefine internal void @_ZN16_1851685_debug_25enter17h7e9cae7a334c5019E() unnamed_addr #1 {\r\nstart:\r\n %_3 = alloca [6 x i32], align 4\r\n %_2 = alloca { i16, i8, [5 x i8], i64 }, align 8\r\n %0 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_2, i32 0, i32 1\r\n store i8 0, ptr %0, align 2\r\n store i16 0, ptr %_2, align 8\r\n %1 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_2, i32 0, i32 3\r\n store i64 0, ptr %1, align 8\r\n %2 = getelementptr inbounds [6 x i32], ptr %_3, i64 0, i64 0\r\n call void @llvm.memset.p0.i64(ptr align 4 %2, i8 0, i64 24, i1 false)\r\n; call _1851685_debug_2::fn14\r\n call void @_ZN16_1851685_debug_24fn1417h1fc74d4c311bb23aE(ptr align 8 %_2, ptr align 4 %_3)\r\n ret void\r\n}\r\n\r\n; _1851685_debug_2::fn14\r\n; Function Attrs: nonlazybind uwtable\r\ndefine internal void @_ZN16_1851685_debug_24fn1417h1fc74d4c311bb23aE(ptr align 8 %_1, ptr align 4 %_2) unnamed_addr #1 {\r\nstart:\r\n %_16 = alloca i8, align 1\r\n %_15 = alloca %Adt58, align 16\r\n %_14 = alloca { i16, i8, [5 x i8], i64 }, align 8\r\n %_13 = alloca { { i16, i8, [5 x i8], i64 }, [6 x i32], i32, [1 x i32], [4 x i64] }, align 8\r\n %_12 = alloca %Adt53, align 16\r\n %_10 = alloca %Adt51, align 16\r\n %_7 = alloca %Adt59, align 8\r\n %_5 = alloca i128, align 16\r\n %0 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 1\r\n store i8 84, ptr %0, align 2\r\n store i16 -25440, ptr %_1, align 8\r\n %1 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 3\r\n store i64 -9223372036854775808, ptr %1, align 8\r\n br label %bb1\r\n\r\nbb1: ; preds = %bb4, %start\r\n store double 0x41A15ED4AE000000, ptr %_7, align 8\r\n %2 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 4\r\n %3 = load i16, ptr %_1, align 8, !noundef !5\r\n %4 = urem i16 %3, -3470\r\n store i16 %4, ptr %2, align 4\r\n %5 = call { i64, i1 } @llvm.ssub.with.overflow.i64(i64 3029947793098001587, i64 -3638983068927244405)\r\n %6 = extractvalue { i64, i1 } %5, 0\r\n %7 = extractvalue { i64, i1 } %5, 1\r\n store i64 %6, ptr %_10, align 16\r\n %8 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %9 = zext i1 %7 to i8\r\n store i8 %9, ptr %8, align 8\r\n %10 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %11 = load i8, ptr %10, align 8, !range !6, !noundef !5\r\n %12 = trunc i8 %11 to i1\r\n %13 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %14 = load i8, ptr %13, align 8, !range !6, !noundef !5\r\n %15 = trunc i8 %14 to i1\r\n %_9 = xor i1 %12, %15\r\n %16 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 2\r\n store ptr %_10, ptr %16, align 8\r\n %17 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 1\r\n store i64 -1498547728408969452, ptr %17, align 8\r\n %18 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %19 = getelementptr inbounds %Adt50, ptr %18, i32 0, i32 2\r\n %20 = getelementptr inbounds [8 x i32], ptr %19, i64 0, i64 0\r\n store i32 168516996, ptr %20, align 16\r\n %21 = getelementptr inbounds [8 x i32], ptr %19, i64 0, i64 1\r\n store i32 245529160, ptr %21, align 4\r\n %22 = getelementptr inbounds [8 x i32], ptr %19, i64 0, i64 2\r\n store i32 1223136339, ptr %22, align 8\r\n %23 = getelementptr inbounds [8 x i32], ptr %19, i64 0, i64 3\r\n store i32 1622354325, ptr %23, align 4\r\n %24 = getelementptr inbounds [8 x i32], ptr %19, i64 0, i64 4\r\n store i32 -1002348909, ptr %24, align 16\r\n %25 = getelementptr inbounds [8 x i32], ptr %19, i64 0, i64 5\r\n store i32 1976405017, ptr %25, align 4\r\n %26 = getelementptr inbounds [8 x i32], ptr %19, i64 0, i64 6\r\n store i32 -1442509311, ptr %26, align 8\r\n %27 = getelementptr inbounds [8 x i32], ptr %19, i64 0, i64 7\r\n store i32 1165829790, ptr %27, align 4\r\n %28 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %29 = getelementptr inbounds %Adt50, ptr %28, i32 0, i32 3\r\n %30 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %29, i32 0, i32 2\r\n %31 = load double, ptr %_7, align 8, !noundef !5\r\n %32 = fneg double %31\r\n store double %32, ptr %30, align 16\r\n %33 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 3\r\n %34 = load i64, ptr %33, align 8, !noundef !5\r\n %_8 = xor i64 %34, -1\r\n store i64 7564290096487423208, ptr %_10, align 16\r\n %35 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %36 = zext i1 %_9 to i8\r\n store i8 %36, ptr %35, align 8\r\n %37 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %38 = getelementptr inbounds %Adt50, ptr %37, i32 0, i32 3\r\n %39 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %38, i32 0, i32 1\r\n store i64 %_8, ptr %39, align 16\r\n %40 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 1\r\n %41 = load i64, ptr %_10, align 16, !noundef !5\r\n store i64 %41, ptr %40, align 8\r\n %42 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %43 = getelementptr inbounds %Adt50, ptr %42, i32 0, i32 3\r\n %44 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %43, i32 0, i32 1\r\n %45 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %44, i32 0, i32 5\r\n; call _1851685_debug_2::fn15\r\n %46 = call i128 @_ZN16_1851685_debug_24fn1517hfe3f07cbb5faefb0E()\r\n store i128 %46, ptr %45, align 16\r\n %47 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %48 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %47, i32 0, i32 1\r\n %49 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 1\r\n %50 = load i64, ptr %49, align 8, !noundef !5\r\n %51 = trunc i64 %50 to i16\r\n store i16 %51, ptr %48, align 16\r\n %52 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 4\r\n %53 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 1\r\n %54 = load i64, ptr %53, align 8, !noundef !5\r\n store i64 %54, ptr %52, align 16\r\n %55 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %56 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %57 = getelementptr inbounds %Adt50, ptr %56, i32 0, i32 3\r\n %58 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %57, i32 0, i32 1\r\n %59 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %58, i32 0, i32 5\r\n %60 = load i128, ptr %59, align 16, !noundef !5\r\n %61 = ashr i128 %60, 0\r\n store i128 %61, ptr %55, align 16\r\n %62 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %63 = getelementptr inbounds %Adt50, ptr %62, i32 0, i32 3\r\n %64 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %63, i32 0, i32 2\r\n %65 = load double, ptr %64, align 16, !noundef !5\r\n %66 = fneg double %65\r\n store double %66, ptr %_7, align 8\r\n %67 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %68 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %67, i32 0, i32 2\r\n %69 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %70 = load i8, ptr %69, align 8, !range !6, !noundef !5\r\n %71 = trunc i8 %70 to i1\r\n %72 = xor i1 %71, true\r\n %73 = zext i1 %72 to i8\r\n store i8 %73, ptr %68, align 2\r\n %74 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %75 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %74, i32 0, i32 4\r\n %76 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %77 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %76, i32 0, i32 1\r\n %78 = load i16, ptr %77, align 16, !noundef !5\r\n %79 = getelementptr inbounds [1 x i16], ptr %75, i64 0, i64 0\r\n store i16 %78, ptr %79, align 4\r\n %80 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %81 = getelementptr inbounds %Adt50, ptr %80, i32 0, i32 1\r\n %82 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %81, i32 0, i32 1\r\n %83 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 1\r\n %84 = load i8, ptr %83, align 2, !noundef !5\r\n store i8 %84, ptr %82, align 2\r\n %85 = getelementptr inbounds [6 x i32], ptr %_2, i64 0, i64 0\r\n store i32 -154507050, ptr %85, align 4\r\n %86 = getelementptr inbounds [6 x i32], ptr %_2, i64 0, i64 1\r\n store i32 2086635898, ptr %86, align 4\r\n %87 = getelementptr inbounds [6 x i32], ptr %_2, i64 0, i64 2\r\n store i32 468582002, ptr %87, align 4\r\n %88 = getelementptr inbounds [6 x i32], ptr %_2, i64 0, i64 3\r\n store i32 -21184342, ptr %88, align 4\r\n %89 = getelementptr inbounds [6 x i32], ptr %_2, i64 0, i64 4\r\n store i32 -1173629817, ptr %89, align 4\r\n %90 = getelementptr inbounds [6 x i32], ptr %_2, i64 0, i64 5\r\n store i32 -2078649110, ptr %90, align 4\r\n %91 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n store i128 0, ptr %91, align 16\r\n %92 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %_12, i32 0, i32 2\r\n %93 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %94 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %93, i32 0, i32 2\r\n %95 = load i8, ptr %94, align 2, !range !6, !noundef !5\r\n %96 = trunc i8 %95 to i1\r\n %97 = zext i1 %96 to i8\r\n store i8 %97, ptr %92, align 2\r\n %98 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %99 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %98, i32 0, i32 1\r\n %100 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %101 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %100, i32 0, i32 1\r\n %102 = load i16, ptr %101, align 16, !noundef !5\r\n %103 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %104 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %103, i32 0, i32 1\r\n %105 = load i16, ptr %104, align 16, !noundef !5\r\n %106 = mul i16 %102, %105\r\n store i16 %106, ptr %99, align 16\r\n %107 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 3\r\n store i32 630181660, ptr %107, align 8\r\n %108 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 3\r\n %109 = load i32, ptr %108, align 8, !noundef !5\r\n %110 = uitofp i32 %109 to double\r\n store double %110, ptr %_7, align 8\r\n %_11 = sub i64 0, %_8\r\n %111 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %112 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %113 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %112, i32 0, i32 1\r\n %114 = load i16, ptr %113, align 16, !noundef !5\r\n %115 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %111, i32 0, i32 1\r\n store i16 %114, ptr %115, align 16\r\n %116 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %117 = load i128, ptr %116, align 16, !noundef !5\r\n store i128 %117, ptr %111, align 16\r\n %118 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %111, i32 0, i32 2\r\n %119 = zext i1 %_9 to i8\r\n store i8 %119, ptr %118, align 2\r\n %120 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %121 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %120, i32 0, i32 4\r\n %122 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %111, i32 0, i32 4\r\n %123 = load i16, ptr %121, align 4\r\n store i16 %123, ptr %122, align 4\r\n %124 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 1\r\n %125 = load i64, ptr %124, align 8, !noundef !5\r\n %126 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 1\r\n %127 = load i64, ptr %126, align 8, !noundef !5\r\n %128 = call { i64, i1 } @llvm.smul.with.overflow.i64(i64 %125, i64 %127)\r\n %129 = extractvalue { i64, i1 } %128, 0\r\n %130 = extractvalue { i64, i1 } %128, 1\r\n store i64 %129, ptr %_10, align 16\r\n %131 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %132 = zext i1 %130 to i8\r\n store i8 %132, ptr %131, align 8\r\n br label %bb3\r\n\r\nbb3: ; preds = %bb6, %bb1\r\n %133 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %134 = getelementptr inbounds %Adt50, ptr %133, i32 0, i32 3\r\n %135 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %134, i32 0, i32 2\r\n %136 = load double, ptr %_7, align 8, !noundef !5\r\n %137 = fdiv double %136, 0x92917F04BFA33\r\n store double %137, ptr %135, align 16\r\n %138 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 5\r\n store i64 -6496701646011298800, ptr %138, align 8\r\n %139 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %140 = getelementptr inbounds %Adt50, ptr %139, i32 0, i32 1\r\n %141 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %140, i32 0, i32 1\r\n %142 = load i8, ptr %141, align 2, !noundef !5\r\n %143 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 1\r\n store i8 %142, ptr %143, align 2\r\n %144 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 4\r\n %145 = load i16, ptr %144, align 4, !noundef !5\r\n store i16 %145, ptr %_1, align 8\r\n %146 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 3\r\n store i64 %_11, ptr %146, align 8\r\n %147 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %148 = getelementptr inbounds %Adt50, ptr %147, i32 0, i32 3\r\n %149 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %148, i32 0, i32 1\r\n %150 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %149, i32 0, i32 2\r\n %151 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 3\r\n %152 = load i32, ptr %151, align 8, !noundef !5\r\n store i32 %152, ptr %150, align 16\r\n %153 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %154 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %153, i32 0, i32 2\r\n %155 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %156 = load i128, ptr %155, align 16, !noundef !5\r\n %157 = icmp sge i128 %156, 0\r\n %158 = zext i1 %157 to i8\r\n store i8 %158, ptr %154, align 2\r\n %159 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %160 = getelementptr inbounds %Adt50, ptr %159, i32 0, i32 1\r\n %161 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %160, i32 0, i32 3\r\n %162 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 3\r\n %163 = load i64, ptr %162, align 8, !noundef !5\r\n %164 = and i64 %163, %_8\r\n store i64 %164, ptr %161, align 8\r\n %165 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 6\r\n %166 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %167 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %166, i32 0, i32 2\r\n %168 = load i8, ptr %167, align 2, !range !6, !noundef !5\r\n %169 = trunc i8 %168 to i1\r\n %170 = getelementptr inbounds [6 x i8], ptr %165, i64 0, i64 0\r\n %171 = zext i1 %169 to i8\r\n store i8 %171, ptr %170, align 16\r\n %172 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %173 = load i8, ptr %172, align 8, !range !6, !noundef !5\r\n %174 = trunc i8 %173 to i1\r\n %175 = getelementptr inbounds [6 x i8], ptr %165, i64 0, i64 1\r\n %176 = zext i1 %174 to i8\r\n store i8 %176, ptr %175, align 1\r\n %177 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %_12, i32 0, i32 2\r\n %178 = load i8, ptr %177, align 2, !range !6, !noundef !5\r\n %179 = trunc i8 %178 to i1\r\n %180 = getelementptr inbounds [6 x i8], ptr %165, i64 0, i64 2\r\n %181 = zext i1 %179 to i8\r\n store i8 %181, ptr %180, align 2\r\n %182 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %_12, i32 0, i32 2\r\n %183 = load i8, ptr %182, align 2, !range !6, !noundef !5\r\n %184 = trunc i8 %183 to i1\r\n %185 = getelementptr inbounds [6 x i8], ptr %165, i64 0, i64 3\r\n %186 = zext i1 %184 to i8\r\n store i8 %186, ptr %185, align 1\r\n %187 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %188 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %187, i32 0, i32 2\r\n %189 = load i8, ptr %188, align 2, !range !6, !noundef !5\r\n %190 = trunc i8 %189 to i1\r\n %191 = getelementptr inbounds [6 x i8], ptr %165, i64 0, i64 4\r\n %192 = zext i1 %190 to i8\r\n store i8 %192, ptr %191, align 4\r\n %193 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %194 = load i8, ptr %193, align 8, !range !6, !noundef !5\r\n %195 = trunc i8 %194 to i1\r\n %196 = getelementptr inbounds [6 x i8], ptr %165, i64 0, i64 5\r\n %197 = zext i1 %195 to i8\r\n store i8 %197, ptr %196, align 1\r\n %198 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %199 = getelementptr inbounds %Adt50, ptr %198, i32 0, i32 3\r\n %200 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %199, i32 0, i32 1\r\n %201 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %200, i32 0, i32 5\r\n %202 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %203 = load i128, ptr %202, align 16, !noundef !5\r\n store i128 %203, ptr %201, align 16\r\n %204 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 2\r\n %205 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %206 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %205, i32 0, i32 1\r\n %207 = load i16, ptr %206, align 16, !noundef !5\r\n %208 = sub i16 0, %207\r\n store i16 %208, ptr %204, align 8\r\n %209 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %210 = getelementptr inbounds %Adt50, ptr %209, i32 0, i32 4\r\n %211 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 1\r\n store ptr %211, ptr %210, align 16\r\n %212 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 5\r\n %213 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 1\r\n %214 = load i8, ptr %213, align 2, !noundef !5\r\n %215 = getelementptr inbounds [1 x i8], ptr %212, i64 0, i64 0\r\n store i8 %214, ptr %215, align 2\r\n %216 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 3\r\n %217 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %218 = getelementptr inbounds %Adt50, ptr %217, i32 0, i32 2\r\n %219 = load <8 x i32>, ptr %218, align 16\r\n store <8 x i32> %219, ptr %216, align 16\r\n %220 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %221 = getelementptr inbounds %Adt50, ptr %220, i32 0, i32 3\r\n %222 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %221, i32 0, i32 1\r\n %223 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %222, i32 0, i32 3\r\n %224 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 5\r\n %225 = load i64, ptr %224, align 8, !noundef !5\r\n %226 = trunc i64 %225 to i32\r\n store i32 %226, ptr %223, align 4\r\n %227 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 3\r\n %228 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %229 = getelementptr inbounds %Adt50, ptr %228, i32 0, i32 1\r\n %230 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %229, i32 0, i32 3\r\n %231 = load i64, ptr %230, align 8, !noundef !5\r\n %232 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %233 = getelementptr inbounds %Adt50, ptr %232, i32 0, i32 3\r\n %234 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %233, i32 0, i32 1\r\n %235 = load i64, ptr %234, align 16, !noundef !5\r\n %236 = xor i64 %231, %235\r\n store i64 %236, ptr %227, align 8\r\n %237 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %238 = getelementptr inbounds %Adt50, ptr %237, i32 0, i32 3\r\n %239 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %238, i32 0, i32 2\r\n %240 = load double, ptr %_7, align 8, !noundef !5\r\n store double %240, ptr %239, align 16\r\n %241 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_14, i32 0, i32 1\r\n %242 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 1\r\n %243 = load i8, ptr %242, align 2, !noundef !5\r\n %244 = xor i8 %243, -1\r\n store i8 %244, ptr %241, align 2\r\n %245 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %246 = getelementptr inbounds %Adt50, ptr %245, i32 0, i32 1\r\n %247 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %248 = load i8, ptr %247, align 8, !range !6, !noundef !5\r\n %249 = trunc i8 %248 to i1\r\n %250 = zext i1 %249 to i16\r\n store i16 %250, ptr %246, align 16\r\n %251 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %252 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %253 = getelementptr inbounds %Adt50, ptr %252, i32 0, i32 3\r\n %254 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %253, i32 0, i32 1\r\n %255 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %254, i32 0, i32 3\r\n %256 = load i32, ptr %255, align 4, !noundef !5\r\n %257 = sext i32 %256 to i128\r\n store i128 %257, ptr %251, align 16\r\n %258 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %259 = getelementptr inbounds %Adt50, ptr %258, i32 0, i32 3\r\n %260 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %259, i32 0, i32 1\r\n %261 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %260, i32 0, i32 3\r\n %262 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %263 = getelementptr inbounds %Adt50, ptr %262, i32 0, i32 1\r\n %264 = load i16, ptr %263, align 16, !noundef !5\r\n %265 = zext i16 %264 to i32\r\n store i32 %265, ptr %261, align 4\r\n br label %bb4\r\n\r\nbb4: ; preds = %bb4, %bb3\r\n %266 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_14, i32 0, i32 1\r\n %267 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %268 = getelementptr inbounds %Adt50, ptr %267, i32 0, i32 3\r\n %269 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %268, i32 0, i32 1\r\n %270 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %269, i32 0, i32 3\r\n %271 = load i32, ptr %270, align 4, !noundef !5\r\n %272 = trunc i32 %271 to i8\r\n store i8 %272, ptr %266, align 2\r\n %273 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_14, i32 0, i32 1\r\n %274 = load i8, ptr %273, align 2, !noundef !5\r\n %275 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_13, i32 0, i32 1\r\n store i8 %274, ptr %275, align 2\r\n %276 = load i16, ptr %_1, align 8, !noundef !5\r\n store i16 %276, ptr %_13, align 8\r\n %277 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %278 = getelementptr inbounds %Adt50, ptr %277, i32 0, i32 1\r\n %279 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %278, i32 0, i32 3\r\n %280 = load i64, ptr %279, align 8, !noundef !5\r\n %281 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_13, i32 0, i32 3\r\n store i64 %280, ptr %281, align 8\r\n %282 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_14, i32 0, i32 3\r\n %283 = getelementptr inbounds %Adt59, ptr %_7, i32 0, i32 4\r\n %284 = load i16, ptr %283, align 4, !noundef !5\r\n %285 = zext i16 %284 to i64\r\n store i64 %285, ptr %282, align 8\r\n %286 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %287 = getelementptr inbounds %Adt50, ptr %286, i32 0, i32 3\r\n %288 = load i64, ptr %_10, align 16, !noundef !5\r\n %289 = sext i64 %288 to i128\r\n store i128 %289, ptr %287, align 16\r\n %290 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 1\r\n %291 = getelementptr inbounds { i128, i16, i8, [1 x i8], [1 x i16], [5 x i16] }, ptr %290, i32 0, i32 2\r\n %292 = load i8, ptr %291, align 2, !range !6, !noundef !5\r\n %293 = trunc i8 %292 to i1\r\n %294 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %295 = load i8, ptr %294, align 8, !range !6, !noundef !5\r\n %296 = trunc i8 %295 to i1\r\n %297 = and i1 %293, %296\r\n %298 = zext i1 %297 to i8\r\n store i8 %298, ptr %_16, align 1\r\n %299 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 1\r\n %300 = getelementptr inbounds { i64, i64, i64 }, ptr %299, i32 0, i32 2\r\n %301 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 3\r\n %302 = load i64, ptr %301, align 8, !noundef !5\r\n %303 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_14, i32 0, i32 3\r\n %304 = load i64, ptr %303, align 8, !noundef !5\r\n %305 = xor i64 %302, %304\r\n store i64 %305, ptr %300, align 8\r\n %306 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_13, i32 0, i32 1\r\n %307 = load i8, ptr %306, align 2, !noundef !5\r\n %308 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_14, i32 0, i32 1\r\n store i8 %307, ptr %308, align 2\r\n %309 = load i16, ptr %_1, align 8, !noundef !5\r\n store i16 %309, ptr %_14, align 8\r\n %310 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 1\r\n %311 = getelementptr inbounds { i64, i64, i64 }, ptr %310, i32 0, i32 2\r\n %312 = load i64, ptr %311, align 8, !noundef !5\r\n %313 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_14, i32 0, i32 3\r\n store i64 %312, ptr %313, align 8\r\n %314 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %315 = getelementptr inbounds %Adt50, ptr %314, i32 0, i32 5\r\n %316 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %317 = getelementptr inbounds %Adt50, ptr %316, i32 0, i32 3\r\n %318 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %317, i32 0, i32 1\r\n %319 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %318, i32 0, i32 3\r\n %320 = load i32, ptr %319, align 4, !noundef !5\r\n %321 = getelementptr inbounds [7 x i32], ptr %315, i64 0, i64 0\r\n store i32 %320, ptr %321, align 8\r\n %322 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %323 = getelementptr inbounds %Adt50, ptr %322, i32 0, i32 3\r\n %324 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %323, i32 0, i32 1\r\n %325 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %324, i32 0, i32 3\r\n %326 = load i32, ptr %325, align 4, !noundef !5\r\n %327 = getelementptr inbounds [7 x i32], ptr %315, i64 0, i64 1\r\n store i32 %326, ptr %327, align 4\r\n %328 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %329 = getelementptr inbounds %Adt50, ptr %328, i32 0, i32 3\r\n %330 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %329, i32 0, i32 1\r\n %331 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %330, i32 0, i32 3\r\n %332 = load i32, ptr %331, align 4, !noundef !5\r\n %333 = getelementptr inbounds [7 x i32], ptr %315, i64 0, i64 2\r\n store i32 %332, ptr %333, align 8\r\n %334 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %335 = getelementptr inbounds %Adt50, ptr %334, i32 0, i32 3\r\n %336 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %335, i32 0, i32 1\r\n %337 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %336, i32 0, i32 3\r\n %338 = load i32, ptr %337, align 4, !noundef !5\r\n %339 = getelementptr inbounds [7 x i32], ptr %315, i64 0, i64 3\r\n store i32 %338, ptr %339, align 4\r\n %340 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %341 = getelementptr inbounds %Adt50, ptr %340, i32 0, i32 3\r\n %342 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %341, i32 0, i32 1\r\n %343 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %342, i32 0, i32 3\r\n %344 = load i32, ptr %343, align 4, !noundef !5\r\n %345 = getelementptr inbounds [7 x i32], ptr %315, i64 0, i64 4\r\n store i32 %344, ptr %345, align 8\r\n %346 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %347 = getelementptr inbounds %Adt50, ptr %346, i32 0, i32 3\r\n %348 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %347, i32 0, i32 1\r\n %349 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %348, i32 0, i32 3\r\n %350 = load i32, ptr %349, align 4, !noundef !5\r\n %351 = getelementptr inbounds [7 x i32], ptr %315, i64 0, i64 5\r\n store i32 %350, ptr %351, align 4\r\n %352 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %353 = getelementptr inbounds %Adt50, ptr %352, i32 0, i32 3\r\n %354 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %353, i32 0, i32 1\r\n %355 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %354, i32 0, i32 3\r\n %356 = load i32, ptr %355, align 4, !noundef !5\r\n %357 = getelementptr inbounds [7 x i32], ptr %315, i64 0, i64 6\r\n store i32 %356, ptr %357, align 8\r\n %358 = getelementptr inbounds %Adt50, ptr %_15, i32 0, i32 3\r\n %359 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %358, i32 0, i32 1\r\n %360 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %359, i32 0, i32 5\r\n %361 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %362 = getelementptr inbounds %Adt50, ptr %361, i32 0, i32 3\r\n %363 = load i128, ptr %362, align 16, !noundef !5\r\n store i128 %363, ptr %360, align 16\r\n %364 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %365 = getelementptr inbounds %Adt50, ptr %364, i32 0, i32 3\r\n %366 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %365, i32 0, i32 1\r\n %367 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %366, i32 0, i32 1\r\n %368 = load double, ptr %_7, align 8, !noundef !5\r\n store double %368, ptr %367, align 8\r\n %369 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %370 = getelementptr inbounds %Adt50, ptr %369, i32 0, i32 3\r\n %371 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %370, i32 0, i32 2\r\n %372 = load double, ptr %371, align 16, !noundef !5\r\n store double %372, ptr %_7, align 8\r\n %373 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 1\r\n %374 = load i8, ptr %373, align 2, !noundef !5\r\n switch i8 %374, label %bb4 [\r\n i8 0, label %bb1\r\n i8 84, label %bb5\r\n ]\r\n\r\nbb5: ; preds = %bb4\r\n %375 = getelementptr inbounds %Adt50, ptr %_15, i32 0, i32 3\r\n %376 = getelementptr inbounds { i128, { i64, double, i32, i32, [2 x i32], i128 }, double, [6 x i32] }, ptr %375, i32 0, i32 1\r\n %377 = getelementptr inbounds { i64, double, i32, i32, [2 x i32], i128 }, ptr %376, i32 0, i32 5\r\n %378 = load i128, ptr %377, align 16, !noundef !5\r\n store i128 %378, ptr %_5, align 16\r\n %379 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 1\r\n %380 = load i64, ptr %379, align 8, !noundef !5\r\n store i64 %380, ptr %_10, align 16\r\n %381 = load i8, ptr %_16, align 1, !range !6, !noundef !5\r\n %382 = trunc i8 %381 to i1\r\n %383 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %384 = zext i1 %382 to i8\r\n store i8 %384, ptr %383, align 8\r\n %385 = load i64, ptr %_10, align 16, !noundef !5\r\n switch i64 %385, label %bb8 [\r\n i64 2, label %bb6\r\n i64 7564290096487423208, label %bb7\r\n ]\r\n\r\nbb8: ; preds = %bb7, %bb5\r\n ret void\r\n\r\nbb6: ; preds = %bb5\r\n %386 = getelementptr inbounds %Adt51, ptr %_10, i32 0, i32 2\r\n %387 = getelementptr inbounds %Adt50, ptr %386, i32 0, i32 1\r\n %388 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %387, i32 0, i32 1\r\n %389 = getelementptr inbounds { i16, i8, [5 x i8], i64 }, ptr %_1, i32 0, i32 1\r\n %390 = load i8, ptr %389, align 2, !noundef !5\r\n store i8 %390, ptr %388, align 2\r\n %391 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 1\r\n %392 = load i64, ptr %391, align 8, !noundef !5\r\n %393 = getelementptr inbounds { double, { i64, i64, i64 }, i16, i8, [5 x i8] }, ptr %_7, i32 0, i32 1\r\n %394 = load i64, ptr %393, align 8, !noundef !5\r\n %395 = call { i64, i1 } @llvm.smul.with.overflow.i64(i64 %392, i64 %394)\r\n %396 = extractvalue { i64, i1 } %395, 0\r\n %397 = extractvalue { i64, i1 } %395, 1\r\n store i64 %396, ptr %_10, align 16\r\n %398 = getelementptr inbounds i8, ptr %_10, i64 8\r\n %399 = zext i1 %397 to i8\r\n store i8 %399, ptr %398, align 8\r\n br label %bb3\r\n\r\nbb7: ; preds = %bb5\r\n %400 = load i128, ptr %_5, align 16, !noundef !5\r\n; call _1851685_debug_2::bbox2\r\n call void @_ZN16_1851685_debug_25bbox217he0199f2e11de3e04E(i128 %400, ptr align 8 %_14)\r\n br label %bb8\r\n}\r\n\r\n; _1851685_debug_2::fn15\r\n; Function Attrs: nonlazybind uwtable\r\ndefine internal i128 @_ZN16_1851685_debug_24fn1517hfe3f07cbb5faefb0E() unnamed_addr #1 {\r\nstart:\r\n %_0 = alloca i128, align 16\r\n store i128 0, ptr %_0, align 16\r\n; call core::hint::black_box\r\n call void @_ZN4core4hint9black_box17ha89c3f9cb79c398cE()\r\n %0 = load i128, ptr %_0, align 16, !noundef !5\r\n ret i128 %0\r\n}\r\n\r\n; _1851685_debug_2::main\r\n; Function Attrs: nonlazybind uwtable\r\ndefine internal void @_ZN16_1851685_debug_24main17he76cece459490d8aE() unnamed_addr #1 {\r\nstart:\r\n; call _1851685_debug_2::enter\r\n call void @_ZN16_1851685_debug_25enter17h7e9cae7a334c5019E()\r\n ret void\r\n}\r\n\r\n; _1851685_debug_2::bbox2\r\n; Function Attrs: noinline nonlazybind uwtable\r\ndefine internal void @_ZN16_1851685_debug_25bbox217he0199f2e11de3e04E(i128 %val1, ptr align 8 %val2) unnamed_addr #0 {\r\nstart:\r\n %_6 = alloca { i16, i8, [5 x i8], i64 }, align 8\r\n %_5 = alloca { i16, i8, [5 x i8], i64 }, align 8\r\n; call _1851685_debug_2::print_i128\r\n call void @_ZN16_1851685_debug_210print_i12817h036b4f930abaf46cE(i128 %val1)\r\n call void @llvm.memcpy.p0.p0.i64(ptr align 8 %_6, ptr align 8 %val2, i64 16, i1 false)\r\n; call core::hint::black_box\r\n call void @_ZN4core4hint9black_box17h7d48bc7feb0af96eE(ptr sret({ i16, i8, [5 x i8], i64 }) align 8 %_5, ptr align 8 %_6)\r\n ret void\r\n}\r\n\r\n; _1851685_debug_2::print_i128\r\n; Function Attrs: nonlazybind uwtable\r\ndefine internal void @_ZN16_1851685_debug_210print_i12817h036b4f930abaf46cE(i128 %x) unnamed_addr #1 {\r\nstart:\r\n %_9 = lshr i128 %x, 64\r\n %_8 = trunc i128 %_9 to i64\r\n %_14 = trunc i128 %x to i64\r\n %_2 = call i32 (ptr, ...) @printf(ptr @alloc_2cdd8ac758b4c372b56d8683306290e0, i64 %_8, i64 %_14)\r\n ret void\r\n}\r\n\r\n; Function Attrs: nonlazybind uwtable\r\ndefine i32 @rust_eh_personality(i32, i32, i64, ptr, ptr) unnamed_addr #1 {\r\nstart:\r\n ret i32 0\r\n}\r\n\r\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)\r\ndeclare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3\r\n\r\n; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)\r\ndeclare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare { i64, i1 } @llvm.ssub.with.overflow.i64(i64, i64) #5\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare { i64, i1 } @llvm.smul.with.overflow.i64(i64, i64) #5\r\n\r\n; Function Attrs: nonlazybind uwtable\r\ndeclare i32 @printf(ptr, ...) unnamed_addr #1\r\n\r\n; Function Attrs: nonlazybind\r\ndefine i32 @main(i32 %0, ptr %1) unnamed_addr #6 {\r\ntop:\r\n call void @_ZN16_1851685_debug_25enter17h7e9cae7a334c5019E()\r\n ret i32 0\r\n}\r\n\r\nattributes #0 = { noinline nonlazybind uwtable \"probe-stack\"=\"inline-asm\" \"target-cpu\"=\"x86-64\" }\r\nattributes #1 = { nonlazybind uwtable \"probe-stack\"=\"inline-asm\" \"target-cpu\"=\"x86-64\" }\r\nattributes #2 = { inlinehint nonlazybind uwtable \"probe-stack\"=\"inline-asm\" \"target-cpu\"=\"x86-64\" }\r\nattributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }\r\nattributes #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }\r\nattributes #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\nattributes #6 = { nonlazybind \"target-cpu\"=\"x86-64\" }\r\n\r\n!llvm.module.flags = !{!0, !1, !2}\r\n!llvm.ident = !{!3}\r\n\r\n!0 = !{i32 8, !\"PIC Level\", i32 2}\r\n!1 = !{i32 7, !\"PIE Level\", i32 2}\r\n!2 = !{i32 2, !\"RtLibUseGOT\", i32 1}\r\n!3 = !{!\"rustc version 1.78.0-dev\"}\r\n!4 = !{i32 753499}\r\n!5 = !{}\r\n!6 = !{i8 0, i8 2}\r\n\r\n```\r\n\r\nRight:\r\n```console\r\n$ clang -O1 1851685_debug_2.ll && ./a.out\r\nhi:-1 lo:-2580139605333929408\r\n```\r\n\r\nWrong:\r\n```console\r\n$ clang -O2 1851685_debug_2.ll && ./a.out\r\nhi:0 lo:-2580139605333929408\r\n```\r\n\r\nBisects down to \r\n```\r\nBISECT: running pass (504) InstCombinePass on _ZN16_1851685_debug_25enter17h7e9cae7a334c5019E\r\n```\r\n\r\nVersion:\r\n```\r\nclang version 19.0.0git (https://github.com/llvm/llvm-project.git cd1d4d8dd31f527615de26f5b62d687c6b2982a6)\r\nTarget: x86_64-unknown-linux-gnu\r\nThread model: posix\r\nInstalledDir: /opt/compiler-explorer/clang-trunk/bin\r\nCompiler returned: 0\r\n```\r\n\r\n\r\n<details>\r\n<summary>From Rust custom MIR</summary>\r\n\r\n```rust\r\n#![feature(custom_mir, core_intrinsics)]\r\nextern crate core;\r\nuse core::intrinsics::mir::*;\r\n\r\npub fn enter() {\r\n fn14((0, 0, 0), [0; 6]);\r\n}\r\n\r\n#[custom_mir(dialect = \"runtime\", phase = \"initial\")]\r\npub fn fn14(mut _3: (i8, u16, isize), mut _6: [i32; 6]) {\r\n mir! {\r\n let _1: u128;\r\n let _2: i128;\r\n let _4: (i128,);\r\n let _5: i128;\r\n let _9: Adt59;\r\n let _11: isize;\r\n let _12: bool;\r\n let _13: Adt51;\r\n let _15: isize;\r\n let _16: Adt53;\r\n let _21: (i32, [i32; 6], (i8, u16, isize), [usize; 4]);\r\n let _23: (i8, u16, isize);\r\n let _25: Adt58;\r\n let _26: Adt52;\r\n let _44: ();\r\n {\r\n _2 = 0;\r\n _5 = 0;\r\n _3 = (84_i8, 40096_u16, (-9223372036854775808_isize));\r\n Goto(bb2)\r\n }\r\n bb1 = {\r\n Return()\r\n }\r\n bb2 = {\r\n _9.fld3.1.0.0 = 145713751_u32 as f64;\r\n _9.fld5 = _3.1 % 62066_u16;\r\n _13.fld1 = Checked(3029947793098001587_i64 - (-3638983068927244405_i64));\r\n _12 = _13.fld1.1 ^ _13.fld1.1;\r\n _9.fld6 = core::ptr::addr_of!(_13.fld1);\r\n _9.fld4 = (16948196345300582164_u64,);\r\n _13.fld3.fld4 = [168516996_i32,245529160_i32,1223136339_i32,1622354325_i32,(-1002348909_i32),1976405017_i32,(-1442509311_i32),1165829790_i32];\r\n _13.fld3.fld6.1 = -_9.fld3.1.0.0;\r\n _11 = !_3.2;\r\n _13.fld1 = (7564290096487423208_i64, _12);\r\n _13.fld3.fld6.2.0 = _11;\r\n _9.fld3.2.0 = _13.fld1.0;\r\n Call(_13.fld3.fld6.2.4 = fn15(), ReturnTo(bb3), UnwindUnreachable())\r\n }\r\n bb3 = {\r\n _13.fld0.0 = _9.fld3.2.0 as i16;\r\n _13.fld2 = _9.fld4.0 as isize;\r\n _13.fld3.fld5.1.0 = _13.fld3.fld6.2.4.0 >> _2;\r\n _9.fld3.1.0.0 = -_13.fld3.fld6.1;\r\n _13.fld0.2 = !_13.fld1.1;\r\n _13.fld3.fld5.3 = [_13.fld0.0];\r\n Goto(bb4)\r\n }\r\n bb4 = {\r\n _13.fld3.fld3.0 = _3.0;\r\n _6 = [(-154507050_i32),2086635898_i32,468582002_i32,(-21184342_i32),(-1173629817_i32),(-2078649110_i32)];\r\n _13.fld3.fld5.1.0 = _5;\r\n _16.fld0.2 = _13.fld0.2;\r\n _13.fld3.fld5.0 = _13.fld0.0 * _13.fld0.0;\r\n _9.fld2 = 2797771210_u32 + 2127377746_u32;\r\n _9.fld3.1.0.0 = _9.fld2 as f64;\r\n _15 = -_11;\r\n _13.fld0 = (_13.fld3.fld5.0, _13.fld3.fld5.1, _12, _13.fld3.fld5.3);\r\n _13.fld1 = Checked(_9.fld3.2.0 * _9.fld3.2.0);\r\n Goto(bb5)\r\n }\r\n bb5 = {\r\n _13.fld3.fld6.1 = _9.fld3.1.0.0 / 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012739273109665954_f64;\r\n _13.fld4 = !6496701646011298799_usize;\r\n _3 = (_13.fld3.fld3.0, _9.fld5, _15);\r\n _13.fld3.fld6.2.1 = _9.fld2;\r\n _13.fld0.2 = _13.fld0.1.0 >= _5;\r\n _13.fld3.fld3.2 = _3.2 & _11;\r\n _13.fld6 = [_13.fld0.2,_13.fld1.1,_16.fld0.2,_16.fld0.2,_13.fld0.2,_13.fld1.1];\r\n _13.fld3.fld6.2.4 = _13.fld3.fld5.1;\r\n _9.fld3.0 = -_13.fld0.0;\r\n _13.fld3.fld0 = core::ptr::addr_of!(_9.fld4.0);\r\n _9.fld0 = [_3.0];\r\n _13.fld5 = _13.fld3.fld4;\r\n _13.fld3.fld6.2.3 = _13.fld4 as i32;\r\n _3.2 = _13.fld3.fld3.2 ^ _13.fld3.fld6.2.0;\r\n _13.fld3.fld6.1 = _9.fld3.1.0.0;\r\n _23.0 = !_3.0;\r\n _13.fld3.fld3.1 = _13.fld1.1 as u16;\r\n _13.fld3.fld5.1.0 = _13.fld3.fld6.2.3 as i128;\r\n _13.fld3.fld6.2.3 = _13.fld3.fld3.1 as i32;\r\n Goto(bb7)\r\n }\r\n bb7 = {\r\n _23.0 = _13.fld3.fld6.2.3 as i8;\r\n _21.2 = (_23.0, _3.1, _13.fld3.fld3.2);\r\n _23.2 = _9.fld5 as isize;\r\n _13.fld3.fld6.0 = _13.fld1.0 as i128;\r\n _26.fld0 = _13.fld0.2 & _13.fld1.1;\r\n _9.fld3.2.2 = _3.2 ^ _23.2;\r\n _23 = (_21.2.0, _3.1, _9.fld3.2.2);\r\n _13.fld3.fld2 = [_13.fld3.fld6.2.3,_13.fld3.fld6.2.3,_13.fld3.fld6.2.3,_13.fld3.fld6.2.3,_13.fld3.fld6.2.3,_13.fld3.fld6.2.3,_13.fld3.fld6.2.3];\r\n _25.fld3.fld6.2.4 = (_13.fld3.fld6.0,);\r\n _13.fld3.fld6.2.2 = _9.fld3.1.0.0;\r\n _9.fld3.1.0.0 = _13.fld3.fld6.1;\r\n match _3.0 {\r\n 0 => bb2,\r\n 84 => bb10,\r\n _ => bb7\r\n }\r\n }\r\n bb10 = {\r\n _4 = (_25.fld3.fld6.2.4.0,);\r\n _13.fld1 = (_9.fld3.2.0, _26.fld0);\r\n match _13.fld1.0 {\r\n 2 => bb14,\r\n 7564290096487423208 => bb18,\r\n _ => bb19\r\n }\r\n }\r\n bb14 = {\r\n _13.fld3.fld3.0 = _3.0;\r\n _13.fld1 = Checked(_9.fld3.2.0 * _9.fld3.2.0);\r\n Goto(bb5)\r\n }\r\n bb18 = {\r\n Call(_44 = bbox2(_4, Move(_23)), ReturnTo(bb19), UnwindUnreachable())\r\n }\r\n bb19 = {\r\n Return()\r\n }\r\n\r\n }\r\n}\r\n\r\n#[custom_mir(dialect = \"runtime\", phase = \"initial\")]\r\nfn fn15() -> (i128,) {\r\n mir! {\r\n let unit:();\r\n let _37: ();\r\n {\r\n RET = (0,);\r\n Call(_37 = core::hint::black_box(unit), ReturnTo(bb16), UnwindUnreachable())\r\n }\r\n bb16 = {\r\n Return()\r\n }\r\n\r\n }\r\n}\r\npub fn main() {\r\n enter();\r\n}\r\n\r\n#[derive(Debug)]\r\npub struct Adt49 {}\r\n#[derive(Debug)]\r\npub struct Adt50 {\r\n fld0: *const u64,\r\n fld2: [i32; 7],\r\n fld3: (i8, u16, isize),\r\n fld4: [i32; 8],\r\n fld5: (i16, (i128,), bool, [i16; 1]),\r\n fld6: (i128, f64, (isize, u32, f64, i32, (i128,)), [i32; 6]),\r\n}\r\n#[derive(Debug)]\r\npub struct Adt51 {\r\n fld0: (i16, (i128,), bool, [i16; 1]),\r\n fld1: (i64, bool),\r\n fld2: isize,\r\n fld3: Adt50,\r\n fld4: usize,\r\n fld5: [i32; 8],\r\n fld6: [bool; 6],\r\n}\r\n#[derive(Debug)]\r\npub struct Adt52 {\r\n fld0: bool,\r\n}\r\n#[derive(Debug)]\r\npub struct Adt53 {\r\n fld0: (i16, (i128,), bool, [i16; 1]),\r\n}\r\n#[derive(Debug)]\r\npub struct Adt58 {\r\n fld3: Adt50,\r\n}\r\n#[derive(Debug, Copy, Clone)]\r\npub struct Adt59 {\r\n fld0: [i8; 1],\r\n fld2: u32,\r\n fld3: (i16, ((f64,),), (i64, isize, isize), u8),\r\n fld4: (u64,),\r\n fld5: u16,\r\n fld6: *const (i64, bool),\r\n}\r\n\r\n#[inline(never)]\r\npub fn bbox2(val1: (i128,), val2: (i8, u16, isize)) {\r\n use core::hint::black_box;\r\n print_i128(val1.0);\r\n black_box(val2);\r\n}\r\n\r\n#[cfg(not(miri))]\r\nfn print_i128(x: i128) {\r\n extern \"C\" {\r\n fn printf(fmt: *const core::ffi::c_char, ...) -> core::ffi::c_int;\r\n }\r\n unsafe {\r\n printf(\r\n b\"hi:%ld lo:%ld\\n\\0\".as_ptr().cast(),\r\n (x as u128 >> 64) as i64,\r\n x as i64,\r\n );\r\n }\r\n}\r\n\r\n#[cfg(miri)]\r\nfn print_i128(x: i128) {\r\n println!(\"hi:{} lo:{}\", (x as u128 >> 64) as i64, x as i64);\r\n}\r\n\r\n```\r\n\r\n</details>\r\n",
"author": "cbeuw",
"labels": [
"miscompilation",
"llvm:transforms"
],
"comments": [
{
"author": "dtcxzyw",
"body": "Reproducer: https://godbolt.org/z/xs1rhnMvb\r\nAlive2: https://alive2.llvm.org/ce/z/gyL7mn\r\n\r\nI will post a fix later.\r\n"
}
]
} | true | null |
88796 | https://github.com/llvm/llvm-project/issues/88796 | crash | 9ef28cf88ca6e45c3ecb75c649463f8797db68d2 | 2024-04-15T21:04:00 | [
"llvm/test/Transforms/VectorCombine"
] | {
"fix_commit": "57b9c15227ec15a5e2abf4587d7d0ad536cff9e6",
"components": [
"VectorCombine"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [
[
1961,
1977
]
],
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": [
"VectorCombine::foldTruncFromReductions"
],
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 57b9c15227ec15a5e2abf4587d7d0ad536cff9e6
Author: Ramkumar Ramachandra <[email protected]>
Date: Wed May 8 09:47:55 2024 +0100
VectorCombine: fix logical error after m_Trunc match (#91201)
The matcher m_Trunc() matches an Operator with a given Opcode, which
could either be an Instruction or ConstExpr.
VectorCombine::foldTruncFromReductions() incorrectly assumes that the
pattern matched is always an Instruction, and attempts a cast. Fix this.
Fixes #88796.
diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index bbb70134870a..8573a8adf53b 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -1961,17 +1961,17 @@ bool VectorCombine::foldTruncFromReductions(Instruction &I) {
if (!match(ReductionSrc, m_OneUse(m_Trunc(m_Value(TruncSrc)))))
return false;
- auto *Trunc = cast<CastInst>(ReductionSrc);
auto *TruncSrcTy = cast<VectorType>(TruncSrc->getType());
auto *ReductionSrcTy = cast<VectorType>(ReductionSrc->getType());
Type *ResultTy = I.getType();
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
- InstructionCost OldCost =
- TTI.getCastInstrCost(Instruction::Trunc, ReductionSrcTy, TruncSrcTy,
- TTI::CastContextHint::None, CostKind, Trunc) +
- TTI.getArithmeticReductionCost(ReductionOpc, ReductionSrcTy, std::nullopt,
- CostKind);
+ InstructionCost OldCost = TTI.getArithmeticReductionCost(
+ ReductionOpc, ReductionSrcTy, std::nullopt, CostKind);
+ if (auto *Trunc = dyn_cast<CastInst>(ReductionSrc))
+ OldCost +=
+ TTI.getCastInstrCost(Instruction::Trunc, ReductionSrcTy, TruncSrcTy,
+ TTI::CastContextHint::None, CostKind, Trunc);
InstructionCost NewCost =
TTI.getArithmeticReductionCost(ReductionOpc, TruncSrcTy, std::nullopt,
CostKind) +
| [
{
"file": "llvm/test/Transforms/VectorCombine/pr88796.ll",
"commands": [
"opt -passes=vector-combine -S %s"
],
"tests": [
{
"test_name": "test",
"test_body": "define i32 @test() {\nentry:\n %0 = tail call i16 @llvm.vector.reduce.and.nxv8i16(<vscale x 8 x i16> trunc (<vscale x 8 x i32> splat (i32 268435456) to <vscale x 8 x i16>))\n ret i32 0\n}\n\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\ndeclare i16 @llvm.vector.reduce.and.nxv8i16(<vscale x 8 x i16>) #0\n\nattributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[VectorCombine] Assertion 'isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed.",
"body": "Reduced LLVM IR:\r\n```llvm ir\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\ndefine i32 @main() #0 {\r\nentry:\r\n %0 = tail call i16 @llvm.vector.reduce.and.nxv8i16(<vscale x 8 x i16> trunc (<vscale x 8 x i32> shufflevector (<vscale x 8 x i32> insertelement (<vscale x 8 x i32> poison, i32 268435456, i64 0), <vscale x 8 x i32> poison, <vscale x 8 x i32> zeroinitializer) to <vscale x 8 x i16>))\r\n ret i32 0\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i16 @llvm.vector.reduce.and.nxv8i16(<vscale x 8 x i16>) #1\r\n\r\nattributes #0 = { \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v,+zicsr,+zifencei,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl256b,+zvl32b,+zvl64b,-e,-experimental-smmpm,-experimental-smnpm,-experimental-ssnpm,-experimental-sspm,-experimental-ssqosid,-experimental-supm,-experimental-zaamo,-experimental-zabha,-experimental-zalasr,-experimental-zalrsc,-experimental-zfbfmin,-experimental-zicfilp,-experimental-zicfiss,-experimental-ztso,-experimental-zvfbfmin,-experimental-zvfbfwma,-h,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smepmp,-ssaia,-ssccptr,-sscofpmf,-sscounterenw,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-za128rs,-za64rs,-zacas,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-zvbb,-zvbc,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b\" }\r\nattributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\nGodbolt: https://godbolt.org/z/jrEv178Ev\r\n\r\nBacktrace:\r\n```\r\nopt: /scratch/tc-testing/tc-apr-15/llvm/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = llvm::CastInst; From = llvm::Value]: Assertion `isa<To>(Val) && \"cast<Ty>() argument of incompatible type!\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt --passes=vector-combine reduced.ll\r\n #0 0x00005eb857c5a1b0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x2da91b0)\r\n #1 0x00005eb857c575bf llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x2da65bf)\r\n #2 0x00005eb857c57715 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x000071f7d0e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x000071f7d0e969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x000071f7d0e969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x000071f7d0e969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x000071f7d0e42476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x000071f7d0e287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x000071f7d0e2871b _nl_load_domain ./intl/loadmsgcat.c:1177:9\r\n#10 0x000071f7d0e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n#11 0x00005eb856da36eb (anonymous namespace)::VectorCombine::run()::'lambda'(llvm::Instruction&)::operator()(llvm::Instruction&) const VectorCombine.cpp:0:0\r\n#12 0x00005eb856da4290 llvm::VectorCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x1ef3290)\r\n#13 0x00005eb855bc7936 llvm::detail::PassModel<llvm::Function, llvm::VectorCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0xd16936)\r\n#14 0x00005eb857a7f451 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x2bce451)\r\n#15 0x00005eb855bbec26 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0xd0dc26)\r\n#16 0x00005eb857a7e12b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x2bcd12b)\r\n#17 0x00005eb855bc6ee6 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0xd15ee6)\r\n#18 0x00005eb857a7bf61 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x2bcaf61)\r\n#19 0x00005eb855440205 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x58f205)\r\n#20 0x00005eb855432836 optMain (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x581836)\r\n#21 0x000071f7d0e29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#22 0x000071f7d0e29e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#23 0x000071f7d0e29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#24 0x00005eb8554284b5 _start (/scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/opt+0x5774b5)\r\nzsh: IOT instruction /scratch/tc-testing/tc-apr-15/build-rv64gcv/build-llvm-linux/bin/op\r\n```\r\n\r\nFound via fuzzer.",
"author": "patrick-rivos",
"labels": [
"vectorizers",
"crash"
],
"comments": []
} | true | null |
120823 | https://github.com/llvm/llvm-project/issues/120823 | miscompilation | 9d0a5d4620a2aa5dc01b150e5ebe7613238cae1c | 2024-12-21T05:25:23 | [
"llvm/test/Transforms/SLPVectorizer"
] | {
"fix_commit": "030829a7e53fad0eab9b87b5dd49427e9fb13303",
"components": [
"SLPVectorizer"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
[
15483,
15488
]
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": [
"BoUpSLP::vectorizeTree"
],
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 030829a7e53fad0eab9b87b5dd49427e9fb13303
Author: Alexey Bataev <[email protected]>
Date: Mon Dec 23 16:53:37 2024 -0800
[SLP]Drop samesign flag if the vector node has reduced bitwidth
If the operands of the icmp instructions has reduced bitwidth after
MinBitwidth analysis, need to drop samesign flag to preserve correctness
of the transformation.
Fixes #120823
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index d22379429d00..b5d68c075b98 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -15483,6 +15483,8 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
CmpInst::Predicate P0 = cast<CmpInst>(VL0)->getPredicate();
Value *V = Builder.CreateCmp(P0, L, R);
propagateIRFlags(V, E->Scalars, VL0);
+ if (auto *ICmp = dyn_cast<ICmpInst>(V); ICmp && It == MinBWs.end())
+ ICmp->setSameSign(/*B=*/false);
// Do not cast for cmps.
VecTy = cast<FixedVectorType>(V->getType());
V = FinalShuffle(V, E);
| [
{
"file": "llvm/test/Transforms/SLPVectorizer/X86/buildvector-schedule-for-subvector.ll",
"commands": [
"opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu -slp-threshold=-99999 < %s"
],
"tests": [
{
"test_name": "test",
"test_body": "define i1 @test() {\nentry:\n %and.i1698.1.i = zext i16 0 to i32\n %and19.i1699.2.i = and i32 %and.i1698.1.i, 0\n %and.i1698.2.i = zext i16 0 to i32\n %cmp25.i1700.2.i2 = icmp samesign uge i32 %and19.i1699.2.i, %and.i1698.1.i\n %and19.i1699.11841.i = and i32 %and.i1698.2.i, 0\n %cmp25.i1700.11842.i3 = icmp samesign uge i32 %and19.i1699.11841.i, %and.i1698.2.i\n %and.i1698.1.1.i = zext i16 0 to i32\n %and19.i1699.2.1.i = and i32 %and.i1698.1.1.i, 0\n %0 = add i16 1, 0\n %and.i1698.2.1.i = zext i16 %0 to i32\n %cmp25.i1700.2.1.i4 = icmp samesign uge i32 %and19.i1699.2.1.i, %and.i1698.1.1.i\n %and19.i1699.21846.i = and i32 %and.i1698.2.1.i, 0\n %cmp25.i1700.21847.i = icmp samesign uge i32 %and19.i1699.21846.i, %and.i1698.2.1.i\n ret i1 %cmp25.i1700.21847.i\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[SLPVectorizer] `samesign` flags should be dropped after narrowing down the width of operands",
"body": "Reproducer: https://alive2.llvm.org/ce/z/AvBhy9\n```\n; bin/opt -passes=slp-vectorizer test.ll -S\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i1 @test() {\nentry:\n %and.i1698.1.i = zext i16 0 to i32\n %and19.i1699.2.i = and i32 %and.i1698.1.i, 0\n %and.i1698.2.i = zext i16 0 to i32\n %cmp25.i1700.2.i2 = icmp samesign uge i32 %and19.i1699.2.i, %and.i1698.1.i\n %and19.i1699.11841.i = and i32 %and.i1698.2.i, 0\n %cmp25.i1700.11842.i3 = icmp samesign uge i32 %and19.i1699.11841.i, %and.i1698.2.i\n %and.i1698.1.1.i = zext i16 0 to i32\n %and19.i1699.2.1.i = and i32 %and.i1698.1.1.i, 0\n %0 = add i16 1, 0\n %and.i1698.2.1.i = zext i16 %0 to i32\n %cmp25.i1700.2.1.i4 = icmp samesign uge i32 %and19.i1699.2.1.i, %and.i1698.1.1.i\n %and19.i1699.21846.i = and i32 %and.i1698.2.1.i, 0\n %cmp25.i1700.21847.i = icmp samesign uge i32 %and19.i1699.21846.i, %and.i1698.2.1.i\n ret i1 %cmp25.i1700.21847.i\n}\n```\n```\ndefine i1 @test() {\nentry:\n %0 = add i16 1, 0\n %1 = insertelement <4 x i16> <i16 poison, i16 0, i16 0, i16 0>, i16 %0, i32 0\n %2 = trunc <4 x i16> %1 to <4 x i1>\n %3 = and <4 x i1> %2, zeroinitializer\n %4 = icmp samesign uge <4 x i1> %3, %2\n %5 = extractelement <4 x i1> %4, i32 0\n ret i1 %5\n}\n```\n```\n\n----------------------------------------\ndefine i1 @src() {\nentry:\n %#0 = add i16 1, 0\n %and.i1698.2.1.i = zext i16 %#0 to i32\n %and19.i1699.21846.i = and i32 %and.i1698.2.1.i, 0\n %cmp25.i1700.21847.i = icmp samesign uge i32 %and19.i1699.21846.i, %and.i1698.2.1.i\n ret i1 %cmp25.i1700.21847.i\n}\n=>\ndefine i1 @src() {\nentry:\n %#0 = add i16 1, 0\n %#1 = insertelement <4 x i16> { poison, 0, 0, 0 }, i16 %#0, i32 0\n %#2 = trunc <4 x i16> %#1 to <4 x i1>\n %#3 = and <4 x i1> %#2, { 0, 0, 0, 0 }\n %#4 = icmp samesign uge <4 x i1> %#3, %#2\n %#5 = extractelement <4 x i1> %#4, i32 0\n ret i1 %#5\n}\nTransformation doesn't verify!\n\nERROR: Target is more poisonous than source\n\nExample:\n\nSource:\ni16 %#0 = #x0001 (1)\ni32 %and.i1698.2.1.i = #x00000001 (1)\ni32 %and19.i1699.21846.i = #x00000000 (0)\ni1 %cmp25.i1700.21847.i = #x0 (0)\n\nTarget:\ni16 %#0 = #x0001 (1)\n<4 x i16> %#1 = < #x0001 (1), #x0000 (0), #x0000 (0), #x0000 (0) >\n<4 x i1> %#2 = < #x1 (1), #x0 (0), #x0 (0), #x0 (0) >\n<4 x i1> %#3 = < #x0 (0), #x0 (0), #x0 (0), #x0 (0) >\n<4 x i1> %#4 = < poison, #x1 (1), #x1 (1), #x1 (1) >\ni1 %#5 = poison\nSource value: #x0 (0)\nTarget value: poison\n\nSummary:\n 0 correct transformations\n 1 incorrect transformations\n 0 failed-to-prove transformations\n 0 Alive2 errors\n```\n",
"author": "dtcxzyw",
"labels": [
"miscompilation",
"llvm:SLPVectorizer"
],
"comments": []
} | true | null |
89959 | https://github.com/llvm/llvm-project/issues/89959 | crash | bc8a4ea11070d06374b403cd09b771a99cc6ba1a | 2024-04-24T17:43:58 | [
"llvm/test/Transforms/IRCE"
] | {
"fix_commit": "22da5a6e34ed6146752b24d9156a678b50fddaef",
"components": [
"InductiveRangeCheckElimination"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": [
[
279,
284
]
],
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": [
"InductiveRangeCheck::parseRangeCheckICmp"
],
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 22da5a6e34ed6146752b24d9156a678b50fddaef
Author: Yingwei Zheng <[email protected]>
Date: Fri Apr 26 16:25:33 2024 +0800
[IRCE] Skip icmp ptr in `InductiveRangeCheck::parseRangeCheckICmp` (#89967)
Fixes https://github.com/llvm/llvm-project/issues/89959.
diff --git a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
index 9df28747570c..104e8ceb7967 100644
--- a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
@@ -279,6 +279,9 @@ bool InductiveRangeCheck::parseRangeCheckICmp(Loop *L, ICmpInst *ICI,
Value *LHS = ICI->getOperand(0);
Value *RHS = ICI->getOperand(1);
+ if (!LHS->getType()->isIntegerTy())
+ return false;
+
// Canonicalize to the `Index Pred Invariant` comparison
if (IsLoopInvariant(LHS)) {
std::swap(LHS, RHS);
| [
{
"file": "llvm/test/Transforms/IRCE/pr89959.ll",
"commands": [
"opt -passes=irce -S < %s 2>&1"
],
"tests": [
{
"test_name": "<module>",
"test_body": "\n; Make sure we don't crash.\ndefine void @pr89959() {\n;\ntop:\n br label %L3\n\nL3:\n %value_phi = phi ptr [ null, %top ], [ %0, %L13 ]\n %0 = getelementptr i8, ptr %value_phi, i64 8\n %.not = icmp ule ptr %value_phi, null\n br i1 %.not, label %L13, label %L15\n\nL13:\n br label %L3\n\nL15:\n ret void\n}",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "Assertion in Scalar Evolution when running IRCE",
"body": "The following IR crashes with \r\n```llvm\r\ndefine void @foo() {\r\ntop:\r\n br label %L3\r\n\r\nL3: ; preds = %L13, %top\r\n %value_phi = phi ptr [ null, %top ], [ %0, %L13 ]\r\n %0 = getelementptr i8, ptr %value_phi, i64 8\r\n %.not = icmp ule ptr %value_phi, null\r\n br i1 %.not, label %L13, label %L15\r\n\r\nL13: ; preds = %L3\r\n br label %L3\r\n\r\nL15: ; preds = %L3\r\n ret void\r\n}\r\n```\r\n\r\n`opt --passes=irce` \r\n\r\nhttps://godbolt.org/z/1sbvaT7r1 ",
"author": "gbaraldi",
"labels": [
"llvm:SCEV",
"crash-on-valid"
],
"comments": []
} | true | null |
87798 | https://github.com/llvm/llvm-project/issues/87798 | crash | 49ef12a08c4c7d7ae4765929e72fe2320a12b08c | 2024-04-05T16:02:46 | [
"llvm/test/Analysis/ScalarEvolution"
] | {
"fix_commit": "54a9f0007cb4f19d2e9df30405c5027229f5def0",
"components": [
"ScalarEvolution"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": [
[
928,
938
]
],
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": [
"BinomialCoefficient"
],
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit 54a9f0007cb4f19d2e9df30405c5027229f5def0
Author: annamthomas <[email protected]>
Date: Wed Apr 10 09:02:23 2024 -0400
[SCEV] Fix BinomialCoefficient Iteration to fit in W bits (#88010)
BinomialCoefficient computes the value of W-bit IV at iteration It of a loop. When W is 1, we can call multiplicative inverse on 0 which triggers an assert since 1b76120.
Since the arithmetic is supposed to wrap if It or K does not fit in W bits, do the truncation into W bits after we do the shift.
Fixes #87798
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index e030b9fc7dac..9fcce797f559 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -928,11 +928,9 @@ static const SCEV *BinomialCoefficient(const SCEV *It, unsigned K,
APInt OddFactorial(W, 1);
unsigned T = 1;
for (unsigned i = 3; i <= K; ++i) {
- APInt Mult(W, i);
- unsigned TwoFactors = Mult.countr_zero();
+ unsigned TwoFactors = countr_zero(i);
T += TwoFactors;
- Mult.lshrInPlace(TwoFactors);
- OddFactorial *= Mult;
+ OddFactorial *= (i >> TwoFactors);
}
// We need at least W + T bits for the multiplication step
| [
{
"file": "llvm/test/Analysis/ScalarEvolution/pr87798.ll",
"commands": [
"opt -disable-output -passes='print<scalar-evolution>' -verify-scev < %s 2>&1"
],
"tests": [
{
"test_name": "pr87798",
"test_body": "target datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\ntarget triple = \"x86_64-unknown-linux-gnu\"\n\ndefine i32 @pr87798() {\nbb:\n br label %bb1\n\nbb1: ; preds = %bb1, %bb\n %phi = phi i32 [ 0, %bb ], [ %add4, %bb1 ]\n %phi2 = phi i32 [ 0, %bb ], [ %add, %bb1 ]\n %phi3 = phi i32 [ 0, %bb ], [ %add5, %bb1 ]\n %add = add i32 %phi2, %phi3\n %mul = mul i32 %phi2, %phi3\n %add4 = add i32 %mul, %phi\n %and = and i32 %phi, 1\n %add5 = add i32 %phi3, 1\n br i1 true, label %preheader, label %bb1\n\npreheader: ; preds = %bb1\n %phi9 = phi i32 [ %and, %bb1 ]\n br label %loop\n\nloop: ; preds = %loop, %preheader\n br label %loop\n\nbb7: ; No predecessors!\n %zext = zext i32 %phi9 to i64\n ret i32 0\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "Assertion failure: \"multiplicative inverse is only defined for odd numbers\" exposed through usage in SCEV",
"body": "With this change [1b76120](https://github.com/llvm/llvm-project/commit/1b761205f2686516cebadbcbc37f798197d9c482) landed in https://github.com/llvm/llvm-project/pull/87610, we started seeing an assertion failure on the introduced API.\r\n\r\nThis change caused an assertion failure in usage of multiplicativeInverse in SCEV's BinomialCoefficient algorithm (which was also updated by the change to use this overloaded API). The `oddFactorial` in this algorithm becomes 0 and the assertion in newly introduced API gets triggered. Note that the old API for multiplicativeInverse (which passed in the explicit modulo) returned 0 when the input was also 0, and probably hid this bug in SCEV. \r\n\r\nHere's a minimal reproducer for trunk:\r\n```\r\ntarget datalayout = \"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2\"\r\ntarget triple = \"x86_64-unknown-linux-gnu\"\r\n\r\ndefine i32 @\"static jint Test.iMeth(jlong, jint, jint)2272037699586\"() {\r\nbci_0:\r\n br label %bci_71.preheader\r\n\r\nbci_71.preheader: ; preds = %bci_71.preheader, %bci_0\r\n %local_9_242 = phi i32 [ 0, %bci_0 ], [ %1, %bci_71.preheader ]\r\n %local_7_241 = phi i32 [ 0, %bci_0 ], [ %0, %bci_71.preheader ]\r\n %local_4_239 = phi i32 [ 0, %bci_0 ], [ %3, %bci_71.preheader ]\r\n %0 = add i32 %local_7_241, %local_4_239\r\n %.neg14 = mul i32 %local_7_241, %local_4_239\r\n %1 = add i32 %.neg14, %local_9_242\r\n %2 = and i32 %local_9_242, 1\r\n %3 = add i32 %local_4_239, 1\r\n br i1 true, label %bci_10.i38.preheader, label %bci_71.preheader\r\n\r\nbci_10.i38: ; preds = %bci_10.i38.preheader, %bci_10.i38\r\n br label %bci_10.i38\r\n\r\n\"static jlong FuzzerUtils.checkSum(jobject)2306397437964.exit\": ; No predecessors!\r\n %4 = zext i32 %.lcssa596 to i64\r\n ret i32 0\r\n\r\nbci_10.i38.preheader: ; preds = %bci_71.preheader\r\n %.lcssa596 = phi i32 [ %2, %bci_71.preheader ]\r\n br label %bci_10.i38\r\n}\r\n```\r\n\r\nopt -passes=indvars reduced.ll produces:\r\n```\r\nopt: /root/llvm-project/llvm/lib/Support/APInt.cpp:1245: llvm::APInt llvm::APInt::multiplicativeInverse() const: Assertion `(*this)[0] && \"multiplicative inverse is only defined for odd numbers!\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=indvars <source>\r\n #0 0x0000000004cfc568 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4cfc568)\r\n #1 0x0000000004cf9cbc SignalHandler(int) Signals.cpp:0:0\r\n #2 0x00007f7209e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x00007f7209e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x00007f7209e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x00007f7209e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x00007f7209e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x00007f7209e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x0000000004bf9eff llvm::APInt::multiplicativeInverse() const (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4bf9eff)\r\n #9 0x000000000443a4b5 llvm::SCEVAddRecExpr::evaluateAtIteration(llvm::ArrayRef<llvm::SCEV const*>, llvm::SCEV const*, llvm::ScalarEvolution&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x443a4b5)\r\n#10 0x000000000443cb4f llvm::ScalarEvolution::computeSCEVAtScope(llvm::SCEV const*, llvm::Loop const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x443cb4f)\r\n#11 0x000000000443cfee llvm::ScalarEvolution::getSCEVAtScope(llvm::SCEV const*, llvm::Loop const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x443cfee)\r\n#12 0x000000000443c525 llvm::ScalarEvolution::computeSCEVAtScope(llvm::SCEV const*, llvm::Loop const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x443c525)\r\n#13 0x000000000443cfee llvm::ScalarEvolution::getSCEVAtScope(llvm::SCEV const*, llvm::Loop const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x443cfee)\r\n#14 0x000000000404eca0 llvm::rewriteLoopExitValues(llvm::Loop*, llvm::LoopInfo*, llvm::TargetLibraryInfo*, llvm::ScalarEvolution*, llvm::TargetTransformInfo const*, llvm::SCEVExpander&, llvm::DominatorTree*, llvm::ReplaceExitVal, llvm::SmallVector<llvm::WeakTrackingVH, 16u>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x404eca0)\r\n#15 0x0000000003a10fd8 (anonymous namespace)::IndVarSimplify::run(llvm::Loop*) IndVarSimplify.cpp:0:0\r\n#16 0x0000000003a11c1a llvm::IndVarSimplifyPass::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3a11c1a)\r\n#17 0x00000000029ffd4e llvm::detail::PassModel<llvm::Loop, llvm::IndVarSimplifyPass, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x29ffd4e)\r\n#18 0x0000000003aaef56 std::optional<llvm::PreservedAnalyses> llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runSinglePass<llvm::Loop, std::unique_ptr<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, std::default_delete<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>>>>(llvm::Loop&, std::unique_ptr<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>, std::default_delete<llvm::detail::PassConcept<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>>>&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&, llvm::PassInstrumentation&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3aaef56)\r\n#19 0x0000000003aaf1ee llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::runWithoutLoopNestPasses(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3aaf1ee)\r\n#20 0x0000000003ab05d9 llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3ab05d9)\r\n...\r\n```",
"author": "annamthomas",
"labels": [
"llvm:SCEV",
"crash"
],
"comments": [
{
"author": "topperc",
"body": "CC @jayfoad "
},
{
"author": "annamthomas",
"body": "I think the old API (multiplicativeInverse when modulo provided) was hiding this bug since multiplicative inverse shouldn't be asked for 0.\r\nAlso, the reason the `oddFactorial` becomes 0 here is because of this:\r\n```\r\n// Calculate K! / 2^T and T; we divide out the factors of two before\r\n // multiplying for calculating K! / 2^T to avoid overflow.\r\n // Other overflow doesn't matter because we only care about the bottom\r\n // W bits of the result.\r\n APInt OddFactorial(W, 1);\r\n unsigned T = 1;\r\n for (unsigned i = 3; i <= K; ++i) {\r\n APInt Mult(W, i);\r\n unsigned TwoFactors = Mult.countr_zero();\r\n T += TwoFactors;\r\n Mult.lshrInPlace(TwoFactors);\r\n OddFactorial *= Mult; \r\n }\r\n ```\r\n\r\nHere, W is one (bit width = 1 and I believe this is the bug) and we are trying to represent Mult=4 in one bit. That makes `Mult` 0 and hence `OddFactorial` 0.\r\n\r\nOne thing we can obviously do is in the newly introduced API, explicitly check if the APInt is 0 and return 0 (this makes behaviour same as the old API).\r\nBut I think this is hiding the bug. "
},
{
"author": "jayfoad",
"body": "Suggestion:\r\n```diff\r\ndiff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp\r\nindex e030b9fc7dac..3f8c390614ff 100644\r\n--- a/llvm/lib/Analysis/ScalarEvolution.cpp\r\n+++ b/llvm/lib/Analysis/ScalarEvolution.cpp\r\n@@ -928,11 +928,9 @@ static const SCEV *BinomialCoefficient(const SCEV *It, unsigned K,\r\n APInt OddFactorial(W, 1);\r\n unsigned T = 1;\r\n for (unsigned i = 3; i <= K; ++i) {\r\n- APInt Mult(W, i);\r\n- unsigned TwoFactors = Mult.countr_zero();\r\n+ unsigned TwoFactors = countr_zero(i);\r\n T += TwoFactors;\r\n- Mult.lshrInPlace(TwoFactors);\r\n- OddFactorial *= Mult;\r\n+ OddFactorial *= i >> TwoFactors;\r\n }\r\n \r\n // We need at least W + T bits for the multiplication step\r\n```"
},
{
"author": "annamthomas",
"body": "yes, that would probably work as well (since we avoid representing Mult in W bit width), but how can the bitWidth of the SCEV result`W` be 1 in the first place? "
},
{
"author": "jayfoad",
"body": "> yes, that would probably work as well (since we avoid representing Mult in W bit width), but how can the bitWidth of the SCEV result`W` be 1 in the first place?\r\n\r\nNo idea! I have only looked at `BinomialCoefficient` itself, not at its callers. I assume it is supposed to work for any W > 0 and K > 0. At least I don't see it mentioned that K has to be representable in W bits, or anything like that."
},
{
"author": "efriedma-quic",
"body": "The function is supposed to compute `BC(It, K) mod 2^W`, i.e. the binomial coefficient truncated to fit into a W-bit integer. This is useful for computing the value of a W-bit induction variable at iteration \"It\" of a loop. There isn't any expectation that \"It\" or \"K\" fit losslessly into \"W\": the arithmetic is supposed to wrap.\r\n\r\nGiven the way the function works, truncating \"i\" after the shift looks like the right solution."
}
]
} | true | null |
97590 | https://github.com/llvm/llvm-project/issues/97590 | crash | ed51908cec879c9dff435abdc70d8b03afc35c07 | 2024-07-03T15:09:36 | [
"llvm/test/Transforms/Inline"
] | {
"fix_commit": "be7239e5a60927f5b4932f995dc4b57423ea8534",
"components": [
"InlineCost"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": [
[
2644,
2651
]
],
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": null,
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": [
"CallAnalyzer::stripAndComputeInBoundsConstantOffsets"
],
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit be7239e5a60927f5b4932f995dc4b57423ea8534
Author: Yingwei Zheng <[email protected]>
Date: Tue Jul 9 15:08:04 2024 +0800
[Inline] Remove bitcast handling in `CallAnalyzer::stripAndComputeInBoundsConstantOffsets` (#97988)
As we are now using opaque pointers, bitcast handling is no longer
needed.
Closes https://github.com/llvm/llvm-project/issues/97590.
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index 94aa8ecf6f55..345e5a019520 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -2644,8 +2644,6 @@ ConstantInt *CallAnalyzer::stripAndComputeInBoundsConstantOffsets(Value *&V) {
if (!GEP->isInBounds() || !accumulateGEPOffset(*GEP, Offset))
return nullptr;
V = GEP->getPointerOperand();
- } else if (Operator::getOpcode(V) == Instruction::BitCast) {
- V = cast<Operator>(V)->getOperand(0);
} else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
if (GA->isInterposable())
break;
| [
{
"file": "llvm/test/Transforms/Inline/pr97590.ll",
"commands": [
"opt -S -passes=inline < %s"
],
"tests": [
{
"test_name": "<module>",
"test_body": "\n; Check that we don't crash when computing the\n; base pointer of `bitcast <1 x ptr> to ptr`\n\ndefine void @caller(<1 x ptr> %x) {\n;\nentry:\n %p = bitcast <1 x ptr> %x to ptr\n call void @callee(ptr %p)\n ret void\n}\n\ndefine void @callee(ptr %p) {\n;\nentry:\n ret void\n}",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[Inline] Assertion `V->getType()->isPointerTy() && \"Unexpected operand type!\"' failed.",
"body": "Reproducer: https://godbolt.org/z/qGc1Kx5YK\r\n```\r\n; bin/opt -passes=inline reduced.ll -S\r\ndefine i32 @func_120(i1 %tobool626, ptr %g_231, ptr %l_506, i1 %tobool724, ptr %p) {\r\nentry:\r\n %0 = bitcast i1 %tobool626 to <1 x i1>\r\n call void @llvm.masked.store.v1i64.p0(<1 x i64> zeroinitializer, ptr %g_231, i32 8, <1 x i1> %0)\r\n %1 = xor i1 %tobool626, true\r\n %2 = bitcast i1 %1 to <1 x i1>\r\n %3 = call <1 x ptr> @llvm.masked.load.v1p0.p0(ptr %g_231, i32 8, <1 x i1> %2, <1 x ptr> poison)\r\n %4 = bitcast <1 x ptr> %3 to ptr\r\n br i1 %tobool626, label %common.ret, label %if.else647\r\n\r\ncommon.ret: ; preds = %entry, %lor.end739\r\n ret i32 0\r\n\r\nif.else647: ; preds = %entry\r\n br i1 %tobool724, label %land.rhs725, label %lor.end739\r\n\r\nland.rhs725: ; preds = %if.else647\r\n %call726 = load i32, ptr %p, align 4\r\n br label %lor.end739\r\n\r\nlor.end739: ; preds = %land.rhs725, %if.else647\r\n %call745 = call i32 @func_136(ptr %4)\r\n br label %common.ret\r\n}\r\n\r\ndefine i32 @func_136(ptr nocapture readnone %p_137) {\r\nentry:\r\n ret i32 0\r\n}\r\n\r\n```\r\n```\r\nopt: /root/llvm-project/llvm/lib/Analysis/InlineCost.cpp:2656: llvm::ConstantInt* {anonymous}::CallAnalyzer::stripAndComputeInBoundsConstantOffsets(llvm::Value*&): Assertion `V->getType()->isPointerTy() && \"Unexpected operand type!\"' failed.\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0.\tProgram arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=inline <source>\r\n1.\tRunning pass \"cgscc(inline)\" on module \"<source>\"\r\n #0 0x0000000004e7cf38 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4e7cf38)\r\n #1 0x0000000004e7a69c SignalHandler(int) Signals.cpp:0:0\r\n #2 0x000077b96f042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #3 0x000077b96f0969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)\r\n #4 0x000077b96f042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)\r\n #5 0x000077b96f0287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)\r\n #6 0x000077b96f02871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)\r\n #7 0x000077b96f039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)\r\n #8 0x00000000043ea53a (anonymous namespace)::CallAnalyzer::analyze() (.part.0) InlineCost.cpp:0:0\r\n #9 0x00000000043eb650 llvm::getInlineCost(llvm::CallBase&, llvm::Function*, llvm::InlineParams const&, llvm::TargetTransformInfo&, llvm::function_ref<llvm::AssumptionCache& (llvm::Function&)>, llvm::function_ref<llvm::TargetLibraryInfo const& (llvm::Function&)>, llvm::function_ref<llvm::BlockFrequencyInfo& (llvm::Function&)>, llvm::ProfileSummaryInfo*, llvm::OptimizationRemarkEmitter*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43eb650)\r\n#10 0x00000000043ebba6 llvm::getInlineCost(llvm::CallBase&, llvm::InlineParams const&, llvm::TargetTransformInfo&, llvm::function_ref<llvm::AssumptionCache& (llvm::Function&)>, llvm::function_ref<llvm::TargetLibraryInfo const& (llvm::Function&)>, llvm::function_ref<llvm::BlockFrequencyInfo& (llvm::Function&)>, llvm::ProfileSummaryInfo*, llvm::OptimizationRemarkEmitter*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43ebba6)\r\n#11 0x00000000043ed0ab llvm::InlineCost llvm::function_ref<llvm::InlineCost (llvm::CallBase&)>::callback_fn<getDefaultInlineAdvice(llvm::CallBase&, llvm::AnalysisManager<llvm::Function>&, llvm::InlineParams const&)::'lambda2'(llvm::CallBase&)>(long, llvm::CallBase&) InlineAdvisor.cpp:0:0\r\n#12 0x00000000043f310d llvm::shouldInline(llvm::CallBase&, llvm::function_ref<llvm::InlineCost (llvm::CallBase&)>, llvm::OptimizationRemarkEmitter&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43f310d)\r\n#13 0x00000000043f4af5 getDefaultInlineAdvice(llvm::CallBase&, llvm::AnalysisManager<llvm::Function>&, llvm::InlineParams const&) InlineAdvisor.cpp:0:0\r\n#14 0x00000000043f4d3b llvm::DefaultInlineAdvisor::getAdviceImpl(llvm::CallBase&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43f4d3b)\r\n#15 0x00000000043eda71 llvm::InlineAdvisor::getAdvice(llvm::CallBase&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43eda71)\r\n#16 0x000000000371e48d llvm::InlinerPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x371e48d)\r\n#17 0x0000000002e127ae llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::InlinerPass, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2e127ae)\r\n#18 0x000000000431385b llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x431385b)\r\n#19 0x0000000002e1154e llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2e1154e)\r\n#20 0x00000000043155b9 llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x43155b9)\r\n#21 0x0000000002e1152e llvm::detail::PassModel<llvm::Module, llvm::ModuleToPostOrderCGSCCPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x2e1152e)\r\n#22 0x0000000004c780c0 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x4c780c0)\r\n#23 0x00000000008d8702 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8d8702)\r\n#24 0x00000000008cb60c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8cb60c)\r\n#25 0x000077b96f029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)\r\n#26 0x000077b96f029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)\r\n#27 0x00000000008c2a6e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x8c2a6e)\r\nProgram terminated with signal: SIGSEGV\r\nCompiler returned: 139\r\n```\r\nhttps://github.com/llvm/llvm-project/blob/f1a8f94bba8b090a0d667065e4b8b4fc66b6a5cc/llvm/lib/Analysis/InlineCost.cpp#L2647-L2648\r\nshould be removed as we use opaque pointers now.\r\n",
"author": "dtcxzyw",
"labels": [
"crash-on-valid",
"llvm:analysis"
],
"comments": [
{
"author": "dtcxzyw",
"body": "Related patch: #96878 "
},
{
"author": "dtcxzyw",
"body": "Reduced reproducer: https://godbolt.org/z/rbjK6ETEW\r\n```\r\n; bin/opt -passes=inline reduced.ll -S\r\ndefine void @caller(<1 x ptr> %x) {\r\nentry:\r\n %p = bitcast <1 x ptr> %x to ptr\r\n call void @callee(ptr %p)\r\n ret void\r\n}\r\n\r\ndefine void @callee(ptr %p) {\r\nentry:\r\n ret void\r\n}\r\n```"
}
]
} | true | null |
83931 | https://github.com/llvm/llvm-project/issues/83931 | crash | d95a0d7c0ff324c1e84606d26591416e6bf02984 | 2024-03-05T00:39:01 | [
"llvm/test/Transforms/InstCombine"
] | {
"fix_commit": "d51fcd4ed86ac6075c8a25b053c2b66051feaf62",
"components": [
"InstCombine"
],
"bug_location_lineno": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": [
[
6544,
6549
]
],
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineInternal.h": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanValue.h": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/include/llvm/Analysis/ValueTracking.h": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/include/llvm/Analysis/LoopCacheAnalysis.h": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/include/llvm/IR/CmpPredicate.h": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.h": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/include/llvm/Analysis/MemorySSAUpdater.h": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/ScalarEvolution.h": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
},
"bug_location_funcname": {
"llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp": null,
"llvm/lib/Transforms/Scalar/Scalarizer.cpp": null,
"llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp": [
"InstCombiner::getFlippedStrictnessPredicateAndConstant"
],
"llvm/lib/Transforms/Coroutines/CoroSplit.cpp": null,
"llvm/lib/IR/Operator.cpp": null,
"llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorize.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp": null,
"llvm/lib/Analysis/ValueTracking.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyIndVar.cpp": null,
"llvm/lib/Analysis/ScalarEvolution.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp": null,
"llvm/lib/Transforms/Scalar/GVNSink.cpp": null,
"llvm/lib/Transforms/Vectorize/VectorCombine.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp": null,
"llvm/lib/Transforms/InstCombine/InstructionCombining.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp": null,
"llvm/lib/Transforms/Utils/ValueMapper.cpp": null,
"llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.h": null,
"llvm/lib/Transforms/Scalar/ConstraintElimination.cpp": null,
"llvm/lib/Analysis/InstructionSimplify.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp": null,
"llvm/lib/Transforms/Utils/Local.cpp": null,
"llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp": null,
"llvm/lib/Analysis/InlineCost.cpp": null,
"llvm/lib/Transforms/Scalar/BDCE.cpp": null,
"llvm/lib/Transforms/Utils/LoopPeel.cpp": null,
"llvm/lib/Analysis/LoopCacheAnalysis.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.h": null,
"llvm/lib/Transforms/Vectorize/VPlan.cpp": null,
"llvm/lib/Transforms/Utils/SimplifyCFG.cpp": null,
"llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp": null,
"llvm/lib/Transforms/Scalar/LICM.cpp": null,
"llvm/lib/Analysis/LazyValueInfo.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp": null,
"llvm/lib/IR/Instructions.cpp": null,
"llvm/lib/Transforms/Scalar/EarlyCSE.cpp": null,
"llvm/lib/Transforms/Utils/DemoteRegToStack.cpp": null,
"llvm/lib/Analysis/ConstantFolding.cpp": null,
"llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h": null,
"llvm/lib/Transforms/Scalar/Reassociate.cpp": null,
"llvm/lib/IR/Value.cpp": null,
"llvm/lib/Analysis/MemorySSAUpdater.cpp": null,
"llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp": null,
"llvm/lib/IR/AsmWriter.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp": null,
"llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp": null,
"llvm/include/llvm/Analysis/SimplifyQuery.h": null,
"llvm/lib/IR/ConstantFold.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp": null,
"llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp": null,
"llvm/lib/Transforms/Utils/LowerSwitch.cpp": null,
"llvm/lib/Transforms/Vectorize/VPlanUtils.cpp": null,
"llvm/include/llvm/Analysis/AliasAnalysis.h": null,
"llvm/include/llvm/Analysis/BasicAliasAnalysis.h": null,
"llvm/lib/Analysis/BasicAliasAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/JumpThreading.cpp": null,
"llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp": null,
"llvm/lib/Transforms/Utils/MoveAutoInit.cpp": null,
"llvm/lib/Transforms/Utils/SCCPSolver.cpp": null,
"llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp": null,
"llvm/lib/Analysis/LoopAccessAnalysis.cpp": null,
"llvm/lib/Transforms/Scalar/IndVarSimplify.cpp": null,
"llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp": null,
"llvm/include/llvm/IR/PatternMatch.h": null,
"llvm/lib/Transforms/IPO/AttributorAttributes.cpp": null,
"llvm/lib/Transforms/Scalar/GVN.cpp": null,
"llvm/lib/Transforms/Scalar/NewGVN.cpp": null
}
} | commit d51fcd4ed86ac6075c8a25b053c2b66051feaf62
Author: Yingwei Zheng <[email protected]>
Date: Tue Mar 5 21:08:15 2024 +0800
[InstCombine] Handle scalable splat in `getFlippedStrictnessPredicateAndConstant` (#83980)
This patch adds support for canonicalization of icmp with a scalable
splat. Some optimizations assume that `icmp pred X, APInt C` is in
canonical form.
Fixes https://github.com/llvm/llvm-project/issues/83931.
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 55207a8343d0..1cebab8203ea 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -6544,6 +6544,13 @@ InstCombiner::getFlippedStrictnessPredicateAndConstant(CmpInst::Predicate Pred,
if (!SafeReplacementConstant)
SafeReplacementConstant = CI;
}
+ } else if (isa<VectorType>(C->getType())) {
+ // Handle scalable splat
+ Value *SplatC = C->getSplatValue();
+ auto *CI = dyn_cast_or_null<ConstantInt>(SplatC);
+ // Bail out if the constant can't be safely incremented/decremented.
+ if (!CI || !ConstantIsOk(CI))
+ return std::nullopt;
} else {
// ConstantExpr?
return std::nullopt;
| [
{
"file": "llvm/test/Transforms/InstCombine/pr83931.ll",
"commands": [
"opt -S -passes=instcombine < %s"
],
"tests": [
{
"test_name": "dont_crash",
"test_body": "define <vscale x 2 x i1> @dont_crash(<vscale x 2 x i64> %x) {\nentry:\n %div = sdiv <vscale x 2 x i64> %x, splat (i64 309383)\n %ret = icmp sge <vscale x 2 x i64> %div, zeroinitializer\n ret <vscale x 2 x i1> %ret\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/InstCombine/select.ll",
"commands": [
"opt < %s -passes=instcombine -S"
],
"tests": [
{
"test_name": "scalable_sign_bits",
"test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine <vscale x 2 x i32> @scalable_sign_bits(<vscale x 2 x i8> %x) {\n %a = sext <vscale x 2 x i8> %x to <vscale x 2 x i32>\n %b = shl <vscale x 2 x i32> %a, splat (i32 16)\n ret <vscale x 2 x i32> %b\n}\n",
"lli_expected_out": null,
"additional_args": null
},
{
"test_name": "scalable_non_zero",
"test_body": "target datalayout = \"e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64\"\n\ndefine <vscale x 2 x i1> @scalable_non_zero(<vscale x 2 x i32> %x) {\n %a = or <vscale x 2 x i32> %x, splat (i32 1)\n %b = add <vscale x 2 x i32> %a, splat (i32 -1)\n %cmp = icmp ult <vscale x 2 x i32> %b, splat (i32 56)\n ret <vscale x 2 x i1> %cmp\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
},
{
"file": "llvm/test/Transforms/InstCombine/vscale_cmp.ll",
"commands": [
"opt < %s -passes=instcombine -S"
],
"tests": [
{
"test_name": "sge",
"test_body": "define <vscale x 2 x i1> @sge(<vscale x 2 x i8> %x) {\n %cmp = icmp sge <vscale x 2 x i8> %x, zeroinitializer\n ret <vscale x 2 x i1> %cmp\n}\n",
"lli_expected_out": null,
"additional_args": null
}
]
}
] | {
"title": "[InstCombine][RISC-V] UNREACHABLE executed at InstCombineCompares.cpp:2788",
"body": "Testcase:\r\n```c\r\nchar a;\r\nint b;\r\nlong *c[5][5];\r\nint main() {\r\n for (int d = -2041027590; d; d++)\r\n a |= b <= c[3][d][8] / 309383;\r\n}\r\n```\r\n\r\nReduced LLVM IR:\r\n```llvm ir\r\n; ModuleID = 'reduced.ll'\r\nsource_filename = \"red.c\"\r\ntarget datalayout = \"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128\"\r\ntarget triple = \"riscv64-unknown-linux-gnu\"\r\n\r\n; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: read, inaccessiblemem: none) uwtable vscale_range(2,1024)\r\ndefine noundef signext i32 @main() #0 {\r\nentry:\r\n %0 = getelementptr inbounds i8, <vscale x 2 x ptr> zeroinitializer, i64 64\r\n %wide.masked.gather = call <vscale x 2 x i64> @llvm.masked.gather.nxv2i64.nxv2p0(<vscale x 2 x ptr> %0, i32 8, <vscale x 2 x i1> shufflevector (<vscale x 2 x i1> insertelement (<vscale x 2 x i1> poison, i1 true, i64 0), <vscale x 2 x i1> poison, <vscale x 2 x i32> zeroinitializer), <vscale x 2 x i64> poison)\r\n %1 = sdiv <vscale x 2 x i64> %wide.masked.gather, shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> poison, i64 309383, i64 0), <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer)\r\n %2 = icmp sge <vscale x 2 x i64> %1, zeroinitializer\r\n %3 = zext <vscale x 2 x i1> %2 to <vscale x 2 x i8>\r\n %4 = call i8 @llvm.vector.reduce.or.nxv2i8(<vscale x 2 x i8> %3)\r\n store i8 %4, ptr null, align 1\r\n ret i32 0\r\n}\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind willreturn memory(read)\r\ndeclare <vscale x 2 x i64> @llvm.masked.gather.nxv2i64.nxv2p0(<vscale x 2 x ptr>, i32 immarg, <vscale x 2 x i1>, <vscale x 2 x i64>) #1\r\n\r\n; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)\r\ndeclare i8 @llvm.vector.reduce.or.nxv2i8(<vscale x 2 x i8>) #2\r\n\r\n; uselistorder directives\r\nuselistorder <vscale x 2 x i64> poison, { 1, 2, 0 }\r\n\r\nattributes #0 = { nofree norecurse nosync nounwind memory(readwrite, argmem: read, inaccessiblemem: none) uwtable vscale_range(2,1024) \"no-trapping-math\"=\"true\" \"stack-protector-buffer-size\"=\"8\" \"target-cpu\"=\"generic-rv64\" \"target-features\"=\"+64bit,+a,+c,+d,+f,+m,+relax,+v\" }\r\nattributes #1 = { nocallback nofree nosync nounwind willreturn memory(read) }\r\nattributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }\r\n```\r\n\r\nBacktrace:\r\n```\r\n> /scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt -passes=\"instcombine\" reduced.ll --disable-output\r\nUnhandled icmp predicate!\r\nUNREACHABLE executed at /scratch/tc-testing/tc-feb-22-llvm/llvm/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:2788!\r\nPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.\r\nStack dump:\r\n0. Program arguments: /scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt -passes=instcombine reduced.ll --disable-output\r\n #0 0x00005565be2171a0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt+0x2ce31a0)\r\n #1 0x00005565be2145af llvm::sys::RunSignalHandlers() (/scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt+0x2ce05af)\r\n #2 0x00005565be214705 SignalHandler(int) Signals.cpp:0:0\r\n #3 0x00007f8b9f842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)\r\n #4 0x00007f8b9f8969fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76\r\n #5 0x00007f8b9f8969fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10\r\n #6 0x00007f8b9f8969fc pthread_kill ./nptl/pthread_kill.c:89:10\r\n #7 0x00007f8b9f842476 gsignal ./signal/../sysdeps/posix/raise.c:27:6\r\n #8 0x00007f8b9f8287f3 abort ./stdlib/abort.c:81:7\r\n #9 0x00005565be14ca5e (/scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt+0x2c18a5e)\r\n#10 0x00005565bd1c1139 llvm::InstCombinerImpl::foldICmpDivConstant(llvm::ICmpInst&, llvm::BinaryOperator*, llvm::APInt const&) (/scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt+0x1c8d139)\r\n#11 0x00005565bd1d710e llvm::InstCombinerImpl::foldICmpBinOpWithConstant(llvm::ICmpInst&, llvm::BinaryOperator*, llvm::APInt const&) (/scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt+0x1ca310e)\r\n#12 0x00005565bd1d7393 llvm::InstCombinerImpl::foldICmpInstWithConstant(llvm::ICmpInst&) (/scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt+0x1ca3393)\r\n#13 0x00005565bd1e46eb llvm::InstCombinerImpl::visitICmpInst(llvm::ICmpInst&) (/scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt+0x1cb06eb)\r\n#14 0x00005565bd1457a5 llvm::InstCombinerImpl::run() (/scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt+0x1c117a5)\r\n#15 0x00005565bd146e85 combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::ProfileSummaryInfo*, llvm::LoopInfo*, llvm::InstCombineOptions const&) InstructionCombining.cpp:0:0\r\n#16 0x00005565bd147ef5 llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt+0x1c13ef5)\r\n#17 0x00005565bc1e5c96 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt+0xcb1c96)\r\n#18 0x00005565be044751 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt+0x2b10751)\r\n#19 0x00005565bc1dd5b6 llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt+0xca95b6)\r\n#20 0x00005565be04344b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt+0x2b0f44b)\r\n#21 0x00005565bc1e5746 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt+0xcb1746)\r\n#22 0x00005565be0412c1 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt+0x2b0d2c1)\r\n#23 0x00005565bba77e55 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt+0x543e55)\r\n#24 0x00005565bba6a296 optMain (/scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt+0x536296)\r\n#25 0x00007f8b9f829d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16\r\n#26 0x00007f8b9f829e40 call_init ./csu/../csu/libc-start.c:128:20\r\n#27 0x00007f8b9f829e40 __libc_start_main ./csu/../csu/libc-start.c:379:5\r\n#28 0x00005565bba5f5a5 _start (/scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt+0x52b5a5)\r\nzsh: IOT instruction (core dumped) /scratch/tc-testing/tc-feb-22-llvm/build/build-llvm-linux/bin/opt reduced.ll\r\n```\r\n\r\nGodbolt: https://godbolt.org/z/9qdYfPTrE\r\n\r\nAssert being tripped: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp#L2788\r\n\r\nFound via fuzzer.",
"author": "patrick-rivos",
"labels": [
"crash",
"llvm:instcombine"
],
"comments": [
{
"author": "dtcxzyw",
"body": "Reduced test case: https://godbolt.org/z/5qocbWsW3\r\n```\r\ndefine <vscale x 2 x i1> @test(<vscale x 2 x i64> %p) {\r\nentry:\r\n %1 = sdiv <vscale x 2 x i64> %p, splat (i64 309383)\r\n %2 = icmp sge <vscale x 2 x i64> %1, zeroinitializer\r\n ret <vscale x 2 x i1> %2\r\n}\r\n\r\n```"
}
]
} | true | null |
Subsets and Splits