Skip to content

Commit 0473b05

Browse files
committed
!fixup, Set FMF for VPReductionRecipe in ctor directly.
1 parent 36b40fc commit 0473b05

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
@@ -9799,9 +9799,9 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
97999799
if (CM.blockNeedsPredicationForAnyReason(BB))
98009800
CondOp = RecipeBuilder.getBlockInMask(BB);
98019801

9802-
auto *RedRecipe =
9803-
new VPReductionRecipe(RdxDesc, CurrentLinkI, PreviousLink, VecOp,
9804-
CondOp, CM.useOrderedReductions(RdxDesc));
9802+
auto *RedRecipe = new VPReductionRecipe(
9803+
RdxDesc, CurrentLinkI, PreviousLink, VecOp, CondOp,
9804+
CM.useOrderedReductions(RdxDesc), CurrentLinkI->getDebugLoc());
98059805
// Append the recipe to the end of the VPBasicBlock because we need to
98069806
// ensure that it comes after all of it's inputs, including CondOp.
98079807
// 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
@@ -790,13 +790,6 @@ class VPRecipeWithIRFlags : public VPSingleDefRecipe {
790790
}
791791
}
792792

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

23052298
protected:
23062299
VPReductionRecipe(const unsigned char SC, const RecurrenceDescriptor &R,
2307-
Instruction *I, ArrayRef<VPValue *> Operands,
2308-
VPValue *CondOp, bool IsOrdered)
2309-
: VPRecipeWithIRFlags(SC, Operands, *I), RdxDesc(R),
2300+
FastMathFlags FMF, Instruction *I,
2301+
ArrayRef<VPValue *> Operands, VPValue *CondOp,
2302+
bool IsOrdered, DebugLoc DL)
2303+
: VPRecipeWithIRFlags(SC, Operands, FMF, DL), RdxDesc(R),
23102304
IsOrdered(IsOrdered) {
23112305
if (CondOp) {
23122306
IsConditional = true;
23132307
addOperand(CondOp);
23142308
}
2315-
2316-
// In-loop reductions may comprise of multiple scalar instructions, and the
2317-
// underlying instruction may not contain the same flags as the
2318-
// recurrence descriptor, so set the flags explicitly.
2319-
if (isa<FPMathOperator>(I))
2320-
setFastMathFlags(R.getFastMathFlags());
2309+
setUnderlyingValue(I);
23212310
}
23222311

23232312
public:
23242313
VPReductionRecipe(const RecurrenceDescriptor &R, Instruction *I,
23252314
VPValue *ChainOp, VPValue *VecOp, VPValue *CondOp,
2326-
bool IsOrdered)
2327-
: VPReductionRecipe(VPDef::VPReductionSC, R, I,
2315+
bool IsOrdered, DebugLoc DL = {})
2316+
: VPReductionRecipe(VPDef::VPReductionSC, R, R.getFastMathFlags(), I,
23282317
ArrayRef<VPValue *>({ChainOp, VecOp}), CondOp,
2329-
IsOrdered) {}
2318+
IsOrdered, DL) {}
23302319

23312320
~VPReductionRecipe() override = default;
23322321

23332322
VPReductionRecipe *clone() override {
23342323
return new VPReductionRecipe(RdxDesc, getUnderlyingInstr(), getChainOp(),
2335-
getVecOp(), getCondOp(), IsOrdered);
2324+
getVecOp(), getCondOp(), IsOrdered,
2325+
getDebugLoc());
23362326
}
23372327

23382328
static inline bool classof(const VPRecipeBase *R) {
@@ -2382,12 +2372,14 @@ class VPReductionRecipe : public VPRecipeWithIRFlags {
23822372
/// The Operands are {ChainOp, VecOp, EVL, [Condition]}.
23832373
class VPReductionEVLRecipe : public VPReductionRecipe {
23842374
public:
2385-
VPReductionEVLRecipe(VPReductionRecipe &R, VPValue &EVL, VPValue *CondOp)
2375+
VPReductionEVLRecipe(VPReductionRecipe &R, VPValue &EVL, VPValue *CondOp,
2376+
DebugLoc DL = {})
23862377
: VPReductionRecipe(
23872378
VPDef::VPReductionEVLSC, R.getRecurrenceDescriptor(),
2379+
R.getFastMathFlags(),
23882380
cast_or_null<Instruction>(R.getUnderlyingValue()),
23892381
ArrayRef<VPValue *>({R.getChainOp(), R.getVecOp(), &EVL}), CondOp,
2390-
R.isOrdered()) {}
2382+
R.isOrdered(), DL) {}
23912383

23922384
~VPReductionEVLRecipe() override = default;
23932385

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)