Skip to content

Commit 62c8979

Browse files
committed
Add isConditional for VPreductionRecipe.
1 parent bdafefa commit 62c8979

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,14 +2115,18 @@ class VPReductionRecipe : public VPSingleDefRecipe {
21152115
/// The recurrence decriptor for the reduction in question.
21162116
const RecurrenceDescriptor &RdxDesc;
21172117
bool IsOrdered;
2118+
/// Whether the reduction is conditional.
2119+
bool IsConditional = false;
21182120

21192121
protected:
21202122
VPReductionRecipe(const unsigned char SC, const RecurrenceDescriptor &R,
21212123
Instruction *I, ArrayRef<VPValue *> Operands,
21222124
VPValue *CondOp, bool IsOrdered)
21232125
: VPSingleDefRecipe(SC, Operands, I), RdxDesc(R), IsOrdered(IsOrdered) {
2124-
if (CondOp)
2126+
if (CondOp) {
2127+
IsConditional = true;
21252128
addOperand(CondOp);
2129+
}
21262130
}
21272131

21282132
public:
@@ -2165,13 +2169,15 @@ class VPReductionRecipe : public VPSingleDefRecipe {
21652169
}
21662170
/// Return true if the in-loop reduction is ordered.
21672171
bool isOrdered() const { return IsOrdered; };
2172+
/// Return true if the in-loop reduction is conditional.
2173+
bool isConditional() const { return IsConditional; };
21682174
/// The VPValue of the scalar Chain being accumulated.
21692175
VPValue *getChainOp() const { return getOperand(0); }
21702176
/// The VPValue of the vector value to be reduced.
21712177
VPValue *getVecOp() const { return getOperand(1); }
21722178
/// The VPValue of the condition for the block.
2173-
virtual VPValue *getCondOp() const {
2174-
return getNumOperands() > 2 ? getOperand(2) : nullptr;
2179+
VPValue *getCondOp() const {
2180+
return isConditional() ? getOperand(getNumOperands() - 1) : nullptr;
21752181
}
21762182
};
21772183

@@ -2207,10 +2213,6 @@ class VPReductionEVLRecipe : public VPReductionRecipe {
22072213

22082214
/// The VPValue of the explicit vector length.
22092215
VPValue *getEVL() const { return getOperand(2); }
2210-
/// The VPValue of the condition for the block.
2211-
VPValue *getCondOp() const override {
2212-
return getNumOperands() > 3 ? getOperand(3) : nullptr;
2213-
}
22142216

22152217
/// Returns true if the recipe only uses the first lane of operand \p Op.
22162218
bool onlyFirstLaneUsed(const VPValue *Op) const override {

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,7 @@ void VPReductionRecipe::print(raw_ostream &O, const Twine &Indent,
17131713
O << getUnderlyingInstr()->getFastMathFlags();
17141714
O << " reduce." << Instruction::getOpcodeName(RdxDesc.getOpcode()) << " (";
17151715
getVecOp()->printAsOperand(O, SlotTracker);
1716-
if (getCondOp()) {
1716+
if (isConditional()) {
17171717
O << ", ";
17181718
getCondOp()->printAsOperand(O, SlotTracker);
17191719
}
@@ -1737,7 +1737,7 @@ void VPReductionEVLRecipe::print(raw_ostream &O, const Twine &Indent,
17371737
getVecOp()->printAsOperand(O, SlotTracker);
17381738
O << ", ";
17391739
getEVL()->printAsOperand(O, SlotTracker);
1740-
if (getCondOp()) {
1740+
if (isConditional()) {
17411741
O << ", ";
17421742
getCondOp()->printAsOperand(O, SlotTracker);
17431743
}

0 commit comments

Comments
 (0)