Skip to content

Commit

Permalink
Add isConditional for VPreductionRecipe.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mel-Chen committed Jul 8, 2024
1 parent bdafefa commit 62c8979
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions llvm/lib/Transforms/Vectorize/VPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -2115,14 +2115,18 @@ class VPReductionRecipe : public VPSingleDefRecipe {
/// The recurrence decriptor for the reduction in question.
const RecurrenceDescriptor &RdxDesc;
bool IsOrdered;
/// Whether the reduction is conditional.
bool IsConditional = false;

protected:
VPReductionRecipe(const unsigned char SC, const RecurrenceDescriptor &R,
Instruction *I, ArrayRef<VPValue *> Operands,
VPValue *CondOp, bool IsOrdered)
: VPSingleDefRecipe(SC, Operands, I), RdxDesc(R), IsOrdered(IsOrdered) {
if (CondOp)
if (CondOp) {
IsConditional = true;
addOperand(CondOp);
}
}

public:
Expand Down Expand Up @@ -2165,13 +2169,15 @@ class VPReductionRecipe : public VPSingleDefRecipe {
}
/// Return true if the in-loop reduction is ordered.
bool isOrdered() const { return IsOrdered; };
/// Return true if the in-loop reduction is conditional.
bool isConditional() const { return IsConditional; };
/// The VPValue of the scalar Chain being accumulated.
VPValue *getChainOp() const { return getOperand(0); }
/// The VPValue of the vector value to be reduced.
VPValue *getVecOp() const { return getOperand(1); }
/// The VPValue of the condition for the block.
virtual VPValue *getCondOp() const {
return getNumOperands() > 2 ? getOperand(2) : nullptr;
VPValue *getCondOp() const {
return isConditional() ? getOperand(getNumOperands() - 1) : nullptr;
}
};

Expand Down Expand Up @@ -2207,10 +2213,6 @@ class VPReductionEVLRecipe : public VPReductionRecipe {

/// The VPValue of the explicit vector length.
VPValue *getEVL() const { return getOperand(2); }
/// The VPValue of the condition for the block.
VPValue *getCondOp() const override {
return getNumOperands() > 3 ? getOperand(3) : nullptr;
}

/// Returns true if the recipe only uses the first lane of operand \p Op.
bool onlyFirstLaneUsed(const VPValue *Op) const override {
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,7 @@ void VPReductionRecipe::print(raw_ostream &O, const Twine &Indent,
O << getUnderlyingInstr()->getFastMathFlags();
O << " reduce." << Instruction::getOpcodeName(RdxDesc.getOpcode()) << " (";
getVecOp()->printAsOperand(O, SlotTracker);
if (getCondOp()) {
if (isConditional()) {
O << ", ";
getCondOp()->printAsOperand(O, SlotTracker);
}
Expand All @@ -1737,7 +1737,7 @@ void VPReductionEVLRecipe::print(raw_ostream &O, const Twine &Indent,
getVecOp()->printAsOperand(O, SlotTracker);
O << ", ";
getEVL()->printAsOperand(O, SlotTracker);
if (getCondOp()) {
if (isConditional()) {
O << ", ";
getCondOp()->printAsOperand(O, SlotTracker);
}
Expand Down

0 comments on commit 62c8979

Please sign in to comment.