[llvm] [SLP] Let the caller tell canConvertToFMA which operand holds the fmul (PR #218754)
Dmitry Sidorov via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 30 14:16:05 PDT 2026
https://github.com/MrSidims updated https://github.com/llvm/llvm-project/pull/218754
>From 2eac97260692193b4e11071c05240e6feb47eea9 Mon Sep 17 00:00:00 2001
From: Dmitry Sidorov <Dmitry.Sidorov at amd.com>
Date: Sat, 22 Aug 2026 23:01:36 +0200
Subject: [PATCH 1/5] [SLP] Let the caller tell canConvertToFMA which operand
holds the fmul
canConvertToFMA only ever looked at operand 0 of the fadd/fsub, so a
tree whose fmul sits on the right hand side was never recognized as
fusable.
---
.../Transforms/Vectorize/SLPVectorizer.cpp | 39 +++--
.../SLPVectorizer/X86/fma-operand-index.ll | 26 ++--
.../X86/horizontal-fadd-with-sub.ll | 141 +++++++++++-------
3 files changed, 128 insertions(+), 78 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 50d81058968d4..5ffa5884c323a 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -13653,7 +13653,18 @@ static InstructionCost canConvertToFMA(ArrayRef<Value *> VL,
DominatorTree &DT, const DataLayout &DL,
TargetTransformInfo &TTI,
const TargetLibraryInfo &TLI,
- const TTI::TargetCostKind CostKind);
+ const TTI::TargetCostKind CostKind,
+ unsigned FMulOpIdx = 0);
+
+/// \returns the operand of \p I that is a one-use fmul, 0 if there is none.
+static unsigned getFMulOperandIdx(const Instruction *I) {
+ for (unsigned Idx : seq<unsigned>(0, I->getNumOperands())) {
+ auto *Op = dyn_cast<Instruction>(I->getOperand(Idx));
+ if (Op && Op->getOpcode() == Instruction::FMul && Op->hasOneUse())
+ return Idx;
+ }
+ return 0;
+}
uint64_t BoUpSLP::getNumScalarInsts(bool HasTreeLoop) {
uint64_t Total = 0;
@@ -13734,7 +13745,7 @@ uint64_t BoUpSLP::getNumScalarInsts(bool HasTreeLoop) {
I->getOpcode() != Instruction::FSub))
continue;
if (canConvertToFMA(I, InstructionsState(I, I), *DT, *DL, *TTI, *TLI,
- CostKind)
+ CostKind, getFMulOperandIdx(I))
.isValid()) {
assert(Count > 0 && "Underflow in scalar inst count (fma)");
--Count;
@@ -14457,7 +14468,8 @@ static InstructionCost canConvertToFMA(ArrayRef<Value *> VL,
DominatorTree &DT, const DataLayout &DL,
TargetTransformInfo &TTI,
const TargetLibraryInfo &TLI,
- const TTI::TargetCostKind CostKind) {
+ const TTI::TargetCostKind CostKind,
+ unsigned FMulOpIdx) {
assert(all_of(VL,
[](Value *V) {
return V->getType()->getScalarType()->isFloatingPointTy();
@@ -14489,13 +14501,15 @@ static InstructionCost canConvertToFMA(ArrayRef<Value *> VL,
InstructionsCompatibilityAnalysis Analysis(DT, DL, TTI, TLI);
SmallVector<BoUpSLP::ValueList> Operands = Analysis.buildOperands(S, VL);
- InstructionsState OpS = getSameOpcode(Operands.front(), TLI);
+ if (FMulOpIdx >= Operands.size())
+ return InstructionCost::getInvalid();
+ InstructionsState OpS = getSameOpcode(Operands[FMulOpIdx], TLI);
if (!OpS.valid())
return InstructionCost::getInvalid();
if (OpS.isAltShuffle() || OpS.getOpcode() != Instruction::FMul)
return InstructionCost::getInvalid();
- if (!CheckForContractable(Operands.front(), OpS))
+ if (!CheckForContractable(Operands[FMulOpIdx], OpS))
return InstructionCost::getInvalid();
// Compare the costs.
InstructionCost FMulPlusFAddCost = 0;
@@ -14536,7 +14550,7 @@ static InstructionCost canConvertToFMA(ArrayRef<Value *> VL,
{I->getOperand(0), I->getOperand(1)});
}
unsigned NumOps = 0;
- for (auto [V, Op] : zip(VL, Operands.front())) {
+ for (auto [V, Op] : zip(VL, Operands[FMulOpIdx])) {
if (S.isCopyableElement(V))
continue;
auto *I = dyn_cast<Instruction>(Op);
@@ -17068,9 +17082,10 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
return IntrinsicCost;
};
auto GetFMulAddCost = [&, &TTI = *TTI](const InstructionsState &S,
- Instruction *VI) {
+ Instruction *VI,
+ unsigned FMulOpIdx = 0) {
InstructionCost Cost =
- canConvertToFMA(VI, S, *DT, *DL, TTI, *TLI, CostKind);
+ canConvertToFMA(VI, S, *DT, *DL, TTI, *TLI, CostKind, FMulOpIdx);
return Cost;
};
switch (ShuffleOrOp) {
@@ -17708,7 +17723,8 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
if (auto *I = dyn_cast<Instruction>(UniqueValues[Idx]);
I && (ShuffleOrOp == Instruction::FAdd ||
ShuffleOrOp == Instruction::FSub)) {
- InstructionCost IntrinsicCost = GetFMulAddCost(E->getOperations(), I);
+ InstructionCost IntrinsicCost =
+ GetFMulAddCost(E->getOperations(), I, getFMulOperandIdx(I));
if (IntrinsicCost.isValid())
ScalarCost = IntrinsicCost;
}
@@ -33062,7 +33078,7 @@ bool SLPVectorizerPass::tryToVectorize(
(I->getOpcode() == Instruction::FAdd ||
I->getOpcode() == Instruction::FSub) &&
canConvertToFMA(I, getSameOpcode(I, *TLI), *DT, *DL, *TTI, *TLI,
- R.getCostKind())
+ R.getCostKind(), getFMulOperandIdx(I))
.isValid()) {
FMACandidates.insert(I);
return false;
@@ -34338,7 +34354,8 @@ bool SLPVectorizerPass::vectorizeOnceUsedSeeds(BasicBlock *BB, BoUpSLP &R) {
auto *U = cast<Instruction>(I.user_back());
if (InstructionsState S = getSameOpcode(U, *TLI);
S && S.isAddSubLikeOp() &&
- canConvertToFMA(U, S, *DT, *DL, *TTI, *TLI, R.getCostKind())
+ canConvertToFMA(U, S, *DT, *DL, *TTI, *TLI, R.getCostKind(),
+ U->getOperand(1) == &I ? 1 : 0)
.isValid())
continue;
}
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/fma-operand-index.ll b/llvm/test/Transforms/SLPVectorizer/X86/fma-operand-index.ll
index abf8abf106eee..a5b28dd341e7a 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/fma-operand-index.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/fma-operand-index.ll
@@ -10,16 +10,19 @@ define double @fmul_rhs_fadd(ptr %x, ptr %y, ptr %z) {
; CHECK-LABEL: define double @fmul_rhs_fadd(
; CHECK-SAME: ptr [[X:%.*]], ptr [[Y:%.*]], ptr [[Z:%.*]]) #[[ATTR0:[0-9]+]] {
; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[X8:%.*]] = getelementptr inbounds nuw i8, ptr [[X]], i64 8
+; CHECK-NEXT: [[Y8:%.*]] = getelementptr inbounds nuw i8, ptr [[Y]], i64 8
; CHECK-NEXT: [[Z8:%.*]] = getelementptr inbounds nuw i8, ptr [[Z]], i64 8
+; CHECK-NEXT: [[X0:%.*]] = load double, ptr [[X]], align 8
+; CHECK-NEXT: [[Y0:%.*]] = load double, ptr [[Y]], align 8
+; CHECK-NEXT: [[MUL0:%.*]] = fmul reassoc nsz contract double [[Y0]], [[X0]]
; CHECK-NEXT: [[Z0:%.*]] = load double, ptr [[Z]], align 8
-; CHECK-NEXT: [[TMP0:%.*]] = load <2 x double>, ptr [[X]], align 8
-; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, ptr [[Y]], align 8
-; CHECK-NEXT: [[TMP2:%.*]] = fmul reassoc nsz contract <2 x double> [[TMP1]], [[TMP0]]
+; CHECK-NEXT: [[X1:%.*]] = load double, ptr [[X8]], align 8
+; CHECK-NEXT: [[Y1:%.*]] = load double, ptr [[Y8]], align 8
+; CHECK-NEXT: [[MUL1:%.*]] = fmul reassoc nsz contract double [[Y1]], [[X1]]
; CHECK-NEXT: [[Z1:%.*]] = load double, ptr [[Z8]], align 8
; CHECK-NEXT: [[ZSUM:%.*]] = fadd reassoc nsz contract double [[Z0]], [[Z1]]
-; CHECK-NEXT: [[MUL0:%.*]] = extractelement <2 x double> [[TMP2]], i64 0
; CHECK-NEXT: [[ADD0:%.*]] = fadd reassoc nsz contract double [[ZSUM]], [[MUL0]]
-; CHECK-NEXT: [[MUL1:%.*]] = extractelement <2 x double> [[TMP2]], i64 1
; CHECK-NEXT: [[ADD1:%.*]] = fadd reassoc nsz contract double [[ADD0]], [[MUL1]]
; CHECK-NEXT: ret double [[ADD1]]
;
@@ -46,16 +49,19 @@ define double @fmul_rhs_fsub(ptr %x, ptr %y, ptr %z) {
; CHECK-LABEL: define double @fmul_rhs_fsub(
; CHECK-SAME: ptr [[X:%.*]], ptr [[Y:%.*]], ptr [[Z:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[X8:%.*]] = getelementptr inbounds nuw i8, ptr [[X]], i64 8
+; CHECK-NEXT: [[Y8:%.*]] = getelementptr inbounds nuw i8, ptr [[Y]], i64 8
; CHECK-NEXT: [[Z8:%.*]] = getelementptr inbounds nuw i8, ptr [[Z]], i64 8
+; CHECK-NEXT: [[X0:%.*]] = load double, ptr [[X]], align 8
+; CHECK-NEXT: [[Y0:%.*]] = load double, ptr [[Y]], align 8
+; CHECK-NEXT: [[MUL0:%.*]] = fmul reassoc nsz contract double [[Y0]], [[X0]]
; CHECK-NEXT: [[Z0:%.*]] = load double, ptr [[Z]], align 8
-; CHECK-NEXT: [[TMP0:%.*]] = load <2 x double>, ptr [[X]], align 8
-; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, ptr [[Y]], align 8
-; CHECK-NEXT: [[TMP2:%.*]] = fmul reassoc nsz contract <2 x double> [[TMP1]], [[TMP0]]
+; CHECK-NEXT: [[X1:%.*]] = load double, ptr [[X8]], align 8
+; CHECK-NEXT: [[Y1:%.*]] = load double, ptr [[Y8]], align 8
+; CHECK-NEXT: [[MUL1:%.*]] = fmul reassoc nsz contract double [[Y1]], [[X1]]
; CHECK-NEXT: [[Z1:%.*]] = load double, ptr [[Z8]], align 8
; CHECK-NEXT: [[ZSUM:%.*]] = fadd reassoc nsz contract double [[Z0]], [[Z1]]
-; CHECK-NEXT: [[MUL0:%.*]] = extractelement <2 x double> [[TMP2]], i64 0
; CHECK-NEXT: [[SUB0:%.*]] = fsub reassoc nsz contract double [[ZSUM]], [[MUL0]]
-; CHECK-NEXT: [[MUL1:%.*]] = extractelement <2 x double> [[TMP2]], i64 1
; CHECK-NEXT: [[SUB1:%.*]] = fsub reassoc nsz contract double [[SUB0]], [[MUL1]]
; CHECK-NEXT: ret double [[SUB1]]
;
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/horizontal-fadd-with-sub.ll b/llvm/test/Transforms/SLPVectorizer/X86/horizontal-fadd-with-sub.ll
index f96ab87e86049..853ab156bed97 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/horizontal-fadd-with-sub.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/horizontal-fadd-with-sub.ll
@@ -9,16 +9,19 @@ define double @fsub_fmul_2(ptr %x, ptr %y, ptr %z) {
; CHECK-LABEL: define double @fsub_fmul_2(
; CHECK-SAME: ptr [[X:%.*]], ptr [[Y:%.*]], ptr [[Z:%.*]]) #[[ATTR0:[0-9]+]] {
; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[X8:%.*]] = getelementptr inbounds nuw i8, ptr [[X]], i64 8
+; CHECK-NEXT: [[Y8:%.*]] = getelementptr inbounds nuw i8, ptr [[Y]], i64 8
; CHECK-NEXT: [[Z8:%.*]] = getelementptr inbounds nuw i8, ptr [[Z]], i64 8
+; CHECK-NEXT: [[X0:%.*]] = load double, ptr [[X]], align 8
+; CHECK-NEXT: [[Y0:%.*]] = load double, ptr [[Y]], align 8
+; CHECK-NEXT: [[TMP5:%.*]] = fmul reassoc nsz contract double [[Y0]], [[X0]]
; CHECK-NEXT: [[Z0:%.*]] = load double, ptr [[Z]], align 8
-; CHECK-NEXT: [[TMP2:%.*]] = load <2 x double>, ptr [[X]], align 8
-; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, ptr [[Y]], align 8
-; CHECK-NEXT: [[TMP3:%.*]] = fmul reassoc nsz contract <2 x double> [[TMP1]], [[TMP2]]
+; CHECK-NEXT: [[X1:%.*]] = load double, ptr [[X8]], align 8
+; CHECK-NEXT: [[Y1:%.*]] = load double, ptr [[Y8]], align 8
+; CHECK-NEXT: [[TMP4:%.*]] = fmul reassoc nsz contract double [[Y1]], [[X1]]
; CHECK-NEXT: [[Z1:%.*]] = load double, ptr [[Z8]], align 8
; CHECK-NEXT: [[ZSUM:%.*]] = fadd reassoc nsz contract double [[Z0]], [[Z1]]
-; CHECK-NEXT: [[TMP5:%.*]] = extractelement <2 x double> [[TMP3]], i64 0
; CHECK-NEXT: [[SUB:%.*]] = fsub reassoc nsz contract double [[TMP5]], [[ZSUM]]
-; CHECK-NEXT: [[TMP4:%.*]] = extractelement <2 x double> [[TMP3]], i64 1
; CHECK-NEXT: [[TMP6:%.*]] = fadd reassoc nsz contract double [[SUB]], [[TMP4]]
; CHECK-NEXT: ret double [[TMP6]]
;
@@ -46,25 +49,28 @@ define double @fsub_fmul_4(ptr %x, ptr %y, ptr %z) {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: [[X8:%.*]] = getelementptr inbounds nuw i8, ptr [[X]], i64 8
; CHECK-NEXT: [[Y8:%.*]] = getelementptr inbounds nuw i8, ptr [[Y]], i64 8
+; CHECK-NEXT: [[X16:%.*]] = getelementptr inbounds nuw i8, ptr [[X]], i64 16
+; CHECK-NEXT: [[Y16:%.*]] = getelementptr inbounds nuw i8, ptr [[Y]], i64 16
; CHECK-NEXT: [[X24:%.*]] = getelementptr inbounds nuw i8, ptr [[X]], i64 24
; CHECK-NEXT: [[Y24:%.*]] = getelementptr inbounds nuw i8, ptr [[Y]], i64 24
; CHECK-NEXT: [[X0:%.*]] = load double, ptr [[X]], align 8
; CHECK-NEXT: [[Y0:%.*]] = load double, ptr [[Y]], align 8
; CHECK-NEXT: [[MUL:%.*]] = fmul reassoc nsz contract double [[Y0]], [[X0]]
-; CHECK-NEXT: [[TMP0:%.*]] = load <2 x double>, ptr [[X8]], align 8
-; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, ptr [[Y8]], align 8
-; CHECK-NEXT: [[TMP2:%.*]] = fmul reassoc nsz contract <2 x double> [[TMP1]], [[TMP0]]
-; CHECK-NEXT: [[X3:%.*]] = load double, ptr [[X24]], align 8
-; CHECK-NEXT: [[Y3:%.*]] = load double, ptr [[Y24]], align 8
+; CHECK-NEXT: [[X3:%.*]] = load double, ptr [[X8]], align 8
+; CHECK-NEXT: [[Y3:%.*]] = load double, ptr [[Y8]], align 8
; CHECK-NEXT: [[MUL16:%.*]] = fmul reassoc nsz contract double [[Y3]], [[X3]]
+; CHECK-NEXT: [[X2:%.*]] = load double, ptr [[X16]], align 8
+; CHECK-NEXT: [[Y2:%.*]] = load double, ptr [[Y16]], align 8
+; CHECK-NEXT: [[TMP7:%.*]] = fmul reassoc nsz contract double [[Y2]], [[X2]]
+; CHECK-NEXT: [[X4:%.*]] = load double, ptr [[X24]], align 8
+; CHECK-NEXT: [[Y4:%.*]] = load double, ptr [[Y24]], align 8
+; CHECK-NEXT: [[MUL17:%.*]] = fmul reassoc nsz contract double [[Y4]], [[X4]]
; CHECK-NEXT: [[TMP3:%.*]] = load <4 x double>, ptr [[Z]], align 8
-; CHECK-NEXT: [[TMP4:%.*]] = extractelement <2 x double> [[TMP2]], i64 0
-; CHECK-NEXT: [[T1:%.*]] = fadd reassoc nsz contract double [[MUL]], [[TMP4]]
-; CHECK-NEXT: [[TMP7:%.*]] = extractelement <2 x double> [[TMP2]], i64 1
+; CHECK-NEXT: [[T1:%.*]] = fadd reassoc nsz contract double [[MUL]], [[MUL16]]
; CHECK-NEXT: [[T3:%.*]] = fadd reassoc nsz contract double [[T1]], [[TMP7]]
; CHECK-NEXT: [[TMP6:%.*]] = call reassoc nsz contract double @llvm.vector.reduce.fadd.v4f64(double 0.000000e+00, <4 x double> [[TMP3]])
; CHECK-NEXT: [[ADD13:%.*]] = fsub reassoc nsz contract double [[T3]], [[TMP6]]
-; CHECK-NEXT: [[TMP5:%.*]] = fadd reassoc nsz contract double [[ADD13]], [[MUL16]]
+; CHECK-NEXT: [[TMP5:%.*]] = fadd reassoc nsz contract double [[ADD13]], [[MUL17]]
; CHECK-NEXT: ret double [[TMP5]]
;
entry:
@@ -390,30 +396,36 @@ define double @fsub_fmul_subtrahend_4(ptr %x, ptr %y, ptr %z) {
; CHECK-LABEL: define double @fsub_fmul_subtrahend_4(
; CHECK-SAME: ptr [[X:%.*]], ptr [[Y:%.*]], ptr [[Z:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[X8:%.*]] = getelementptr inbounds nuw i8, ptr [[X]], i64 8
+; CHECK-NEXT: [[Y8:%.*]] = getelementptr inbounds nuw i8, ptr [[Y]], i64 8
; CHECK-NEXT: [[Z8:%.*]] = getelementptr inbounds nuw i8, ptr [[Z]], i64 8
; CHECK-NEXT: [[X16:%.*]] = getelementptr inbounds nuw i8, ptr [[X]], i64 16
; CHECK-NEXT: [[Y16:%.*]] = getelementptr inbounds nuw i8, ptr [[Y]], i64 16
; CHECK-NEXT: [[Z16:%.*]] = getelementptr inbounds nuw i8, ptr [[Z]], i64 16
+; CHECK-NEXT: [[X24:%.*]] = getelementptr inbounds nuw i8, ptr [[X]], i64 24
+; CHECK-NEXT: [[Y24:%.*]] = getelementptr inbounds nuw i8, ptr [[Y]], i64 24
; CHECK-NEXT: [[Z24:%.*]] = getelementptr inbounds nuw i8, ptr [[Z]], i64 24
+; CHECK-NEXT: [[X0:%.*]] = load double, ptr [[X]], align 8
+; CHECK-NEXT: [[Y0:%.*]] = load double, ptr [[Y]], align 8
+; CHECK-NEXT: [[TMP6:%.*]] = fmul reassoc nsz contract double [[Y0]], [[X0]]
; CHECK-NEXT: [[Z0:%.*]] = load double, ptr [[Z]], align 8
-; CHECK-NEXT: [[TMP0:%.*]] = load <2 x double>, ptr [[X]], align 8
-; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, ptr [[Y]], align 8
-; CHECK-NEXT: [[TMP2:%.*]] = fmul reassoc nsz contract <2 x double> [[TMP1]], [[TMP0]]
+; CHECK-NEXT: [[X1:%.*]] = load double, ptr [[X8]], align 8
+; CHECK-NEXT: [[Y1:%.*]] = load double, ptr [[Y8]], align 8
+; CHECK-NEXT: [[TMP7:%.*]] = fmul reassoc nsz contract double [[Y1]], [[X1]]
; CHECK-NEXT: [[Z1:%.*]] = load double, ptr [[Z8]], align 8
+; CHECK-NEXT: [[X2:%.*]] = load double, ptr [[X16]], align 8
+; CHECK-NEXT: [[Y2:%.*]] = load double, ptr [[Y16]], align 8
+; CHECK-NEXT: [[TMP8:%.*]] = fmul reassoc nsz contract double [[Y2]], [[X2]]
; CHECK-NEXT: [[Z2:%.*]] = load double, ptr [[Z16]], align 8
-; CHECK-NEXT: [[TMP3:%.*]] = load <2 x double>, ptr [[X16]], align 8
-; CHECK-NEXT: [[TMP4:%.*]] = load <2 x double>, ptr [[Y16]], align 8
-; CHECK-NEXT: [[TMP5:%.*]] = fmul reassoc nsz contract <2 x double> [[TMP4]], [[TMP3]]
+; CHECK-NEXT: [[X3:%.*]] = load double, ptr [[X24]], align 8
+; CHECK-NEXT: [[Y3:%.*]] = load double, ptr [[Y24]], align 8
+; CHECK-NEXT: [[TMP9:%.*]] = fmul reassoc nsz contract double [[Y3]], [[X3]]
; CHECK-NEXT: [[Z3:%.*]] = load double, ptr [[Z24]], align 8
-; CHECK-NEXT: [[TMP6:%.*]] = extractelement <2 x double> [[TMP2]], i64 0
; CHECK-NEXT: [[S0:%.*]] = fsub reassoc nsz contract double [[Z0]], [[TMP6]]
; CHECK-NEXT: [[A1:%.*]] = fadd reassoc nsz contract double [[S0]], [[Z1]]
-; CHECK-NEXT: [[TMP7:%.*]] = extractelement <2 x double> [[TMP2]], i64 1
; CHECK-NEXT: [[S1:%.*]] = fsub reassoc nsz contract double [[A1]], [[TMP7]]
; CHECK-NEXT: [[A2:%.*]] = fadd reassoc nsz contract double [[S1]], [[Z2]]
-; CHECK-NEXT: [[TMP8:%.*]] = extractelement <2 x double> [[TMP5]], i64 0
; CHECK-NEXT: [[S2:%.*]] = fsub reassoc nsz contract double [[A2]], [[TMP8]]
-; CHECK-NEXT: [[TMP9:%.*]] = extractelement <2 x double> [[TMP5]], i64 1
; CHECK-NEXT: [[S3:%.*]] = fsub reassoc nsz contract double [[S2]], [[TMP9]]
; CHECK-NEXT: [[R:%.*]] = fadd reassoc nsz contract double [[S3]], [[Z3]]
; CHECK-NEXT: ret double [[R]]
@@ -499,50 +511,59 @@ define double @three_sign_groups(ptr %x, ptr %y, ptr %u, ptr %v, ptr %z) {
; CHECK-SAME: ptr [[X:%.*]], ptr [[Y:%.*]], ptr [[U:%.*]], ptr [[V:%.*]], ptr [[Z:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: [[X8:%.*]] = getelementptr inbounds nuw i8, ptr [[X]], i64 8
+; CHECK-NEXT: [[X16:%.*]] = getelementptr inbounds nuw i8, ptr [[X]], i64 16
; CHECK-NEXT: [[X24:%.*]] = getelementptr inbounds nuw i8, ptr [[X]], i64 24
; CHECK-NEXT: [[Y8:%.*]] = getelementptr inbounds nuw i8, ptr [[Y]], i64 8
+; CHECK-NEXT: [[Y16:%.*]] = getelementptr inbounds nuw i8, ptr [[Y]], i64 16
; CHECK-NEXT: [[Y24:%.*]] = getelementptr inbounds nuw i8, ptr [[Y]], i64 24
+; CHECK-NEXT: [[U8:%.*]] = getelementptr inbounds nuw i8, ptr [[U]], i64 8
; CHECK-NEXT: [[U16:%.*]] = getelementptr inbounds nuw i8, ptr [[U]], i64 16
+; CHECK-NEXT: [[U24:%.*]] = getelementptr inbounds nuw i8, ptr [[U]], i64 24
+; CHECK-NEXT: [[V8:%.*]] = getelementptr inbounds nuw i8, ptr [[V]], i64 8
; CHECK-NEXT: [[V16:%.*]] = getelementptr inbounds nuw i8, ptr [[V]], i64 16
+; CHECK-NEXT: [[V24:%.*]] = getelementptr inbounds nuw i8, ptr [[V]], i64 24
; CHECK-NEXT: [[Z8:%.*]] = getelementptr inbounds nuw i8, ptr [[Z]], i64 8
; CHECK-NEXT: [[Z16:%.*]] = getelementptr inbounds nuw i8, ptr [[Z]], i64 16
; CHECK-NEXT: [[Z24:%.*]] = getelementptr inbounds nuw i8, ptr [[Z]], i64 24
; CHECK-NEXT: [[X0:%.*]] = load double, ptr [[X]], align 8
-; CHECK-NEXT: [[X3:%.*]] = load double, ptr [[X24]], align 8
+; CHECK-NEXT: [[X3:%.*]] = load double, ptr [[X8]], align 8
+; CHECK-NEXT: [[X2:%.*]] = load double, ptr [[X16]], align 8
+; CHECK-NEXT: [[X4:%.*]] = load double, ptr [[X24]], align 8
; CHECK-NEXT: [[Y0:%.*]] = load double, ptr [[Y]], align 8
-; CHECK-NEXT: [[Y3:%.*]] = load double, ptr [[Y24]], align 8
+; CHECK-NEXT: [[Y3:%.*]] = load double, ptr [[Y8]], align 8
+; CHECK-NEXT: [[Y2:%.*]] = load double, ptr [[Y16]], align 8
+; CHECK-NEXT: [[Y4:%.*]] = load double, ptr [[Y24]], align 8
+; CHECK-NEXT: [[U0:%.*]] = load double, ptr [[U]], align 8
+; CHECK-NEXT: [[U1:%.*]] = load double, ptr [[U8]], align 8
+; CHECK-NEXT: [[U2:%.*]] = load double, ptr [[U16]], align 8
+; CHECK-NEXT: [[U3:%.*]] = load double, ptr [[U24]], align 8
+; CHECK-NEXT: [[V0:%.*]] = load double, ptr [[V]], align 8
+; CHECK-NEXT: [[V1:%.*]] = load double, ptr [[V8]], align 8
+; CHECK-NEXT: [[V2:%.*]] = load double, ptr [[V16]], align 8
+; CHECK-NEXT: [[V3:%.*]] = load double, ptr [[V24]], align 8
; CHECK-NEXT: [[Z0:%.*]] = load double, ptr [[Z]], align 8
; CHECK-NEXT: [[Z1:%.*]] = load double, ptr [[Z8]], align 8
; CHECK-NEXT: [[Z2:%.*]] = load double, ptr [[Z16]], align 8
; CHECK-NEXT: [[Z3:%.*]] = load double, ptr [[Z24]], align 8
; CHECK-NEXT: [[MXY0:%.*]] = fmul reassoc nsz contract double [[X0]], [[Y0]]
-; CHECK-NEXT: [[TMP0:%.*]] = load <2 x double>, ptr [[X8]], align 8
-; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, ptr [[Y8]], align 8
-; CHECK-NEXT: [[TMP2:%.*]] = fmul reassoc nsz contract <2 x double> [[TMP0]], [[TMP1]]
; CHECK-NEXT: [[MXY3:%.*]] = fmul reassoc nsz contract double [[X3]], [[Y3]]
-; CHECK-NEXT: [[TMP3:%.*]] = load <2 x double>, ptr [[U]], align 8
-; CHECK-NEXT: [[TMP4:%.*]] = load <2 x double>, ptr [[V]], align 8
-; CHECK-NEXT: [[TMP5:%.*]] = fmul reassoc nsz contract <2 x double> [[TMP3]], [[TMP4]]
-; CHECK-NEXT: [[TMP6:%.*]] = load <2 x double>, ptr [[U16]], align 8
-; CHECK-NEXT: [[TMP7:%.*]] = load <2 x double>, ptr [[V16]], align 8
-; CHECK-NEXT: [[TMP8:%.*]] = fmul reassoc nsz contract <2 x double> [[TMP6]], [[TMP7]]
-; CHECK-NEXT: [[TMP9:%.*]] = extractelement <2 x double> [[TMP2]], i64 0
-; CHECK-NEXT: [[T0:%.*]] = fadd reassoc nsz contract double [[MXY0]], [[TMP9]]
-; CHECK-NEXT: [[TMP10:%.*]] = extractelement <2 x double> [[TMP2]], i64 1
+; CHECK-NEXT: [[TMP10:%.*]] = fmul reassoc nsz contract double [[X2]], [[Y2]]
+; CHECK-NEXT: [[MXY4:%.*]] = fmul reassoc nsz contract double [[X4]], [[Y4]]
+; CHECK-NEXT: [[TMP11:%.*]] = fmul reassoc nsz contract double [[U0]], [[V0]]
+; CHECK-NEXT: [[TMP12:%.*]] = fmul reassoc nsz contract double [[U1]], [[V1]]
+; CHECK-NEXT: [[TMP13:%.*]] = fmul reassoc nsz contract double [[U2]], [[V2]]
+; CHECK-NEXT: [[TMP14:%.*]] = fmul reassoc nsz contract double [[U3]], [[V3]]
+; CHECK-NEXT: [[T0:%.*]] = fadd reassoc nsz contract double [[MXY0]], [[MXY3]]
; CHECK-NEXT: [[T1:%.*]] = fadd reassoc nsz contract double [[T0]], [[TMP10]]
-; CHECK-NEXT: [[TMP11:%.*]] = extractelement <2 x double> [[TMP5]], i64 0
; CHECK-NEXT: [[S0:%.*]] = fsub reassoc nsz contract double [[T1]], [[TMP11]]
-; CHECK-NEXT: [[TMP12:%.*]] = extractelement <2 x double> [[TMP5]], i64 1
; CHECK-NEXT: [[S1:%.*]] = fsub reassoc nsz contract double [[S0]], [[TMP12]]
-; CHECK-NEXT: [[TMP13:%.*]] = extractelement <2 x double> [[TMP8]], i64 0
; CHECK-NEXT: [[S2:%.*]] = fsub reassoc nsz contract double [[S1]], [[TMP13]]
-; CHECK-NEXT: [[TMP14:%.*]] = extractelement <2 x double> [[TMP8]], i64 1
; CHECK-NEXT: [[S3:%.*]] = fsub reassoc nsz contract double [[S2]], [[TMP14]]
; CHECK-NEXT: [[W0:%.*]] = fsub reassoc nsz contract double [[S3]], [[Z0]]
; CHECK-NEXT: [[W1:%.*]] = fsub reassoc nsz contract double [[W0]], [[Z1]]
; CHECK-NEXT: [[W2:%.*]] = fsub reassoc nsz contract double [[W1]], [[Z2]]
; CHECK-NEXT: [[W3:%.*]] = fsub reassoc nsz contract double [[W2]], [[Z3]]
-; CHECK-NEXT: [[R:%.*]] = fadd reassoc nsz contract double [[W3]], [[MXY3]]
+; CHECK-NEXT: [[R:%.*]] = fadd reassoc nsz contract double [[W3]], [[MXY4]]
; CHECK-NEXT: ret double [[R]]
;
entry:
@@ -611,30 +632,33 @@ define double @negated_repeated_pair(ptr %x, ptr %y, ptr %z) {
; CHECK-SAME: ptr [[X:%.*]], ptr [[Y:%.*]], ptr [[Z:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: [[X8:%.*]] = getelementptr inbounds nuw i8, ptr [[X]], i64 8
+; CHECK-NEXT: [[X16:%.*]] = getelementptr inbounds nuw i8, ptr [[X]], i64 16
; CHECK-NEXT: [[X24:%.*]] = getelementptr inbounds nuw i8, ptr [[X]], i64 24
; CHECK-NEXT: [[Y8:%.*]] = getelementptr inbounds nuw i8, ptr [[Y]], i64 8
+; CHECK-NEXT: [[Y16:%.*]] = getelementptr inbounds nuw i8, ptr [[Y]], i64 16
; CHECK-NEXT: [[Y24:%.*]] = getelementptr inbounds nuw i8, ptr [[Y]], i64 24
; CHECK-NEXT: [[Z8:%.*]] = getelementptr inbounds nuw i8, ptr [[Z]], i64 8
; CHECK-NEXT: [[X0:%.*]] = load double, ptr [[X]], align 8
-; CHECK-NEXT: [[X3:%.*]] = load double, ptr [[X24]], align 8
+; CHECK-NEXT: [[X3:%.*]] = load double, ptr [[X8]], align 8
+; CHECK-NEXT: [[X2:%.*]] = load double, ptr [[X16]], align 8
+; CHECK-NEXT: [[X4:%.*]] = load double, ptr [[X24]], align 8
; CHECK-NEXT: [[Y0:%.*]] = load double, ptr [[Y]], align 8
-; CHECK-NEXT: [[Y3:%.*]] = load double, ptr [[Y24]], align 8
+; CHECK-NEXT: [[Y3:%.*]] = load double, ptr [[Y8]], align 8
+; CHECK-NEXT: [[Y2:%.*]] = load double, ptr [[Y16]], align 8
+; CHECK-NEXT: [[Y4:%.*]] = load double, ptr [[Y24]], align 8
; CHECK-NEXT: [[ZA:%.*]] = load double, ptr [[Z]], align 8
; CHECK-NEXT: [[ZB:%.*]] = load double, ptr [[Z8]], align 8
; CHECK-NEXT: [[M0:%.*]] = fmul reassoc nsz contract double [[X0]], [[Y0]]
-; CHECK-NEXT: [[TMP0:%.*]] = load <2 x double>, ptr [[X8]], align 8
-; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, ptr [[Y8]], align 8
-; CHECK-NEXT: [[TMP2:%.*]] = fmul reassoc nsz contract <2 x double> [[TMP0]], [[TMP1]]
; CHECK-NEXT: [[M3:%.*]] = fmul reassoc nsz contract double [[X3]], [[Y3]]
-; CHECK-NEXT: [[TMP3:%.*]] = extractelement <2 x double> [[TMP2]], i64 0
-; CHECK-NEXT: [[T0:%.*]] = fadd reassoc nsz contract double [[M0]], [[TMP3]]
-; CHECK-NEXT: [[TMP4:%.*]] = extractelement <2 x double> [[TMP2]], i64 1
+; CHECK-NEXT: [[TMP4:%.*]] = fmul reassoc nsz contract double [[X2]], [[Y2]]
+; CHECK-NEXT: [[M4:%.*]] = fmul reassoc nsz contract double [[X4]], [[Y4]]
+; CHECK-NEXT: [[T0:%.*]] = fadd reassoc nsz contract double [[M0]], [[M3]]
; CHECK-NEXT: [[T1:%.*]] = fadd reassoc nsz contract double [[T0]], [[TMP4]]
; CHECK-NEXT: [[S0:%.*]] = fsub reassoc nsz contract double [[T1]], [[ZA]]
; CHECK-NEXT: [[S1:%.*]] = fsub reassoc nsz contract double [[S0]], [[ZB]]
; CHECK-NEXT: [[S2:%.*]] = fsub reassoc nsz contract double [[S1]], [[ZA]]
; CHECK-NEXT: [[S3:%.*]] = fsub reassoc nsz contract double [[S2]], [[ZB]]
-; CHECK-NEXT: [[R:%.*]] = fadd reassoc nsz contract double [[S3]], [[M3]]
+; CHECK-NEXT: [[R:%.*]] = fadd reassoc nsz contract double [[S3]], [[M4]]
; CHECK-NEXT: ret double [[R]]
;
entry:
@@ -707,17 +731,20 @@ define double @ordered_switch_restart(ptr %x, ptr %y, ptr %z, ptr %out) {
; CHECK-LABEL: define double @ordered_switch_restart(
; CHECK-SAME: ptr [[X:%.*]], ptr [[Y:%.*]], ptr [[Z:%.*]], ptr [[OUT:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[X8:%.*]] = getelementptr inbounds nuw i8, ptr [[X]], i64 8
+; CHECK-NEXT: [[Y8:%.*]] = getelementptr inbounds nuw i8, ptr [[Y]], i64 8
; CHECK-NEXT: [[Z8:%.*]] = getelementptr inbounds nuw i8, ptr [[Z]], i64 8
+; CHECK-NEXT: [[X0:%.*]] = load double, ptr [[X]], align 8
+; CHECK-NEXT: [[Y0:%.*]] = load double, ptr [[Y]], align 8
+; CHECK-NEXT: [[TMP3:%.*]] = fmul reassoc nsz contract double [[Y0]], [[X0]]
; CHECK-NEXT: [[Z0:%.*]] = load double, ptr [[Z]], align 8
-; CHECK-NEXT: [[TMP0:%.*]] = load <2 x double>, ptr [[X]], align 8
-; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, ptr [[Y]], align 8
-; CHECK-NEXT: [[TMP2:%.*]] = fmul reassoc nsz contract <2 x double> [[TMP1]], [[TMP0]]
+; CHECK-NEXT: [[X1:%.*]] = load double, ptr [[X8]], align 8
+; CHECK-NEXT: [[Y1:%.*]] = load double, ptr [[Y8]], align 8
+; CHECK-NEXT: [[TMP4:%.*]] = fmul reassoc nsz contract double [[Y1]], [[X1]]
; CHECK-NEXT: [[Z1:%.*]] = load double, ptr [[Z8]], align 8
; CHECK-NEXT: [[ZSUM:%.*]] = fadd reassoc nsz contract double [[Z0]], [[Z1]]
; CHECK-NEXT: store double [[ZSUM]], ptr [[OUT]], align 8
-; CHECK-NEXT: [[TMP3:%.*]] = extractelement <2 x double> [[TMP2]], i64 0
; CHECK-NEXT: [[SUB:%.*]] = fsub reassoc nsz contract double [[TMP3]], [[ZSUM]]
-; CHECK-NEXT: [[TMP4:%.*]] = extractelement <2 x double> [[TMP2]], i64 1
; CHECK-NEXT: [[ADD:%.*]] = fadd reassoc nsz contract double [[SUB]], [[TMP4]]
; CHECK-NEXT: ret double [[ADD]]
;
>From 8bd4e20ff0a3a3a5651e29abc65517d7d4741973 Mon Sep 17 00:00:00 2001
From: Dmitry Sidorov <Dmitry.Sidorov at amd.com>
Date: Tue, 25 Aug 2026 21:43:33 +0200
Subject: [PATCH 2/5] format
---
.../Transforms/Vectorize/SLPVectorizer.cpp | 24 ++++++++-----------
1 file changed, 10 insertions(+), 14 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 5ffa5884c323a..0a66731d45862 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -13648,13 +13648,11 @@ bool BoUpSLP::areAllUsersVectorized(
});
}
-static InstructionCost canConvertToFMA(ArrayRef<Value *> VL,
- const InstructionsState &S,
- DominatorTree &DT, const DataLayout &DL,
- TargetTransformInfo &TTI,
- const TargetLibraryInfo &TLI,
- const TTI::TargetCostKind CostKind,
- unsigned FMulOpIdx = 0);
+static InstructionCost
+canConvertToFMA(ArrayRef<Value *> VL, const InstructionsState &S,
+ DominatorTree &DT, const DataLayout &DL,
+ TargetTransformInfo &TTI, const TargetLibraryInfo &TLI,
+ const TTI::TargetCostKind CostKind, unsigned FMulOpIdx = 0);
/// \returns the operand of \p I that is a one-use fmul, 0 if there is none.
static unsigned getFMulOperandIdx(const Instruction *I) {
@@ -14463,13 +14461,11 @@ void BoUpSLP::reorderGatherNode(TreeEntry &TE) {
/// Check if we can convert fadd/fsub sequence to FMAD.
/// \returns Cost of the FMAD, if conversion is possible, invalid cost otherwise.
-static InstructionCost canConvertToFMA(ArrayRef<Value *> VL,
- const InstructionsState &S,
- DominatorTree &DT, const DataLayout &DL,
- TargetTransformInfo &TTI,
- const TargetLibraryInfo &TLI,
- const TTI::TargetCostKind CostKind,
- unsigned FMulOpIdx) {
+static InstructionCost
+canConvertToFMA(ArrayRef<Value *> VL, const InstructionsState &S,
+ DominatorTree &DT, const DataLayout &DL,
+ TargetTransformInfo &TTI, const TargetLibraryInfo &TLI,
+ const TTI::TargetCostKind CostKind, unsigned FMulOpIdx) {
assert(all_of(VL,
[](Value *V) {
return V->getType()->getScalarType()->isFloatingPointTy();
>From 2b708b28959cfb7ff9a2cb43e38ba77846654631 Mon Sep 17 00:00:00 2001
From: Dmitry Sidorov <Dmitry.Sidorov at amd.com>
Date: Sat, 29 Aug 2026 23:01:17 +0200
Subject: [PATCH 3/5] partially address comments
---
.../Transforms/Vectorize/SLPVectorizer.cpp | 25 ++++++-------------
.../Vectorize/SLPVectorizer/SLPUtils.cpp | 12 +++++++++
.../Vectorize/SLPVectorizer/SLPUtils.h | 4 +++
3 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 3478f5064b416..1779611454340 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -13756,17 +13756,7 @@ static InstructionCost
canConvertToFMA(ArrayRef<Value *> VL, const InstructionsState &S,
DominatorTree &DT, const DataLayout &DL,
TargetTransformInfo &TTI, const TargetLibraryInfo &TLI,
- const TTI::TargetCostKind CostKind, unsigned FMulOpIdx = 0);
-
-/// \returns the operand of \p I that is a one-use fmul, 0 if there is none.
-static unsigned getFMulOperandIdx(const Instruction *I) {
- for (unsigned Idx : seq<unsigned>(0, I->getNumOperands())) {
- auto *Op = dyn_cast<Instruction>(I->getOperand(Idx));
- if (Op && Op->getOpcode() == Instruction::FMul && Op->hasOneUse())
- return Idx;
- }
- return 0;
-}
+ const TTI::TargetCostKind CostKind, unsigned FMulOpIdx);
uint64_t BoUpSLP::getNumScalarInsts(bool HasTreeLoop) {
uint64_t Total = 0;
@@ -15461,7 +15451,7 @@ void BoUpSLP::transformNodes() {
!IsOneUseVectorFMulOperand(RHS)))
break;
if (!canConvertToFMA(E.Scalars, E.getOperations(), *DT, *DL, *TTI, *TLI,
- CostKind)
+ CostKind, /*FMulOpIdx=*/0)
.isValid())
break;
// This node is a fmuladd node.
@@ -17182,8 +17172,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
return IntrinsicCost;
};
auto GetFMulAddCost = [&, &TTI = *TTI](const InstructionsState &S,
- Instruction *VI,
- unsigned FMulOpIdx = 0) {
+ Instruction *VI, unsigned FMulOpIdx) {
InstructionCost Cost =
canConvertToFMA(VI, S, *DT, *DL, TTI, *TLI, CostKind, FMulOpIdx);
return Cost;
@@ -17649,8 +17638,8 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
auto GetScalarCost = [&](unsigned Idx) {
if (isa<PoisonValue>(UniqueValues[Idx]))
return InstructionCost(TTI::TCC_Free);
- return GetFMulAddCost(E->getOperations(),
- cast<Instruction>(UniqueValues[Idx]));
+ auto *VI = cast<Instruction>(UniqueValues[Idx]);
+ return GetFMulAddCost(E->getOperations(), VI, getFMulOperandIdx(VI));
};
auto GetVectorCost = [&, &TTI = *TTI](InstructionCost CommonCost) {
FastMathFlags FMF;
@@ -32281,7 +32270,7 @@ class HorizontalReduction {
if (RdxKind == RecurKind::FAdd) {
InstructionCost FMACost =
canConvertToFMA(RdxOp, getSameOpcode(RdxOp, TLI), DT, DL,
- *TTI, TLI, CostKind);
+ *TTI, TLI, CostKind, /*FMulOpIdx=*/0);
if (FMACost.isValid()) {
LLVM_DEBUG(dbgs() << "FMA cost: " << FMACost << "\n");
if (auto *I = dyn_cast<Instruction>(RdxVal)) {
@@ -32407,7 +32396,7 @@ class HorizontalReduction {
}
if (!Ops.empty()) {
FMACost = canConvertToFMA(Ops, getSameOpcode(Ops, TLI), DT, DL,
- *TTI, TLI, CostKind);
+ *TTI, TLI, CostKind, /*FMulOpIdx=*/0);
if (FMACost.isValid()) {
// Calculate actual FMAD cost.
IntrinsicCostAttributes ICA(Intrinsic::fmuladd, RVecTy,
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer/SLPUtils.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer/SLPUtils.cpp
index af6f8032c7b0b..d8ab0d5f1d3c9 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer/SLPUtils.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer/SLPUtils.cpp
@@ -771,6 +771,18 @@ Instruction *lookThroughCastRoundTrip(Value *V, bool MustBeElidable) {
return Narrow;
}
+unsigned getFMulOperandIdx(const Instruction *I) {
+ assert((I->getOpcode() == Instruction::Add ||
+ I->getOpcode() == Instruction::Sub ||
+ I->getOpcode() == Instruction::FAdd ||
+ I->getOpcode() == Instruction::FSub) &&
+ "Expected an add/sub-like instruction");
+ for (unsigned Idx : seq<unsigned>(I->getNumOperands()))
+ if (match(I->getOperand(Idx), m_OneUse(m_FMul(m_Value(), m_Value()))))
+ return Idx;
+ return 0;
+}
+
namespace {
/// Shifts and the mask accumulated from the narrow ops on the current path:
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer/SLPUtils.h b/llvm/lib/Transforms/Vectorize/SLPVectorizer/SLPUtils.h
index e9aeff605eb91..774cd02ada4f7 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer/SLPUtils.h
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer/SLPUtils.h
@@ -337,6 +337,10 @@ bool isOnceUsedSeed(const Instruction *I);
/// produce nan/inf.
Instruction *lookThroughCastRoundTrip(Value *V, bool MustBeElidable);
+/// \returns the operand index of \p I that holds a one-use fmul, 0 if there is
+/// none. \p I must be an add/sub-like instruction.
+unsigned getFMulOperandIdx(const Instruction *I);
+
/// Narrow reduction leaf: the value, the shift applied after widening and
/// the mask applied in the narrow type before widening, clearing the bits
/// the absorbed narrow shls shift out and applying the absorbed narrow
>From 97c99be6ff7290a9671dc6452ec60a7e1483a2a1 Mon Sep 17 00:00:00 2001
From: Dmitry Sidorov <Dmitry.Sidorov at amd.com>
Date: Sun, 30 Aug 2026 19:33:30 +0200
Subject: [PATCH 4/5] wip
---
.../Transforms/Vectorize/SLPVectorizer.cpp | 24 ++++++++++---------
.../Vectorize/SLPVectorizer/SLPUtils.cpp | 6 ++---
.../Vectorize/SLPVectorizer/SLPUtils.h | 2 +-
3 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 1779611454340..e20bffb02800c 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -14591,8 +14591,7 @@ canConvertToFMA(ArrayRef<Value *> VL, const InstructionsState &S,
InstructionsCompatibilityAnalysis Analysis(DT, DL, TTI, TLI);
SmallVector<BoUpSLP::ValueList> Operands = Analysis.buildOperands(S, VL);
- if (FMulOpIdx >= Operands.size())
- return InstructionCost::getInvalid();
+ assert(FMulOpIdx < Operands.size() && "Expected a binary add/sub-like op");
InstructionsState OpS = getSameOpcode(Operands[FMulOpIdx], TLI);
if (!OpS.valid())
return InstructionCost::getInvalid();
@@ -15446,17 +15445,17 @@ void BoUpSLP::transformNodes() {
V->hasOneUse();
});
};
- if (!IsOneUseVectorFMulOperand(LHS) &&
- (E.getOpcode() == Instruction::FSub ||
- !IsOneUseVectorFMulOperand(RHS)))
+ const bool FMulOnLHS = IsOneUseVectorFMulOperand(LHS);
+ if (!FMulOnLHS && (E.getOpcode() == Instruction::FSub ||
+ !IsOneUseVectorFMulOperand(RHS)))
break;
if (!canConvertToFMA(E.Scalars, E.getOperations(), *DT, *DL, *TTI, *TLI,
- CostKind, /*FMulOpIdx=*/0)
+ CostKind, FMulOnLHS ? 0 : 1)
.isValid())
break;
// This node is a fmuladd node.
E.CombinedOp = TreeEntry::FMulAdd;
- TreeEntry *FMulEntry = getOperandEntry(&E, 0);
+ TreeEntry *FMulEntry = getOperandEntry(&E, FMulOnLHS ? 0 : 1);
if (FMulEntry->UserTreeIndex &&
FMulEntry->State == TreeEntry::Vectorize) {
// The FMul node is part of the combined fmuladd node.
@@ -17639,7 +17638,9 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
if (isa<PoisonValue>(UniqueValues[Idx]))
return InstructionCost(TTI::TCC_Free);
auto *VI = cast<Instruction>(UniqueValues[Idx]);
- return GetFMulAddCost(E->getOperations(), VI, getFMulOperandIdx(VI));
+ return GetFMulAddCost(E->getOperations(), VI,
+ E->isCopyableElement(VI) ? 0
+ : getFMulOperandIdx(VI));
};
auto GetVectorCost = [&, &TTI = *TTI](InstructionCost CommonCost) {
FastMathFlags FMF;
@@ -17810,8 +17811,9 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
InstructionCost ScalarCost = TTI->getArithmeticInstrCost(
ShuffleOrOp, OrigScalarTy, CostKind, Op1Info, Op2Info, Operands);
if (auto *I = dyn_cast<Instruction>(UniqueValues[Idx]);
- I && (ShuffleOrOp == Instruction::FAdd ||
- ShuffleOrOp == Instruction::FSub)) {
+ I && !E->isCopyableElement(I) &&
+ (ShuffleOrOp == Instruction::FAdd ||
+ ShuffleOrOp == Instruction::FSub)) {
InstructionCost IntrinsicCost =
GetFMulAddCost(E->getOperations(), I, getFMulOperandIdx(I));
if (IntrinsicCost.isValid())
@@ -34481,7 +34483,7 @@ bool SLPVectorizerPass::vectorizeOnceUsedSeeds(BasicBlock *BB, BoUpSLP &R) {
if (InstructionsState S = getSameOpcode(U, *TLI);
S && S.isAddSubLikeOp() &&
canConvertToFMA(U, S, *DT, *DL, *TTI, *TLI, R.getCostKind(),
- U->getOperand(1) == &I ? 1 : 0)
+ getFMulOperandIdx(U))
.isValid())
continue;
}
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer/SLPUtils.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer/SLPUtils.cpp
index d8ab0d5f1d3c9..960d49866ad2c 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer/SLPUtils.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer/SLPUtils.cpp
@@ -772,11 +772,9 @@ Instruction *lookThroughCastRoundTrip(Value *V, bool MustBeElidable) {
}
unsigned getFMulOperandIdx(const Instruction *I) {
- assert((I->getOpcode() == Instruction::Add ||
- I->getOpcode() == Instruction::Sub ||
- I->getOpcode() == Instruction::FAdd ||
+ assert((I->getOpcode() == Instruction::FAdd ||
I->getOpcode() == Instruction::FSub) &&
- "Expected an add/sub-like instruction");
+ "Expected an fadd/fsub-like instruction");
for (unsigned Idx : seq<unsigned>(I->getNumOperands()))
if (match(I->getOperand(Idx), m_OneUse(m_FMul(m_Value(), m_Value()))))
return Idx;
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer/SLPUtils.h b/llvm/lib/Transforms/Vectorize/SLPVectorizer/SLPUtils.h
index 774cd02ada4f7..9edc8eda3cd8d 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer/SLPUtils.h
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer/SLPUtils.h
@@ -338,7 +338,7 @@ bool isOnceUsedSeed(const Instruction *I);
Instruction *lookThroughCastRoundTrip(Value *V, bool MustBeElidable);
/// \returns the operand index of \p I that holds a one-use fmul, 0 if there is
-/// none. \p I must be an add/sub-like instruction.
+/// none. \p I must be an fadd/fsub-like instruction.
unsigned getFMulOperandIdx(const Instruction *I);
/// Narrow reduction leaf: the value, the shift applied after widening and
>From 0f178028f239fca03d10a40ff25cfacadd47c95f Mon Sep 17 00:00:00 2001
From: Dmitry Sidorov <Dmitry.Sidorov at amd.com>
Date: Sun, 30 Aug 2026 22:58:20 +0200
Subject: [PATCH 5/5] update tests
---
.../AMDGPU/elementwise-fma-operand1.ll | 126 +++++++++++++++---
.../X86/select-logical-or-and-i1-vector.ll | 102 +++++++-------
2 files changed, 162 insertions(+), 66 deletions(-)
diff --git a/llvm/test/Transforms/SLPVectorizer/AMDGPU/elementwise-fma-operand1.ll b/llvm/test/Transforms/SLPVectorizer/AMDGPU/elementwise-fma-operand1.ll
index c4c97622ac726..c928eb4df3227 100644
--- a/llvm/test/Transforms/SLPVectorizer/AMDGPU/elementwise-fma-operand1.ll
+++ b/llvm/test/Transforms/SLPVectorizer/AMDGPU/elementwise-fma-operand1.ll
@@ -18,12 +18,42 @@ define void @axpy4_contract(ptr noalias %d, ptr noalias %a, ptr noalias %b, ptr
; CHECK-LABEL: define void @axpy4_contract(
; CHECK-SAME: ptr noalias [[D:%.*]], ptr noalias [[A:%.*]], ptr noalias [[B:%.*]], ptr noalias [[C:%.*]]) #[[ATTR0:[0-9]+]] {
; CHECK-NEXT: [[ENTRY:.*:]]
-; CHECK-NEXT: [[TMP0:%.*]] = load <4 x float>, ptr [[C]], align 4
-; CHECK-NEXT: [[TMP1:%.*]] = load <4 x float>, ptr [[A]], align 4
-; CHECK-NEXT: [[TMP2:%.*]] = load <4 x float>, ptr [[B]], align 4
-; CHECK-NEXT: [[TMP3:%.*]] = fmul contract <4 x float> [[TMP1]], [[TMP2]]
-; CHECK-NEXT: [[TMP4:%.*]] = fadd contract <4 x float> [[TMP0]], [[TMP3]]
-; CHECK-NEXT: store <4 x float> [[TMP4]], ptr [[D]], align 4
+; CHECK-NEXT: [[C0:%.*]] = load float, ptr [[C]], align 4
+; CHECK-NEXT: [[A0:%.*]] = load float, ptr [[A]], align 4
+; CHECK-NEXT: [[B0:%.*]] = load float, ptr [[B]], align 4
+; CHECK-NEXT: [[M0:%.*]] = fmul contract float [[A0]], [[B0]]
+; CHECK-NEXT: [[R0:%.*]] = fadd contract float [[C0]], [[M0]]
+; CHECK-NEXT: store float [[R0]], ptr [[D]], align 4
+; CHECK-NEXT: [[CP1:%.*]] = getelementptr inbounds float, ptr [[C]], i64 1
+; CHECK-NEXT: [[C1:%.*]] = load float, ptr [[CP1]], align 4
+; CHECK-NEXT: [[AP1:%.*]] = getelementptr inbounds float, ptr [[A]], i64 1
+; CHECK-NEXT: [[A1:%.*]] = load float, ptr [[AP1]], align 4
+; CHECK-NEXT: [[BP1:%.*]] = getelementptr inbounds float, ptr [[B]], i64 1
+; CHECK-NEXT: [[B1:%.*]] = load float, ptr [[BP1]], align 4
+; CHECK-NEXT: [[M1:%.*]] = fmul contract float [[A1]], [[B1]]
+; CHECK-NEXT: [[R1:%.*]] = fadd contract float [[C1]], [[M1]]
+; CHECK-NEXT: [[DP1:%.*]] = getelementptr inbounds float, ptr [[D]], i64 1
+; CHECK-NEXT: store float [[R1]], ptr [[DP1]], align 4
+; CHECK-NEXT: [[CP2:%.*]] = getelementptr inbounds float, ptr [[C]], i64 2
+; CHECK-NEXT: [[C2:%.*]] = load float, ptr [[CP2]], align 4
+; CHECK-NEXT: [[AP2:%.*]] = getelementptr inbounds float, ptr [[A]], i64 2
+; CHECK-NEXT: [[A2:%.*]] = load float, ptr [[AP2]], align 4
+; CHECK-NEXT: [[BP2:%.*]] = getelementptr inbounds float, ptr [[B]], i64 2
+; CHECK-NEXT: [[B2:%.*]] = load float, ptr [[BP2]], align 4
+; CHECK-NEXT: [[M2:%.*]] = fmul contract float [[A2]], [[B2]]
+; CHECK-NEXT: [[R2:%.*]] = fadd contract float [[C2]], [[M2]]
+; CHECK-NEXT: [[DP2:%.*]] = getelementptr inbounds float, ptr [[D]], i64 2
+; CHECK-NEXT: store float [[R2]], ptr [[DP2]], align 4
+; CHECK-NEXT: [[CP3:%.*]] = getelementptr inbounds float, ptr [[C]], i64 3
+; CHECK-NEXT: [[C3:%.*]] = load float, ptr [[CP3]], align 4
+; CHECK-NEXT: [[AP3:%.*]] = getelementptr inbounds float, ptr [[A]], i64 3
+; CHECK-NEXT: [[A3:%.*]] = load float, ptr [[AP3]], align 4
+; CHECK-NEXT: [[BP3:%.*]] = getelementptr inbounds float, ptr [[B]], i64 3
+; CHECK-NEXT: [[B3:%.*]] = load float, ptr [[BP3]], align 4
+; CHECK-NEXT: [[M3:%.*]] = fmul contract float [[A3]], [[B3]]
+; CHECK-NEXT: [[R3:%.*]] = fadd contract float [[C3]], [[M3]]
+; CHECK-NEXT: [[DP3:%.*]] = getelementptr inbounds float, ptr [[D]], i64 3
+; CHECK-NEXT: store float [[R3]], ptr [[DP3]], align 4
; CHECK-NEXT: ret void
;
; THR12-LABEL: define void @axpy4_contract(
@@ -81,12 +111,42 @@ define void @axpy4_reassoc(ptr noalias %d, ptr noalias %a, ptr noalias %b, ptr n
; CHECK-LABEL: define void @axpy4_reassoc(
; CHECK-SAME: ptr noalias [[D:%.*]], ptr noalias [[A:%.*]], ptr noalias [[B:%.*]], ptr noalias [[C:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[ENTRY:.*:]]
-; CHECK-NEXT: [[TMP0:%.*]] = load <4 x float>, ptr [[C]], align 4
-; CHECK-NEXT: [[TMP1:%.*]] = load <4 x float>, ptr [[A]], align 4
-; CHECK-NEXT: [[TMP2:%.*]] = load <4 x float>, ptr [[B]], align 4
-; CHECK-NEXT: [[TMP3:%.*]] = fmul reassoc contract <4 x float> [[TMP1]], [[TMP2]]
-; CHECK-NEXT: [[TMP4:%.*]] = fadd reassoc contract <4 x float> [[TMP0]], [[TMP3]]
-; CHECK-NEXT: store <4 x float> [[TMP4]], ptr [[D]], align 4
+; CHECK-NEXT: [[C0:%.*]] = load float, ptr [[C]], align 4
+; CHECK-NEXT: [[A0:%.*]] = load float, ptr [[A]], align 4
+; CHECK-NEXT: [[B0:%.*]] = load float, ptr [[B]], align 4
+; CHECK-NEXT: [[M0:%.*]] = fmul reassoc contract float [[A0]], [[B0]]
+; CHECK-NEXT: [[R0:%.*]] = fadd reassoc contract float [[C0]], [[M0]]
+; CHECK-NEXT: store float [[R0]], ptr [[D]], align 4
+; CHECK-NEXT: [[CP1:%.*]] = getelementptr inbounds float, ptr [[C]], i64 1
+; CHECK-NEXT: [[C1:%.*]] = load float, ptr [[CP1]], align 4
+; CHECK-NEXT: [[AP1:%.*]] = getelementptr inbounds float, ptr [[A]], i64 1
+; CHECK-NEXT: [[A1:%.*]] = load float, ptr [[AP1]], align 4
+; CHECK-NEXT: [[BP1:%.*]] = getelementptr inbounds float, ptr [[B]], i64 1
+; CHECK-NEXT: [[B1:%.*]] = load float, ptr [[BP1]], align 4
+; CHECK-NEXT: [[M1:%.*]] = fmul reassoc contract float [[A1]], [[B1]]
+; CHECK-NEXT: [[R1:%.*]] = fadd reassoc contract float [[C1]], [[M1]]
+; CHECK-NEXT: [[DP1:%.*]] = getelementptr inbounds float, ptr [[D]], i64 1
+; CHECK-NEXT: store float [[R1]], ptr [[DP1]], align 4
+; CHECK-NEXT: [[CP2:%.*]] = getelementptr inbounds float, ptr [[C]], i64 2
+; CHECK-NEXT: [[C2:%.*]] = load float, ptr [[CP2]], align 4
+; CHECK-NEXT: [[AP2:%.*]] = getelementptr inbounds float, ptr [[A]], i64 2
+; CHECK-NEXT: [[A2:%.*]] = load float, ptr [[AP2]], align 4
+; CHECK-NEXT: [[BP2:%.*]] = getelementptr inbounds float, ptr [[B]], i64 2
+; CHECK-NEXT: [[B2:%.*]] = load float, ptr [[BP2]], align 4
+; CHECK-NEXT: [[M2:%.*]] = fmul reassoc contract float [[A2]], [[B2]]
+; CHECK-NEXT: [[R2:%.*]] = fadd reassoc contract float [[C2]], [[M2]]
+; CHECK-NEXT: [[DP2:%.*]] = getelementptr inbounds float, ptr [[D]], i64 2
+; CHECK-NEXT: store float [[R2]], ptr [[DP2]], align 4
+; CHECK-NEXT: [[CP3:%.*]] = getelementptr inbounds float, ptr [[C]], i64 3
+; CHECK-NEXT: [[C3:%.*]] = load float, ptr [[CP3]], align 4
+; CHECK-NEXT: [[AP3:%.*]] = getelementptr inbounds float, ptr [[A]], i64 3
+; CHECK-NEXT: [[A3:%.*]] = load float, ptr [[AP3]], align 4
+; CHECK-NEXT: [[BP3:%.*]] = getelementptr inbounds float, ptr [[B]], i64 3
+; CHECK-NEXT: [[B3:%.*]] = load float, ptr [[BP3]], align 4
+; CHECK-NEXT: [[M3:%.*]] = fmul reassoc contract float [[A3]], [[B3]]
+; CHECK-NEXT: [[R3:%.*]] = fadd reassoc contract float [[C3]], [[M3]]
+; CHECK-NEXT: [[DP3:%.*]] = getelementptr inbounds float, ptr [[D]], i64 3
+; CHECK-NEXT: store float [[R3]], ptr [[DP3]], align 4
; CHECK-NEXT: ret void
;
; THR12-LABEL: define void @axpy4_reassoc(
@@ -144,12 +204,42 @@ define void @axpy4_mixed_reassoc(ptr noalias %d, ptr noalias %a, ptr noalias %b,
; CHECK-LABEL: define void @axpy4_mixed_reassoc(
; CHECK-SAME: ptr noalias [[D:%.*]], ptr noalias [[A:%.*]], ptr noalias [[B:%.*]], ptr noalias [[C:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[ENTRY:.*:]]
-; CHECK-NEXT: [[TMP0:%.*]] = load <4 x float>, ptr [[C]], align 4
-; CHECK-NEXT: [[TMP1:%.*]] = load <4 x float>, ptr [[A]], align 4
-; CHECK-NEXT: [[TMP2:%.*]] = load <4 x float>, ptr [[B]], align 4
-; CHECK-NEXT: [[TMP3:%.*]] = fmul contract <4 x float> [[TMP1]], [[TMP2]]
-; CHECK-NEXT: [[TMP4:%.*]] = fadd contract <4 x float> [[TMP0]], [[TMP3]]
-; CHECK-NEXT: store <4 x float> [[TMP4]], ptr [[D]], align 4
+; CHECK-NEXT: [[C0:%.*]] = load float, ptr [[C]], align 4
+; CHECK-NEXT: [[A0:%.*]] = load float, ptr [[A]], align 4
+; CHECK-NEXT: [[B0:%.*]] = load float, ptr [[B]], align 4
+; CHECK-NEXT: [[M0:%.*]] = fmul contract float [[A0]], [[B0]]
+; CHECK-NEXT: [[R0:%.*]] = fadd reassoc contract float [[C0]], [[M0]]
+; CHECK-NEXT: store float [[R0]], ptr [[D]], align 4
+; CHECK-NEXT: [[CP1:%.*]] = getelementptr inbounds float, ptr [[C]], i64 1
+; CHECK-NEXT: [[C1:%.*]] = load float, ptr [[CP1]], align 4
+; CHECK-NEXT: [[AP1:%.*]] = getelementptr inbounds float, ptr [[A]], i64 1
+; CHECK-NEXT: [[A1:%.*]] = load float, ptr [[AP1]], align 4
+; CHECK-NEXT: [[BP1:%.*]] = getelementptr inbounds float, ptr [[B]], i64 1
+; CHECK-NEXT: [[B1:%.*]] = load float, ptr [[BP1]], align 4
+; CHECK-NEXT: [[M1:%.*]] = fmul contract float [[A1]], [[B1]]
+; CHECK-NEXT: [[R1:%.*]] = fadd contract float [[C1]], [[M1]]
+; CHECK-NEXT: [[DP1:%.*]] = getelementptr inbounds float, ptr [[D]], i64 1
+; CHECK-NEXT: store float [[R1]], ptr [[DP1]], align 4
+; CHECK-NEXT: [[CP2:%.*]] = getelementptr inbounds float, ptr [[C]], i64 2
+; CHECK-NEXT: [[C2:%.*]] = load float, ptr [[CP2]], align 4
+; CHECK-NEXT: [[AP2:%.*]] = getelementptr inbounds float, ptr [[A]], i64 2
+; CHECK-NEXT: [[A2:%.*]] = load float, ptr [[AP2]], align 4
+; CHECK-NEXT: [[BP2:%.*]] = getelementptr inbounds float, ptr [[B]], i64 2
+; CHECK-NEXT: [[B2:%.*]] = load float, ptr [[BP2]], align 4
+; CHECK-NEXT: [[M2:%.*]] = fmul contract float [[A2]], [[B2]]
+; CHECK-NEXT: [[R2:%.*]] = fadd contract float [[C2]], [[M2]]
+; CHECK-NEXT: [[DP2:%.*]] = getelementptr inbounds float, ptr [[D]], i64 2
+; CHECK-NEXT: store float [[R2]], ptr [[DP2]], align 4
+; CHECK-NEXT: [[CP3:%.*]] = getelementptr inbounds float, ptr [[C]], i64 3
+; CHECK-NEXT: [[C3:%.*]] = load float, ptr [[CP3]], align 4
+; CHECK-NEXT: [[AP3:%.*]] = getelementptr inbounds float, ptr [[A]], i64 3
+; CHECK-NEXT: [[A3:%.*]] = load float, ptr [[AP3]], align 4
+; CHECK-NEXT: [[BP3:%.*]] = getelementptr inbounds float, ptr [[B]], i64 3
+; CHECK-NEXT: [[B3:%.*]] = load float, ptr [[BP3]], align 4
+; CHECK-NEXT: [[M3:%.*]] = fmul contract float [[A3]], [[B3]]
+; CHECK-NEXT: [[R3:%.*]] = fadd contract float [[C3]], [[M3]]
+; CHECK-NEXT: [[DP3:%.*]] = getelementptr inbounds float, ptr [[D]], i64 3
+; CHECK-NEXT: store float [[R3]], ptr [[DP3]], align 4
; CHECK-NEXT: ret void
;
; THR12-LABEL: define void @axpy4_mixed_reassoc(
diff --git a/llvm/test/Transforms/SLPVectorizer/X86/select-logical-or-and-i1-vector.ll b/llvm/test/Transforms/SLPVectorizer/X86/select-logical-or-and-i1-vector.ll
index 979701609b499..bb10829b8cca2 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/select-logical-or-and-i1-vector.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/select-logical-or-and-i1-vector.ll
@@ -12,30 +12,33 @@ define void @select_logical_or_i1(ptr %dst,
; CHECK-LABEL: define void @select_logical_or_i1(
; CHECK-SAME: ptr [[DST:%.*]], float [[D0:%.*]], float [[D1:%.*]], float [[D2:%.*]], float [[D3:%.*]], float [[THRESHOLD:%.*]], float [[HPHB_VAL:%.*]], i1 [[SCALAR_COND:%.*]], float [[Y0:%.*]], float [[Y1:%.*]], float [[Y2:%.*]], float [[Y3:%.*]], float [[E0:%.*]], float [[E1:%.*]], float [[E2:%.*]], float [[E3:%.*]]) #[[ATTR0:[0-9]+]] {
; CHECK-NEXT: [[ENTRY:.*:]]
-; CHECK-NEXT: [[TMP0:%.*]] = insertelement <4 x float> poison, float [[D0]], i64 0
-; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x float> [[TMP0]], float [[D1]], i64 1
-; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x float> [[TMP1]], float [[D2]], i64 2
-; CHECK-NEXT: [[TMP3:%.*]] = insertelement <4 x float> [[TMP2]], float [[D3]], i64 3
-; CHECK-NEXT: [[TMP4:%.*]] = insertelement <4 x float> poison, float [[THRESHOLD]], i64 0
-; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <4 x float> [[TMP4]], <4 x float> poison, <4 x i32> zeroinitializer
-; CHECK-NEXT: [[TMP6:%.*]] = fcmp fast uge <4 x float> [[TMP3]], [[TMP5]]
-; CHECK-NEXT: [[TMP7:%.*]] = insertelement <4 x i1> poison, i1 [[SCALAR_COND]], i64 0
-; CHECK-NEXT: [[TMP8:%.*]] = shufflevector <4 x i1> [[TMP7]], <4 x i1> poison, <4 x i32> zeroinitializer
-; CHECK-NEXT: [[TMP9:%.*]] = select <4 x i1> [[TMP6]], <4 x i1> splat (i1 true), <4 x i1> [[TMP8]]
-; CHECK-NEXT: [[TMP10:%.*]] = insertelement <4 x float> poison, float [[HPHB_VAL]], i64 0
-; CHECK-NEXT: [[TMP11:%.*]] = shufflevector <4 x float> [[TMP10]], <4 x float> poison, <4 x i32> zeroinitializer
-; CHECK-NEXT: [[TMP12:%.*]] = select <4 x i1> [[TMP9]], <4 x float> zeroinitializer, <4 x float> [[TMP11]]
-; CHECK-NEXT: [[TMP13:%.*]] = insertelement <4 x float> poison, float [[Y0]], i64 0
-; CHECK-NEXT: [[TMP14:%.*]] = insertelement <4 x float> [[TMP13]], float [[Y1]], i64 1
-; CHECK-NEXT: [[TMP15:%.*]] = insertelement <4 x float> [[TMP14]], float [[Y2]], i64 2
-; CHECK-NEXT: [[TMP16:%.*]] = insertelement <4 x float> [[TMP15]], float [[Y3]], i64 3
-; CHECK-NEXT: [[TMP17:%.*]] = fmul fast <4 x float> [[TMP12]], [[TMP16]]
-; CHECK-NEXT: [[TMP18:%.*]] = insertelement <4 x float> poison, float [[E0]], i64 0
-; CHECK-NEXT: [[TMP19:%.*]] = insertelement <4 x float> [[TMP18]], float [[E1]], i64 1
-; CHECK-NEXT: [[TMP20:%.*]] = insertelement <4 x float> [[TMP19]], float [[E2]], i64 2
-; CHECK-NEXT: [[TMP21:%.*]] = insertelement <4 x float> [[TMP20]], float [[E3]], i64 3
-; CHECK-NEXT: [[TMP22:%.*]] = fadd fast <4 x float> [[TMP21]], [[TMP17]]
-; CHECK-NEXT: store <4 x float> [[TMP22]], ptr [[DST]], align 4
+; CHECK-NEXT: [[CMP0:%.*]] = fcmp fast uge float [[D0]], [[THRESHOLD]]
+; CHECK-NEXT: [[CMP1:%.*]] = fcmp fast uge float [[D1]], [[THRESHOLD]]
+; CHECK-NEXT: [[CMP2:%.*]] = fcmp fast uge float [[D2]], [[THRESHOLD]]
+; CHECK-NEXT: [[CMP3:%.*]] = fcmp fast uge float [[D3]], [[THRESHOLD]]
+; CHECK-NEXT: [[OR0:%.*]] = select i1 [[CMP0]], i1 true, i1 [[SCALAR_COND]]
+; CHECK-NEXT: [[OR1:%.*]] = select i1 [[CMP1]], i1 true, i1 [[SCALAR_COND]]
+; CHECK-NEXT: [[OR2:%.*]] = select i1 [[CMP2]], i1 true, i1 [[SCALAR_COND]]
+; CHECK-NEXT: [[OR3:%.*]] = select i1 [[CMP3]], i1 true, i1 [[SCALAR_COND]]
+; CHECK-NEXT: [[SEL0:%.*]] = select i1 [[OR0]], float 0.000000e+00, float [[HPHB_VAL]]
+; CHECK-NEXT: [[SEL1:%.*]] = select i1 [[OR1]], float 0.000000e+00, float [[HPHB_VAL]]
+; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[OR2]], float 0.000000e+00, float [[HPHB_VAL]]
+; CHECK-NEXT: [[SEL3:%.*]] = select i1 [[OR3]], float 0.000000e+00, float [[HPHB_VAL]]
+; CHECK-NEXT: [[MUL0:%.*]] = fmul fast float [[SEL0]], [[Y0]]
+; CHECK-NEXT: [[MUL1:%.*]] = fmul fast float [[SEL1]], [[Y1]]
+; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[SEL2]], [[Y2]]
+; CHECK-NEXT: [[MUL3:%.*]] = fmul fast float [[SEL3]], [[Y3]]
+; CHECK-NEXT: [[RES0:%.*]] = fadd fast float [[E0]], [[MUL0]]
+; CHECK-NEXT: [[RES1:%.*]] = fadd fast float [[E1]], [[MUL1]]
+; CHECK-NEXT: [[RES2:%.*]] = fadd fast float [[E2]], [[MUL2]]
+; CHECK-NEXT: [[RES3:%.*]] = fadd fast float [[E3]], [[MUL3]]
+; CHECK-NEXT: store float [[RES0]], ptr [[DST]], align 4
+; CHECK-NEXT: [[P1:%.*]] = getelementptr inbounds float, ptr [[DST]], i64 1
+; CHECK-NEXT: store float [[RES1]], ptr [[P1]], align 4
+; CHECK-NEXT: [[P2:%.*]] = getelementptr inbounds float, ptr [[DST]], i64 2
+; CHECK-NEXT: store float [[RES2]], ptr [[P2]], align 4
+; CHECK-NEXT: [[P3:%.*]] = getelementptr inbounds float, ptr [[DST]], i64 3
+; CHECK-NEXT: store float [[RES3]], ptr [[P3]], align 4
; CHECK-NEXT: ret void
;
float %d0, float %d1, float %d2, float %d3,
@@ -84,30 +87,33 @@ define void @select_logical_and_i1(ptr %dst,
; CHECK-LABEL: define void @select_logical_and_i1(
; CHECK-SAME: ptr [[DST:%.*]], float [[D0:%.*]], float [[D1:%.*]], float [[D2:%.*]], float [[D3:%.*]], float [[THRESHOLD:%.*]], float [[HPHB_VAL:%.*]], i1 [[SCALAR_COND:%.*]], float [[Y0:%.*]], float [[Y1:%.*]], float [[Y2:%.*]], float [[Y3:%.*]], float [[E0:%.*]], float [[E1:%.*]], float [[E2:%.*]], float [[E3:%.*]]) #[[ATTR0]] {
; CHECK-NEXT: [[ENTRY:.*:]]
-; CHECK-NEXT: [[TMP0:%.*]] = insertelement <4 x float> poison, float [[D0]], i64 0
-; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x float> [[TMP0]], float [[D1]], i64 1
-; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x float> [[TMP1]], float [[D2]], i64 2
-; CHECK-NEXT: [[TMP3:%.*]] = insertelement <4 x float> [[TMP2]], float [[D3]], i64 3
-; CHECK-NEXT: [[TMP4:%.*]] = insertelement <4 x float> poison, float [[THRESHOLD]], i64 0
-; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <4 x float> [[TMP4]], <4 x float> poison, <4 x i32> zeroinitializer
-; CHECK-NEXT: [[TMP6:%.*]] = fcmp fast uge <4 x float> [[TMP3]], [[TMP5]]
-; CHECK-NEXT: [[TMP7:%.*]] = insertelement <4 x i1> poison, i1 [[SCALAR_COND]], i64 0
-; CHECK-NEXT: [[TMP8:%.*]] = shufflevector <4 x i1> [[TMP7]], <4 x i1> poison, <4 x i32> zeroinitializer
-; CHECK-NEXT: [[TMP9:%.*]] = select <4 x i1> [[TMP6]], <4 x i1> [[TMP8]], <4 x i1> zeroinitializer
-; CHECK-NEXT: [[TMP10:%.*]] = insertelement <4 x float> poison, float [[HPHB_VAL]], i64 0
-; CHECK-NEXT: [[TMP11:%.*]] = shufflevector <4 x float> [[TMP10]], <4 x float> poison, <4 x i32> zeroinitializer
-; CHECK-NEXT: [[TMP12:%.*]] = select <4 x i1> [[TMP9]], <4 x float> zeroinitializer, <4 x float> [[TMP11]]
-; CHECK-NEXT: [[TMP13:%.*]] = insertelement <4 x float> poison, float [[Y0]], i64 0
-; CHECK-NEXT: [[TMP14:%.*]] = insertelement <4 x float> [[TMP13]], float [[Y1]], i64 1
-; CHECK-NEXT: [[TMP15:%.*]] = insertelement <4 x float> [[TMP14]], float [[Y2]], i64 2
-; CHECK-NEXT: [[TMP16:%.*]] = insertelement <4 x float> [[TMP15]], float [[Y3]], i64 3
-; CHECK-NEXT: [[TMP17:%.*]] = fmul fast <4 x float> [[TMP12]], [[TMP16]]
-; CHECK-NEXT: [[TMP18:%.*]] = insertelement <4 x float> poison, float [[E0]], i64 0
-; CHECK-NEXT: [[TMP19:%.*]] = insertelement <4 x float> [[TMP18]], float [[E1]], i64 1
-; CHECK-NEXT: [[TMP20:%.*]] = insertelement <4 x float> [[TMP19]], float [[E2]], i64 2
-; CHECK-NEXT: [[TMP21:%.*]] = insertelement <4 x float> [[TMP20]], float [[E3]], i64 3
-; CHECK-NEXT: [[TMP22:%.*]] = fadd fast <4 x float> [[TMP21]], [[TMP17]]
-; CHECK-NEXT: store <4 x float> [[TMP22]], ptr [[DST]], align 4
+; CHECK-NEXT: [[CMP0:%.*]] = fcmp fast uge float [[D0]], [[THRESHOLD]]
+; CHECK-NEXT: [[CMP1:%.*]] = fcmp fast uge float [[D1]], [[THRESHOLD]]
+; CHECK-NEXT: [[CMP2:%.*]] = fcmp fast uge float [[D2]], [[THRESHOLD]]
+; CHECK-NEXT: [[CMP3:%.*]] = fcmp fast uge float [[D3]], [[THRESHOLD]]
+; CHECK-NEXT: [[AND0:%.*]] = select i1 [[CMP0]], i1 [[SCALAR_COND]], i1 false
+; CHECK-NEXT: [[AND1:%.*]] = select i1 [[CMP1]], i1 [[SCALAR_COND]], i1 false
+; CHECK-NEXT: [[AND2:%.*]] = select i1 [[CMP2]], i1 [[SCALAR_COND]], i1 false
+; CHECK-NEXT: [[AND3:%.*]] = select i1 [[CMP3]], i1 [[SCALAR_COND]], i1 false
+; CHECK-NEXT: [[SEL0:%.*]] = select i1 [[AND0]], float 0.000000e+00, float [[HPHB_VAL]]
+; CHECK-NEXT: [[SEL1:%.*]] = select i1 [[AND1]], float 0.000000e+00, float [[HPHB_VAL]]
+; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[AND2]], float 0.000000e+00, float [[HPHB_VAL]]
+; CHECK-NEXT: [[SEL3:%.*]] = select i1 [[AND3]], float 0.000000e+00, float [[HPHB_VAL]]
+; CHECK-NEXT: [[MUL0:%.*]] = fmul fast float [[SEL0]], [[Y0]]
+; CHECK-NEXT: [[MUL1:%.*]] = fmul fast float [[SEL1]], [[Y1]]
+; CHECK-NEXT: [[MUL2:%.*]] = fmul fast float [[SEL2]], [[Y2]]
+; CHECK-NEXT: [[MUL3:%.*]] = fmul fast float [[SEL3]], [[Y3]]
+; CHECK-NEXT: [[RES0:%.*]] = fadd fast float [[E0]], [[MUL0]]
+; CHECK-NEXT: [[RES1:%.*]] = fadd fast float [[E1]], [[MUL1]]
+; CHECK-NEXT: [[RES2:%.*]] = fadd fast float [[E2]], [[MUL2]]
+; CHECK-NEXT: [[RES3:%.*]] = fadd fast float [[E3]], [[MUL3]]
+; CHECK-NEXT: store float [[RES0]], ptr [[DST]], align 4
+; CHECK-NEXT: [[P1:%.*]] = getelementptr inbounds float, ptr [[DST]], i64 1
+; CHECK-NEXT: store float [[RES1]], ptr [[P1]], align 4
+; CHECK-NEXT: [[P2:%.*]] = getelementptr inbounds float, ptr [[DST]], i64 2
+; CHECK-NEXT: store float [[RES2]], ptr [[P2]], align 4
+; CHECK-NEXT: [[P3:%.*]] = getelementptr inbounds float, ptr [[DST]], i64 3
+; CHECK-NEXT: store float [[RES3]], ptr [[P3]], align 4
; CHECK-NEXT: ret void
;
float %d0, float %d1, float %d2, float %d3,
More information about the llvm-commits
mailing list