[llvm] f23246a - [LV] Directly add fast-math flags to select recipe (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 21 03:06:45 PDT 2023
Author: Florian Hahn
Date: 2023-09-21T11:05:55+01:00
New Revision: f23246a0bb403c2a6f206f6e190496f45fad4ef9
URL: https://github.com/llvm/llvm-project/commit/f23246a0bb403c2a6f206f6e190496f45fad4ef9
DIFF: https://github.com/llvm/llvm-project/commit/f23246a0bb403c2a6f206f6e190496f45fad4ef9.diff
LOG: [LV] Directly add fast-math flags to select recipe (NFC).
Now that VPInstruction can manage fast math flags via
VPRecipeWithIRFlags, use them directly to model the fast-math flags of
the select created for the final reduction value instead of adding them
late.
Added:
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 34936b9b7b6fc26..8da5692f1ee89c2 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -3832,9 +3832,6 @@ void InnerLoopVectorizer::fixReduction(VPReductionPHIRecipe *PhiR,
assert(Sel && "Reduction exit feeds no select");
State.reset(LoopExitInstDef, Sel, Part);
- if (isa<FPMathOperator>(Sel))
- Sel->setFastMathFlags(RdxDesc.getFastMathFlags());
-
// If the target can create a predicated operator for the reduction at no
// extra cost in the loop (for example a predicated vadd), it can be
// cheaper for the select to remain in the loop than be sunk out of it,
@@ -9162,12 +9159,19 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
VPReductionPHIRecipe *PhiR = dyn_cast<VPReductionPHIRecipe>(&R);
if (!PhiR || PhiR->isInLoop())
continue;
+ const RecurrenceDescriptor &RdxDesc = PhiR->getRecurrenceDescriptor();
VPValue *Cond =
RecipeBuilder.createBlockInMask(OrigLoop->getHeader(), *Plan);
VPValue *Red = PhiR->getBackedgeValue();
assert(Red->getDefiningRecipe()->getParent() != LatchVPBB &&
"reduction recipe must be defined before latch");
- Builder.createNaryOp(Instruction::Select, {Cond, Red, PhiR});
+ FastMathFlags FMFs = RdxDesc.getFastMathFlags();
+ Type *PhiTy = PhiR->getOperand(0)->getLiveInIRValue()->getType();
+ auto *Select =
+ PhiTy->isFloatingPointTy()
+ ? new VPInstruction(Instruction::Select, {Cond, Red, PhiR}, FMFs)
+ : new VPInstruction(Instruction::Select, {Cond, Red, PhiR});
+ Select->insertBefore(&*Builder.getInsertPoint());
}
}
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index ee66735df2708ec..d507f436feb8153 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -415,14 +415,15 @@ bool VPInstruction::isFPMathOp() const {
return Opcode == Instruction::FAdd || Opcode == Instruction::FMul ||
Opcode == Instruction::FNeg || Opcode == Instruction::FSub ||
Opcode == Instruction::FDiv || Opcode == Instruction::FRem ||
- Opcode == Instruction::FCmp;
+ Opcode == Instruction::FCmp || Opcode == Instruction::Select;
}
#endif
void VPInstruction::execute(VPTransformState &State) {
assert(!State.Instance && "VPInstruction executing an Instance");
IRBuilderBase::FastMathFlagGuard FMFGuard(State.Builder);
- assert(hasFastMathFlags() == isFPMathOp() &&
+ assert((hasFastMathFlags() == isFPMathOp() ||
+ getOpcode() == Instruction::Select) &&
"Recipe not a FPMathOp but has fast-math flags?");
if (hasFastMathFlags())
State.Builder.setFastMathFlags(getFastMathFlags());
More information about the llvm-commits
mailing list