Skip to content

Commit 44e1e63

Browse files
ElvisWang123lukel97
authored andcommitted
!fixup, Set FMF for VPReductionRecipe in ctor directly.
1 parent 281514a commit 44e1e63

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9797,9 +9797,9 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
97979797
if (CM.blockNeedsPredicationForAnyReason(BB))
97989798
CondOp = RecipeBuilder.getBlockInMask(BB);
97999799

9800-
auto *RedRecipe =
9801-
new VPReductionRecipe(RdxDesc, CurrentLinkI, PreviousLink, VecOp,
9802-
CondOp, CM.useOrderedReductions(RdxDesc));
9800+
auto *RedRecipe = new VPReductionRecipe(
9801+
RdxDesc, CurrentLinkI, PreviousLink, VecOp, CondOp,
9802+
CM.useOrderedReductions(RdxDesc), CurrentLinkI->getDebugLoc());
98039803
// Append the recipe to the end of the VPBasicBlock because we need to
98049804
// ensure that it comes after all of it's inputs, including CondOp.
98059805
// Delete CurrentLink as it will be invalid if its operand is replaced

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -788,13 +788,6 @@ class VPRecipeWithIRFlags : public VPSingleDefRecipe {
788788
}
789789
}
790790

791-
/// Set fast-math flags for this recipe.
792-
void setFastMathFlags(FastMathFlags FMFs) {
793-
assert(OpType == OperationType::FPMathOp &&
794-
"We should only set the FastMathFlags when the recipes is FPFathOP");
795-
this->FMFs = FMFs;
796-
}
797-
798791
CmpInst::Predicate getPredicate() const {
799792
assert(OpType == OperationType::Cmp &&
800793
"recipe doesn't have a compare predicate");
@@ -2254,35 +2247,32 @@ class VPReductionRecipe : public VPRecipeWithIRFlags {
22542247

22552248
protected:
22562249
VPReductionRecipe(const unsigned char SC, const RecurrenceDescriptor &R,
2257-
Instruction *I, ArrayRef<VPValue *> Operands,
2258-
VPValue *CondOp, bool IsOrdered)
2259-
: VPRecipeWithIRFlags(SC, Operands, *I), RdxDesc(R),
2250+
FastMathFlags FMF, Instruction *I,
2251+
ArrayRef<VPValue *> Operands, VPValue *CondOp,
2252+
bool IsOrdered, DebugLoc DL)
2253+
: VPRecipeWithIRFlags(SC, Operands, FMF, DL), RdxDesc(R),
22602254
IsOrdered(IsOrdered) {
22612255
if (CondOp) {
22622256
IsConditional = true;
22632257
addOperand(CondOp);
22642258
}
2265-
2266-
// In-loop reductions may comprise of multiple scalar instructions, and the
2267-
// underlying instruction may not contain the same flags as the
2268-
// recurrence descriptor, so set the flags explicitly.
2269-
if (isa<FPMathOperator>(I))
2270-
setFastMathFlags(R.getFastMathFlags());
2259+
setUnderlyingValue(I);
22712260
}
22722261

22732262
public:
22742263
VPReductionRecipe(const RecurrenceDescriptor &R, Instruction *I,
22752264
VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp,
2276-
bool IsOrdered)
2277-
: VPReductionRecipe(VPDef::VPReductionSC, R, I,
2265+
bool IsOrdered, DebugLoc DL = {})
2266+
: VPReductionRecipe(VPDef::VPReductionSC, R, R.getFastMathFlags(), I,
22782267
ArrayRef<VPValue *>({ChainOp, VecOp}), CondOp,
2279-
IsOrdered) {}
2268+
IsOrdered, DL) {}
22802269

22812270
~VPReductionRecipe() override = default;
22822271

22832272
VPReductionRecipe *clone() override {
22842273
return new VPReductionRecipe(RdxDesc, getUnderlyingInstr(), getChainOp(),
2285-
getVecOp(), getCondOp(), IsOrdered);
2274+
getVecOp(), getCondOp(), IsOrdered,
2275+
getDebugLoc());
22862276
}
22872277

22882278
static inline bool classof(const VPRecipeBase *R) {
@@ -2332,12 +2322,14 @@ class VPReductionRecipe : public VPRecipeWithIRFlags {
23322322
/// The Operands are {ChainOp, VecOp, EVL, [Condition]}.
23332323
class VPReductionEVLRecipe : public VPReductionRecipe {
23342324
public:
2335-
VPReductionEVLRecipe(VPReductionRecipe &R, VPValue &EVL, VPValue *CondOp)
2325+
VPReductionEVLRecipe(VPReductionRecipe &R, VPValue &EVL, VPValue *CondOp,
2326+
DebugLoc DL = {})
23362327
: VPReductionRecipe(
23372328
VPDef::VPReductionEVLSC, R.getRecurrenceDescriptor(),
2329+
R.getFastMathFlags(),
23382330
cast_or_null<Instruction>(R.getUnderlyingValue()),
23392331
ArrayRef<VPValue *>({R.getChainOp(), R.getVecOp(), &EVL}), CondOp,
2340-
R.isOrdered()) {}
2332+
R.isOrdered(), DL) {}
23412333

23422334
~VPReductionEVLRecipe() override = default;
23432335

llvm/test/Transforms/LoopVectorize/RISCV/vplan-vp-intrinsics-reduction.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ define i32 @reduction(ptr %a, i64 %n, i32 %start) {
101101
; IF-EVL-INLOOP-NEXT: CLONE ir<[[GEP1:%.+]]> = getelementptr inbounds ir<%a>, vp<[[ST]]>
102102
; IF-EVL-INLOOP-NEXT: vp<[[PTR1:%[0-9]+]]> = vector-pointer ir<[[GEP1]]>
103103
; IF-EVL-INLOOP-NEXT: WIDEN ir<[[LD1:%.+]]> = vp.load vp<[[PTR1]]>, vp<[[EVL]]>
104-
; IF-EVL-INLOOP-NEXT: REDUCE ir<[[ADD:%.+]]> = ir<[[RDX_PHI]]> + nsw vp.reduce.add (ir<[[LD1]]>, vp<[[EVL]]>)
104+
; IF-EVL-INLOOP-NEXT: REDUCE ir<[[ADD:%.+]]> = ir<[[RDX_PHI]]> + reassoc nsz arcp contract afn vp.reduce.add (ir<[[LD1]]>, vp<[[EVL]]>)
105105
; IF-EVL-INLOOP-NEXT: SCALAR-CAST vp<[[CAST:%[0-9]+]]> = zext vp<[[EVL]]> to i64
106106
; IF-EVL-INLOOP-NEXT: EMIT vp<[[IV_NEXT]]> = add vp<[[CAST]]>, vp<[[EVL_PHI]]>
107107
; IF-EVL-INLOOP-NEXT: EMIT vp<[[IV_NEXT_EXIT:%.+]]> = add vp<[[IV]]>, vp<[[VFUF]]>
@@ -196,7 +196,7 @@ define i32 @reduction(ptr %a, i64 %n, i32 %start) {
196196
; NO-VP-INLOOP-NEXT: CLONE ir<[[GEP1:%.+]]> = getelementptr inbounds ir<%a>, vp<[[ST]]>
197197
; NO-VP-INLOOP-NEXT: vp<[[PTR1:%[0-9]+]]> = vector-pointer ir<[[GEP1]]>
198198
; NO-VP-INLOOP-NEXT: WIDEN ir<[[LD1:%.+]]> = load vp<[[PTR1]]>
199-
; NO-VP-INLOOP-NEXT: REDUCE ir<[[ADD:%.+]]> = ir<[[RDX_PHI]]> + reduce.add (ir<[[LD1]]>)
199+
; NO-VP-INLOOP-NEXT: REDUCE ir<[[ADD:%.+]]> = ir<[[RDX_PHI]]> + reassoc nsz arcp contract afn reduce.add (ir<[[LD1]]>)
200200
; NO-VP-INLOOP-NEXT: EMIT vp<[[IV_NEXT_EXIT:%.+]]> = add nuw vp<[[IV]]>, vp<[[VFUF]]>
201201
; NO-VP-INLOOP-NEXT: EMIT branch-on-count vp<[[IV_NEXT_EXIT]]>, vp<[[VTC]]>
202202
; NO-VP-INLOOP-NEXT: No successors

0 commit comments

Comments
 (0)