Skip to content

Commit 35bf9d0

Browse files
committed
Add isConditional for VPreductionRecipe.
1 parent 20f6383 commit 35bf9d0

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
@@ -2172,14 +2172,18 @@ class VPReductionRecipe : public VPSingleDefRecipe {
21722172
/// The recurrence decriptor for the reduction in question.
21732173
const RecurrenceDescriptor &RdxDesc;
21742174
bool IsOrdered;
2175+
/// Whether the reduction is conditional.
2176+
bool IsConditional = false;
21752177

21762178
protected:
21772179
VPReductionRecipe(const unsigned char SC, const RecurrenceDescriptor &R,
21782180
Instruction *I, ArrayRef<VPValue *> Operands,
21792181
VPValue *CondOp, bool IsOrdered)
21802182
: VPSingleDefRecipe(SC, Operands, I), RdxDesc(R), IsOrdered(IsOrdered) {
2181-
if (CondOp)
2183+
if (CondOp) {
2184+
IsConditional = true;
21822185
addOperand(CondOp);
2186+
}
21832187
}
21842188

21852189
public:
@@ -2222,13 +2226,15 @@ class VPReductionRecipe : public VPSingleDefRecipe {
22222226
}
22232227
/// Return true if the in-loop reduction is ordered.
22242228
bool isOrdered() const { return IsOrdered; };
2229+
/// Return true if the in-loop reduction is conditional.
2230+
bool isConditional() const { return IsConditional; };
22252231
/// The VPValue of the scalar Chain being accumulated.
22262232
VPValue *getChainOp() const { return getOperand(0); }
22272233
/// The VPValue of the vector value to be reduced.
22282234
VPValue *getVecOp() const { return getOperand(1); }
22292235
/// The VPValue of the condition for the block.
2230-
virtual VPValue *getCondOp() const {
2231-
return getNumOperands() > 2 ? getOperand(2) : nullptr;
2236+
VPValue *getCondOp() const {
2237+
return isConditional() ? getOperand(getNumOperands() - 1) : nullptr;
22322238
}
22332239
};
22342240

@@ -2264,10 +2270,6 @@ class VPReductionEVLRecipe : public VPReductionRecipe {
22642270

22652271
/// The VPValue of the explicit vector length.
22662272
VPValue *getEVL() const { return getOperand(2); }
2267-
/// The VPValue of the condition for the block.
2268-
VPValue *getCondOp() const override {
2269-
return getNumOperands() > 3 ? getOperand(3) : nullptr;
2270-
}
22712273

22722274
/// Returns true if the recipe only uses the first lane of operand \p Op.
22732275
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
@@ -1799,7 +1799,7 @@ void VPReductionRecipe::print(raw_ostream &O, const Twine &Indent,
17991799
O << getUnderlyingInstr()->getFastMathFlags();
18001800
O << " reduce." << Instruction::getOpcodeName(RdxDesc.getOpcode()) << " (";
18011801
getVecOp()->printAsOperand(O, SlotTracker);
1802-
if (getCondOp()) {
1802+
if (isConditional()) {
18031803
O << ", ";
18041804
getCondOp()->printAsOperand(O, SlotTracker);
18051805
}
@@ -1823,7 +1823,7 @@ void VPReductionEVLRecipe::print(raw_ostream &O, const Twine &Indent,
18231823
getVecOp()->printAsOperand(O, SlotTracker);
18241824
O << ", ";
18251825
getEVL()->printAsOperand(O, SlotTracker);
1826-
if (getCondOp()) {
1826+
if (isConditional()) {
18271827
O << ", ";
18281828
getCondOp()->printAsOperand(O, SlotTracker);
18291829
}

0 commit comments

Comments
 (0)