[llvm] [VPlan] Plumb recurrence FMFs through VPReductionPHIRecipe via VPIRFlags. NFC (PR #181694)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 19 02:56:46 PST 2026
https://github.com/lukel97 updated https://github.com/llvm/llvm-project/pull/181694
>From 682d80f69e82aa8542843451996d57fa2a297fb9 Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Sun, 25 Jan 2026 17:44:26 +0800
Subject: [PATCH 1/5] [VPlan] Plumb reduction FMFs through VPReductionPHIRecipe
via VPIRFlags. NFC
In order to be able to create selects for reduction phis through tail folding in foldTailByMasking (#176143), make VPReductionPHIRecipe an instance of VPIRFlags and plumb the FMFs from the original RdxDesc.
This allows us to remove more uses of the RecurrenceDescriptor in addReductionResultComputation, which should help untie it from LoopVectorizationLegality.
---
.../Transforms/Vectorize/LoopVectorize.cpp | 21 +++++++------------
llvm/lib/Transforms/Vectorize/VPlan.h | 7 ++++---
.../Vectorize/VPlanConstruction.cpp | 2 ++
.../lib/Transforms/Vectorize/VPlanRecipes.cpp | 3 ++-
.../Transforms/Vectorize/VPlanTransforms.cpp | 3 ++-
5 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 72400e1055427..003945697c921 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8480,11 +8480,8 @@ void LoopVectorizationPlanner::addReductionResultComputation(
if (!PhiR->isInLoop() && CM.foldTailByMasking() &&
(!RR || !RR->isPartialReduction())) {
VPValue *Cond = vputils::findHeaderMask(*Plan);
- VPIRFlags Flags = PhiTy->isFloatingPointTy()
- ? VPIRFlags(RdxDesc.getFastMathFlags())
- : VPIRFlags();
NewExitingVPV =
- Builder.createSelect(Cond, OrigExitingVPV, PhiR, {}, "", Flags);
+ Builder.createSelect(Cond, OrigExitingVPV, PhiR, {}, "", *PhiR);
OrigExitingVPV->replaceUsesWithIf(NewExitingVPV, [](VPUser &U, unsigned) {
using namespace VPlanPatternMatch;
return match(
@@ -8532,9 +8529,7 @@ void LoopVectorizationPlanner::addReductionResultComputation(
{Start, NewVal, NewExitingVPV}, ExitDL);
} else {
FastMathFlags FMFs =
- RecurrenceDescriptor::isFloatingPointRecurrenceKind(RecurrenceKind)
- ? RdxDesc.getFastMathFlags()
- : FastMathFlags();
+ PhiR->hasFastMathFlags() ? PhiR->getFastMathFlags() : FastMathFlags();
VPIRFlags Flags(RecurrenceKind, PhiR->isOrdered(), PhiR->isInLoop(),
FMFs);
FinalReductionResult =
@@ -8622,20 +8617,20 @@ void LoopVectorizationPlanner::addReductionResultComputation(
continue;
}
- RecurKind RK = RdxDesc.getRecurrenceKind();
+ RecurKind RK = PhiR->getRecurrenceKind();
if ((!RecurrenceDescriptor::isAnyOfRecurrenceKind(RK) &&
!RecurrenceDescriptor::isFindIVRecurrenceKind(RK) &&
!RecurrenceDescriptor::isMinMaxRecurrenceKind(RK) &&
!RecurrenceDescriptor::isFindLastRecurrenceKind(RK))) {
VPBuilder PHBuilder(Plan->getVectorPreheader());
- VPValue *Iden = Plan->getOrAddLiveIn(
- getRecurrenceIdentity(RK, PhiTy, RdxDesc.getFastMathFlags()));
+ VPValue *Iden = Plan->getOrAddLiveIn(getRecurrenceIdentity(
+ RK, PhiTy,
+ PhiR->hasFastMathFlags() ? PhiR->getFastMathFlags()
+ : FastMathFlags()));
auto *ScaleFactorVPV = Plan->getConstantInt(32, 1);
VPValue *StartV = PHBuilder.createNaryOp(
VPInstruction::ReductionStartVector,
- {PhiR->getStartValue(), Iden, ScaleFactorVPV},
- PhiTy->isFloatingPointTy() ? RdxDesc.getFastMathFlags()
- : FastMathFlags());
+ {PhiR->getStartValue(), Iden, ScaleFactorVPV}, *PhiR);
PhiR->setOperand(0, StartV);
}
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index bb36659cdba6c..b126d11496597 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -2602,7 +2602,7 @@ inline ReductionStyle getReductionStyle(bool InLoop, bool Ordered,
/// A recipe for handling reduction phis. The start value is the first operand
/// of the recipe and the incoming value from the backedge is the second
/// operand.
-class VPReductionPHIRecipe : public VPHeaderPHIRecipe {
+class VPReductionPHIRecipe : public VPHeaderPHIRecipe, public VPIRFlags {
/// The recurrence kind of the reduction.
const RecurKind Kind;
@@ -2618,9 +2618,10 @@ class VPReductionPHIRecipe : public VPHeaderPHIRecipe {
/// Create a new VPReductionPHIRecipe for the reduction \p Phi.
VPReductionPHIRecipe(PHINode *Phi, RecurKind Kind, VPValue &Start,
VPValue &BackedgeValue, ReductionStyle Style,
+ const VPIRFlags &Flags,
bool HasUsesOutsideReductionChain = false)
: VPHeaderPHIRecipe(VPRecipeBase::VPReductionPHISC, Phi, &Start),
- Kind(Kind), Style(Style),
+ VPIRFlags(Flags), Kind(Kind), Style(Style),
HasUsesOutsideReductionChain(HasUsesOutsideReductionChain) {
addOperand(&BackedgeValue);
}
@@ -2630,7 +2631,7 @@ class VPReductionPHIRecipe : public VPHeaderPHIRecipe {
VPReductionPHIRecipe *clone() override {
return new VPReductionPHIRecipe(
dyn_cast_or_null<PHINode>(getUnderlyingValue()), getRecurrenceKind(),
- *getOperand(0), *getBackedgeValue(), Style,
+ *getOperand(0), *getBackedgeValue(), Style, *this,
HasUsesOutsideReductionChain);
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp b/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
index 80847fcbb77fb..ac9deb89560a5 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp
@@ -720,6 +720,8 @@ void VPlanTransforms::createHeaderPhiRecipes(
Phi, RdxDesc.getRecurrenceKind(), *Start, *BackedgeValue,
getReductionStyle(InLoopReductions.contains(Phi), UseOrderedReductions,
ScaleFactor),
+ Phi->getType()->isFloatingPointTy() ? RdxDesc.getFastMathFlags()
+ : VPIRFlags(),
RdxDesc.hasUsesOutsideReductionChain());
};
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index bab1fc773fa4b..d1f6c6698d09c 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -714,7 +714,8 @@ Value *VPInstruction::generate(VPTransformState &State) {
if (State.VF.isScalar())
return State.get(getOperand(0), true);
IRBuilderBase::FastMathFlagGuard FMFG(Builder);
- Builder.setFastMathFlags(getFastMathFlags());
+ if (hasFastMathFlags())
+ Builder.setFastMathFlags(getFastMathFlags());
// If this start vector is scaled then it should produce a vector with fewer
// elements than the VF.
ElementCount VF = State.VF.divideCoefficientBy(
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 51208b6aad680..0f2538b9dadbc 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -5734,7 +5734,8 @@ void VPlanTransforms::optimizeFindIVReductions(VPlan &Plan,
auto *NewPhiR = new VPReductionPHIRecipe(
cast<PHINode>(PhiR->getUnderlyingInstr()), RecurKind::FindIV, *Sentinel,
- *BackedgeVal, RdxUnordered{1}, PhiR->hasUsesOutsideReductionChain());
+ *BackedgeVal, RdxUnordered{1}, {},
+ PhiR->hasUsesOutsideReductionChain());
NewPhiR->insertBefore(PhiR);
PhiR->replaceAllUsesWith(NewPhiR);
PhiR->eraseFromParent();
>From 5d3ceea884a243b8dff50dfc42550de9104cb257 Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Tue, 17 Feb 2026 23:16:41 +0800
Subject: [PATCH 2/5] Print flags
---
llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp | 3 ++-
.../LoopVectorize/VPlan/vplan-printing-reductions.ll | 6 +++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index d1f6c6698d09c..dcbb3a18b6d74 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -4609,7 +4609,8 @@ void VPReductionPHIRecipe::printRecipe(raw_ostream &O, const Twine &Indent,
O << Indent << "WIDEN-REDUCTION-PHI ";
printAsOperand(O, SlotTracker);
- O << " = phi ";
+ O << " = phi";
+ printFlags(O);
printOperands(O, SlotTracker);
if (getVFScaleFactor() > 1)
O << " (VF scaled by 1/" << getVFScaleFactor() << ")";
diff --git a/llvm/test/Transforms/LoopVectorize/VPlan/vplan-printing-reductions.ll b/llvm/test/Transforms/LoopVectorize/VPlan/vplan-printing-reductions.ll
index e7bf014fdbd80..cd95f5cb99507 100644
--- a/llvm/test/Transforms/LoopVectorize/VPlan/vplan-printing-reductions.ll
+++ b/llvm/test/Transforms/LoopVectorize/VPlan/vplan-printing-reductions.ll
@@ -22,7 +22,7 @@ define float @print_reduction(i64 %n, ptr noalias %y) {
; CHECK-NEXT: <x1> vector loop: {
; CHECK-NEXT: vector.body:
; CHECK-NEXT: EMIT vp<[[VP4:%[0-9]+]]> = CANONICAL-INDUCTION ir<0>, vp<%index.next>
-; CHECK-NEXT: WIDEN-REDUCTION-PHI ir<%red> = phi vp<[[VP3]]>, ir<%red.next>
+; CHECK-NEXT: WIDEN-REDUCTION-PHI ir<%red> = phi fast vp<[[VP3]]>, ir<%red.next>
; CHECK-NEXT: vp<[[VP5:%[0-9]+]]> = SCALAR-STEPS vp<[[VP4]]>, ir<1>, vp<[[VP0]]>
; CHECK-NEXT: CLONE ir<%arrayidx> = getelementptr inbounds ir<%y>, vp<[[VP5]]>
; CHECK-NEXT: vp<[[VP6:%[0-9]+]]> = vector-pointer inbounds ir<%arrayidx>
@@ -95,7 +95,7 @@ define void @print_reduction_with_invariant_store(i64 %n, ptr noalias %y, ptr no
; CHECK-NEXT: <x1> vector loop: {
; CHECK-NEXT: vector.body:
; CHECK-NEXT: EMIT vp<[[VP4:%[0-9]+]]> = CANONICAL-INDUCTION ir<0>, vp<%index.next>
-; CHECK-NEXT: WIDEN-REDUCTION-PHI ir<%red> = phi vp<[[VP3]]>, ir<%red.next>
+; CHECK-NEXT: WIDEN-REDUCTION-PHI ir<%red> = phi fast vp<[[VP3]]>, ir<%red.next>
; CHECK-NEXT: vp<[[VP5:%[0-9]+]]> = SCALAR-STEPS vp<[[VP4]]>, ir<1>, vp<[[VP0]]>
; CHECK-NEXT: CLONE ir<%arrayidx> = getelementptr inbounds ir<%y>, vp<[[VP5]]>
; CHECK-NEXT: vp<[[VP6:%[0-9]+]]> = vector-pointer inbounds ir<%arrayidx>
@@ -170,7 +170,7 @@ define float @print_fmuladd_strict(ptr %a, ptr %b, i64 %n) {
; CHECK-NEXT: <x1> vector loop: {
; CHECK-NEXT: vector.body:
; CHECK-NEXT: EMIT vp<[[VP4:%[0-9]+]]> = CANONICAL-INDUCTION ir<0>, vp<%index.next>
-; CHECK-NEXT: WIDEN-REDUCTION-PHI ir<%sum.07> = phi vp<[[VP3]]>, ir<%muladd>
+; CHECK-NEXT: WIDEN-REDUCTION-PHI ir<%sum.07> = phi nnan ninf nsz vp<[[VP3]]>, ir<%muladd>
; CHECK-NEXT: vp<[[VP5:%[0-9]+]]> = SCALAR-STEPS vp<[[VP4]]>, ir<1>, vp<[[VP0]]>
; CHECK-NEXT: CLONE ir<%arrayidx> = getelementptr inbounds ir<%a>, vp<[[VP5]]>
; CHECK-NEXT: vp<[[VP6:%[0-9]+]]> = vector-pointer inbounds ir<%arrayidx>
>From feef96a94e5858764729cc9e60f458b550e8993a Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Tue, 17 Feb 2026 23:27:20 +0800
Subject: [PATCH 3/5] Return empty FMFs if OpType == Other in
VPIRFlags::getFastMathFlags
---
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 8 ++------
llvm/lib/Transforms/Vectorize/VPlan.h | 6 +++---
llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp | 13 ++++++-------
3 files changed, 11 insertions(+), 16 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 003945697c921..1948e18d8398b 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8528,10 +8528,8 @@ void LoopVectorizationPlanner::addReductionResultComputation(
Builder.createNaryOp(VPInstruction::ComputeAnyOfResult,
{Start, NewVal, NewExitingVPV}, ExitDL);
} else {
- FastMathFlags FMFs =
- PhiR->hasFastMathFlags() ? PhiR->getFastMathFlags() : FastMathFlags();
VPIRFlags Flags(RecurrenceKind, PhiR->isOrdered(), PhiR->isInLoop(),
- FMFs);
+ PhiR->getFastMathFlags());
FinalReductionResult =
Builder.createNaryOp(VPInstruction::ComputeReductionResult,
{NewExitingVPV}, Flags, ExitDL);
@@ -8624,9 +8622,7 @@ void LoopVectorizationPlanner::addReductionResultComputation(
!RecurrenceDescriptor::isFindLastRecurrenceKind(RK))) {
VPBuilder PHBuilder(Plan->getVectorPreheader());
VPValue *Iden = Plan->getOrAddLiveIn(getRecurrenceIdentity(
- RK, PhiTy,
- PhiR->hasFastMathFlags() ? PhiR->getFastMathFlags()
- : FastMathFlags()));
+ RK, PhiTy, PhiR->getFastMathFlags()));
auto *ScaleFactorVPV = Plan->getConstantInt(32, 1);
VPValue *StartV = PHBuilder.createNaryOp(
VPInstruction::ReductionStartVector,
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index b126d11496597..2c10a493ad9fa 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -3999,9 +3999,9 @@ class LLVM_ABI_FOR_TEST VPScalarIVStepsRecipe : public VPRecipeWithIRFlags {
~VPScalarIVStepsRecipe() override = default;
VPScalarIVStepsRecipe *clone() override {
- return new VPScalarIVStepsRecipe(
- getOperand(0), getOperand(1), getOperand(2), InductionOpcode,
- hasFastMathFlags() ? getFastMathFlags() : FastMathFlags(),
+ return new VPScalarIVStepsRecipe(getOperand(0), getOperand(1),
+ getOperand(2), InductionOpcode,
+ getFastMathFlags(),
getDebugLoc());
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index dcbb3a18b6d74..7fe644811f89d 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -367,8 +367,11 @@ void VPIRFlags::intersectFlags(const VPIRFlags &Other) {
FastMathFlags VPIRFlags::getFastMathFlags() const {
assert((OpType == OperationType::FPMathOp || OpType == OperationType::FCmp ||
- OpType == OperationType::ReductionOp) &&
+ OpType == OperationType::ReductionOp ||
+ OpType == OperationType::Other) &&
"recipe doesn't have fast math flags");
+ if (OpType == OperationType::Other)
+ return FastMathFlags();
const FastMathFlagsTy &F = getFMFsRef();
FastMathFlags Res;
Res.setAllowReassoc(F.AllowReassoc);
@@ -584,9 +587,7 @@ Value *VPInstruction::generate(VPTransformState &State) {
OnlyFirstLaneUsed || vputils::isSingleScalar(getOperand(0)));
Value *Op1 = State.get(getOperand(1), OnlyFirstLaneUsed);
Value *Op2 = State.get(getOperand(2), OnlyFirstLaneUsed);
- FastMathFlags FMFs =
- hasFastMathFlags() ? getFastMathFlags() : FastMathFlags();
- return Builder.CreateSelectFMF(Cond, Op1, Op2, FMFs, Name);
+ return Builder.CreateSelectFMF(Cond, Op1, Op2, getFastMathFlags(), Name);
}
case VPInstruction::ActiveLaneMask: {
// Get first lane of vector induction variable.
@@ -1948,10 +1949,8 @@ static InstructionCost getCostForIntrinsics(Intrinsic::ID ID,
}
// TODO: Rework TTI interface to avoid reliance on underlying IntrinsicInst.
- FastMathFlags FMF =
- R.hasFastMathFlags() ? R.getFastMathFlags() : FastMathFlags();
IntrinsicCostAttributes CostAttrs(
- ID, RetTy, Arguments, ParamTys, FMF,
+ ID, RetTy, Arguments, ParamTys, R.getFastMathFlags(),
dyn_cast_or_null<IntrinsicInst>(R.getUnderlyingValue()),
InstructionCost::getInvalid(), &Ctx.TLI);
return Ctx.TTI.getIntrinsicInstrCost(CostAttrs, Ctx.CostKind);
>From 14f9c12b8581f44e1e4cbe22851a6295822f3c83 Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Wed, 18 Feb 2026 00:01:40 +0800
Subject: [PATCH 4/5] clang-format
---
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 4 ++--
llvm/lib/Transforms/Vectorize/VPlan.h | 3 +--
llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp | 2 +-
3 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 1948e18d8398b..a152001a17c95 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8621,8 +8621,8 @@ void LoopVectorizationPlanner::addReductionResultComputation(
!RecurrenceDescriptor::isMinMaxRecurrenceKind(RK) &&
!RecurrenceDescriptor::isFindLastRecurrenceKind(RK))) {
VPBuilder PHBuilder(Plan->getVectorPreheader());
- VPValue *Iden = Plan->getOrAddLiveIn(getRecurrenceIdentity(
- RK, PhiTy, PhiR->getFastMathFlags()));
+ VPValue *Iden = Plan->getOrAddLiveIn(
+ getRecurrenceIdentity(RK, PhiTy, PhiR->getFastMathFlags()));
auto *ScaleFactorVPV = Plan->getConstantInt(32, 1);
VPValue *StartV = PHBuilder.createNaryOp(
VPInstruction::ReductionStartVector,
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 2c10a493ad9fa..93a2f47fb0c07 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -4001,8 +4001,7 @@ class LLVM_ABI_FOR_TEST VPScalarIVStepsRecipe : public VPRecipeWithIRFlags {
VPScalarIVStepsRecipe *clone() override {
return new VPScalarIVStepsRecipe(getOperand(0), getOperand(1),
getOperand(2), InductionOpcode,
- getFastMathFlags(),
- getDebugLoc());
+ getFastMathFlags(), getDebugLoc());
}
VP_CLASSOF_IMPL(VPRecipeBase::VPScalarIVStepsSC)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 7fe644811f89d..d0611ad8d9f2f 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -1950,7 +1950,7 @@ static InstructionCost getCostForIntrinsics(Intrinsic::ID ID,
// TODO: Rework TTI interface to avoid reliance on underlying IntrinsicInst.
IntrinsicCostAttributes CostAttrs(
- ID, RetTy, Arguments, ParamTys, R.getFastMathFlags(),
+ ID, RetTy, Arguments, ParamTys, R.getFastMathFlags(),
dyn_cast_or_null<IntrinsicInst>(R.getUnderlyingValue()),
InstructionCost::getInvalid(), &Ctx.TLI);
return Ctx.TTI.getIntrinsicInstrCost(CostAttrs, Ctx.CostKind);
>From 10ee7ff241d51a4cecf6f130f01cb2c75aa4fc37 Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Thu, 19 Feb 2026 18:55:31 +0800
Subject: [PATCH 5/5] Remove some hasFastMathFlags() checks
---
llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index d0611ad8d9f2f..2e0a416ea8719 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -715,8 +715,7 @@ Value *VPInstruction::generate(VPTransformState &State) {
if (State.VF.isScalar())
return State.get(getOperand(0), true);
IRBuilderBase::FastMathFlagGuard FMFG(Builder);
- if (hasFastMathFlags())
- Builder.setFastMathFlags(getFastMathFlags());
+ Builder.setFastMathFlags(getFastMathFlags());
// If this start vector is scaled then it should produce a vector with fewer
// elements than the VF.
ElementCount VF = State.VF.divideCoefficientBy(
@@ -755,8 +754,7 @@ Value *VPInstruction::generate(VPTransformState &State) {
RdxParts[Part] = State.get(getOperand(Part), IsInLoop);
IRBuilderBase::FastMathFlagGuard FMFG(Builder);
- if (hasFastMathFlags())
- Builder.setFastMathFlags(getFastMathFlags());
+ Builder.setFastMathFlags(getFastMathFlags());
// Reduce multiple operands into one.
Value *ReducedPartRdx = RdxParts[0];
@@ -2542,8 +2540,7 @@ void VPDerivedIVRecipe::printRecipe(raw_ostream &O, const Twine &Indent,
void VPScalarIVStepsRecipe::execute(VPTransformState &State) {
// Fast-math-flags propagate from the original induction instruction.
IRBuilder<>::FastMathFlagGuard FMFG(State.Builder);
- if (hasFastMathFlags())
- State.Builder.setFastMathFlags(getFastMathFlags());
+ State.Builder.setFastMathFlags(getFastMathFlags());
/// Compute scalar induction steps. \p ScalarIV is the scalar induction
/// variable on which to base the steps, \p Step is the size of the step.
More information about the llvm-commits
mailing list