Skip to content

Commit 3e2d564

Browse files
committed
[VPlan] Use VPRecipeWithFlags for VPScalarIVStepsRecipe (NFC).
This directly models the flags as part of the recipe, which allows dropping them using the VPlan infrastructure when required. It also allows removing the full reference to InductionDescriptor and limit it to only the opcode.
1 parent bd6e77c commit 3e2d564

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,14 +2204,23 @@ class VPDerivedIVRecipe : public VPRecipeBase, public VPValue {
22042204

22052205
/// A recipe for handling phi nodes of integer and floating-point inductions,
22062206
/// producing their scalar values.
2207-
class VPScalarIVStepsRecipe : public VPRecipeBase, public VPValue {
2208-
const InductionDescriptor &IndDesc;
2207+
class VPScalarIVStepsRecipe : public VPRecipeWithIRFlags, public VPValue {
2208+
Instruction::BinaryOps InductionOpcode;
22092209

22102210
public:
2211+
VPScalarIVStepsRecipe(VPValue *IV, VPValue *Step,
2212+
Instruction::BinaryOps Opcode, FastMathFlags FMFs)
2213+
: VPRecipeWithIRFlags(VPDef::VPScalarIVStepsSC,
2214+
ArrayRef<VPValue *>({IV, Step}), FMFs),
2215+
VPValue(this), InductionOpcode(Opcode) {}
2216+
22112217
VPScalarIVStepsRecipe(const InductionDescriptor &IndDesc, VPValue *IV,
22122218
VPValue *Step)
2213-
: VPRecipeBase(VPDef::VPScalarIVStepsSC, {IV, Step}), VPValue(this),
2214-
IndDesc(IndDesc) {}
2219+
: VPScalarIVStepsRecipe(
2220+
IV, Step, IndDesc.getInductionOpcode(),
2221+
dyn_cast_or_null<FPMathOperator>(IndDesc.getInductionBinOp())
2222+
? IndDesc.getInductionBinOp()->getFastMathFlags()
2223+
: FastMathFlags()) {}
22152224

22162225
~VPScalarIVStepsRecipe() override = default;
22172226

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -992,10 +992,8 @@ void VPDerivedIVRecipe::print(raw_ostream &O, const Twine &Indent,
992992
void VPScalarIVStepsRecipe::execute(VPTransformState &State) {
993993
// Fast-math-flags propagate from the original induction instruction.
994994
IRBuilder<>::FastMathFlagGuard FMFG(State.Builder);
995-
if (IndDesc.getInductionBinOp() &&
996-
isa<FPMathOperator>(IndDesc.getInductionBinOp()))
997-
State.Builder.setFastMathFlags(
998-
IndDesc.getInductionBinOp()->getFastMathFlags());
995+
if (hasFastMathFlags())
996+
State.Builder.setFastMathFlags(getFastMathFlags());
999997

1000998
/// Compute scalar induction steps. \p ScalarIV is the scalar induction
1001999
/// variable on which to base the steps, \p Step is the size of the step.
@@ -1022,7 +1020,7 @@ void VPScalarIVStepsRecipe::execute(VPTransformState &State) {
10221020
AddOp = Instruction::Add;
10231021
MulOp = Instruction::Mul;
10241022
} else {
1025-
AddOp = IndDesc.getInductionOpcode();
1023+
AddOp = InductionOpcode;
10261024
MulOp = Instruction::FMul;
10271025
}
10281026

0 commit comments

Comments
 (0)