[llvm] 609d421 - [SLP] Do not vectorize copyable operands of expanded binops
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 11 07:15:11 PDT 2026
Author: Alexey Bataev
Date: 2026-06-11T10:15:05-04:00
New Revision: 609d4215f1d760c84254b88600a3add7bdeb42d3
URL: https://github.com/llvm/llvm-project/commit/609d4215f1d760c84254b88600a3add7bdeb42d3
DIFF: https://github.com/llvm/llvm-project/commit/609d4215f1d760c84254b88600a3add7bdeb42d3.diff
LOG: [SLP] Do not vectorize copyable operands of expanded binops
An operand modeled as a copyable element on one operand edge of an
expanded binop (shl X, 1 represented as add X, X) leaves the duplicated
operand edge as a plain gathered operand with no copyable. The scheduler
then decrements that operand's ScheduleData for a use calculateDependencies
never counted for it, so its unscheduled-deps counter goes negative and
trips the assertion. Reject such bundles instead.
Fixes #203193
Reviewers:
Pull Request: https://github.com/llvm/llvm-project/pull/203285
Added:
llvm/test/Transforms/SLPVectorizer/X86/expanded-binop-copyable-operand-deps.ll
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 8a2e5a97f7573..68d7c0295a41f 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -25418,6 +25418,29 @@ BoUpSLP::BlockScheduling::tryScheduleBundle(ArrayRef<Value *> VL, BoUpSLP *SLP,
}))
return std::nullopt;
+ // Reject modeling the duplicated source operand of an expanded binop as a
+ // copyable element. shl X, 1 is represented as add X, X, so the parent uses X
+ // on a second operand edge that stays a plain (gathered) operand. At schedule
+ // time that duplicated use is decremented against X's own ScheduleData, which
+ // calculateDependencies attributed to the copyable instead, so X's
+ // unscheduled-deps counter goes negative and trips the assertion. Only the
+ // values this bundle models as copyable that are the expanded binop source
+ // operand are checked, matched by value so the detection is unaffected by the
+ // parent node's operand reordering or reuse shuffle mask.
+ // TODO: investigate modeling such operands correctly.
+ if (S.areInstructionsWithCopyableElements() && EI.UserTE &&
+ EI.UserTE->hasState()) {
+ for (Value *V : VL) {
+ if (!S.isCopyableElement(V))
+ continue;
+ if (any_of(EI.UserTE->Scalars, [&](Value *PV) {
+ auto *I = dyn_cast<Instruction>(PV);
+ return I && EI.UserTE->isExpandedBinOp(I) && I->getOperand(0) == V;
+ }))
+ return std::nullopt;
+ }
+ }
+
// Initialize the instruction bundle.
Instruction *OldScheduleEnd = ScheduleEnd;
LLVM_DEBUG(dbgs() << "SLP: bundle: " << *S.getMainOp() << "\n");
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/expanded-binop-copyable-operand-deps.ll b/llvm/test/Transforms/SLPVectorizer/X86/expanded-binop-copyable-operand-deps.ll
new file mode 100644
index 0000000000000..d37e1ed5986c9
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/X86/expanded-binop-copyable-operand-deps.ll
@@ -0,0 +1,38 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S --passes=slp-vectorizer -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
+
+define void @test() {
+; CHECK-LABEL: define void @test() {
+; CHECK-NEXT: [[ENTRY:.*]]:
+; CHECK-NEXT: br label %[[LBL_BR13:.*]]
+; CHECK: [[LBL_BR13]]:
+; CHECK-NEXT: [[TMP0:%.*]] = phi i16 [ 0, %[[ENTRY]] ], [ [[TMP6:%.*]], %[[LBL_BR13]] ]
+; CHECK-NEXT: [[TMP1:%.*]] = phi i16 [ 0, %[[ENTRY]] ], [ [[TMP4:%.*]], %[[LBL_BR13]] ]
+; CHECK-NEXT: [[TMP2:%.*]] = phi i16 [ 0, %[[ENTRY]] ], [ [[TMP6]], %[[LBL_BR13]] ]
+; CHECK-NEXT: [[TMP3:%.*]] = phi i16 [ 0, %[[ENTRY]] ], [ [[SUB32:%.*]], %[[LBL_BR13]] ]
+; CHECK-NEXT: [[SUB:%.*]] = sub i16 0, 0
+; CHECK-NEXT: store i16 [[SUB]], ptr null, align 2
+; CHECK-NEXT: [[TMP4]] = and i16 [[SUB]], 0
+; CHECK-NEXT: [[TMP5:%.*]] = load i16, ptr null, align 2
+; CHECK-NEXT: [[SUB32]] = add i16 [[TMP5]], 1
+; CHECK-NEXT: [[CONV34:%.*]] = trunc i16 [[SUB32]] to i8
+; CHECK-NEXT: [[TMP6]] = shl i16 [[TMP5]], 1
+; CHECK-NEXT: br label %[[LBL_BR13]]
+;
+entry:
+ br label %lbl_br13
+
+lbl_br13:
+ %0 = phi i16 [ 0, %entry ], [ %6, %lbl_br13 ]
+ %1 = phi i16 [ 0, %entry ], [ %4, %lbl_br13 ]
+ %2 = phi i16 [ 0, %entry ], [ %6, %lbl_br13 ]
+ %3 = phi i16 [ 0, %entry ], [ %sub32, %lbl_br13 ]
+ %sub = sub i16 0, 0
+ store i16 %sub, ptr null, align 2
+ %4 = and i16 %sub, 0
+ %5 = load i16, ptr null, align 2
+ %sub32 = add i16 %5, 1
+ %conv34 = trunc i16 %sub32 to i8
+ %6 = shl i16 %5, 1
+ br label %lbl_br13
+}
More information about the llvm-commits
mailing list