diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index 18e250f8ebd1da..b72438c236d674 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -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 Operands, VPValue *CondOp, bool IsOrdered) : VPSingleDefRecipe(SC, Operands, I), RdxDesc(R), IsOrdered(IsOrdered) { - if (CondOp) + if (CondOp) { + IsConditional = true; addOperand(CondOp); + } } public: @@ -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; } }; @@ -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 { diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp index aa1291095c35f0..31b2f1fa52a53c 100644 --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -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); } @@ -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); }