[llvm] ea5ee40 - [SLP]Fix miscompile of absorbing lanes in flattened chains
via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 11 06:15:14 PDT 2026
Author: Alexey Bataev
Date: 2026-10-11T09:15:09-04:00
New Revision: ea5ee402aa9851793fd5159e59a54a4f831b9528
URL: https://github.com/llvm/llvm-project/commit/ea5ee402aa9851793fd5159e59a54a4f831b9528
DIFF: https://github.com/llvm/llvm-project/commit/ea5ee402aa9851793fd5159e59a54a4f831b9528.diff
LOG: [SLP]Fix miscompile of absorbing lanes in flattened chains
The operand columns, peeled while flattening the associative chains,
modeled the lane with the absorbing constant as op(C, poison). Such
lanes belong to the real instructions of the flattened node, so the
poison operand is not frozen there and the lane becomes poison. Keep the
identity as the other operand for the peeled columns.
Follow-up to #228872.
Reviewers:
Pull Request: https://github.com/llvm/llvm-project/pull/230959
Added:
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/test/Transforms/SLPVectorizer/X86/wide-load-absorbed-lane.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index a6922c644582c..1b881e2f05b64 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -11628,9 +11628,9 @@ class InstructionsCompatibilityAnalysis {
return S;
}
- SmallVector<BoUpSLP::ValueList> buildOperands(const InstructionsState &S,
- ArrayRef<Value *> VL,
- const BoUpSLP &R) {
+ SmallVector<BoUpSLP::ValueList>
+ buildOperands(const InstructionsState &S, ArrayRef<Value *> VL,
+ const BoUpSLP &R, bool AllowPoisonPlaceholders = true) {
assert(S && "Invalid state!");
SmallVector<BoUpSLP::ValueList> Operands;
if (S.areInstructionsWithCopyableElements()) {
@@ -11660,7 +11660,8 @@ class InstructionsCompatibilityAnalysis {
Operands.assign(NumMainOpOperands,
BoUpSLP::ValueList(VL.size(), nullptr));
SmallPtrSet<const Value *, 4> SelfOpLanes = findSelfOpLanes(S, VL, R);
- const bool PoisonPlaceholders = canUsePoisonPlaceholders(S, VL);
+ const bool PoisonPlaceholders =
+ AllowPoisonPlaceholders && canUsePoisonPlaceholders(S, VL);
// Populate operands for every lane.
for (auto [Idx, V] : enumerate(VL)) {
SmallVector<Value *> OperandsForValue =
@@ -12201,8 +12202,10 @@ static void scanAssociativeOperands(
continue;
}
BoUpSLP::ValueList Column = std::move(Columns[Idx].Col);
- SmallVector<BoUpSLP::ValueList> SubOperands =
- Analysis.buildOperands(ColS, Column, R);
+ // The absorbing constants of the peeled lanes keep the identity as the
+ // other operand: the poison operand is not frozen in the flattened node.
+ SmallVector<BoUpSLP::ValueList> SubOperands = Analysis.buildOperands(
+ ColS, Column, R, /*AllowPoisonPlaceholders=*/false);
assert(SubOperands.size() == 2 && "Expected 2 operand columns.");
// Poison and copyable lanes have no real instruction left to erase
// later: a copyable V is used as-is, not subsumed by the flattened
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/wide-load-absorbed-lane.ll b/llvm/test/Transforms/SLPVectorizer/X86/wide-load-absorbed-lane.ll
index 701c20f11faf8..2066414c01181 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/wide-load-absorbed-lane.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/wide-load-absorbed-lane.ll
@@ -423,7 +423,7 @@ define void @reassoc_absorbing_lane(ptr %p) {
; CHECK-NEXT: [[TMP0:%.*]] = load <2 x i32>, ptr [[P]], align 4
; CHECK-NEXT: [[TMP1:%.*]] = add <2 x i32> [[TMP0]], <i32 -3, i32 -1>
; CHECK-NEXT: [[TMP2:%.*]] = and <2 x i32> [[TMP1]], <i32 -1, i32 255>
-; CHECK-NEXT: [[TMP3:%.*]] = or <2 x i32> <i32 256, i32 poison>, [[TMP2]]
+; CHECK-NEXT: [[TMP3:%.*]] = or <2 x i32> <i32 256, i32 0>, [[TMP2]]
; CHECK-NEXT: [[TMP4:%.*]] = or <2 x i32> [[TMP3]], <i32 16, i32 -1>
; CHECK-NEXT: store <2 x i32> [[TMP4]], ptr [[P]], align 4
; CHECK-NEXT: ret void
More information about the llvm-commits
mailing list