diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index 147ca5b4475b5..6bae45a8e739d 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -1851,6 +1851,9 @@ class VPWidenInductionRecipe : public VPHeaderPHIRecipe { class VPWidenIntOrFpInductionRecipe : public VPWidenInductionRecipe { TruncInst *Trunc; + // If this recipe is unrolled it will have 2 additional operands. + bool isUnrolled() const { return getNumOperands() == 5; } + public: VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step, VPValue *VF, const InductionDescriptor &IndDesc, @@ -1899,9 +1902,9 @@ class VPWidenIntOrFpInductionRecipe : public VPWidenInductionRecipe { const VPValue *getVFValue() const { return getOperand(2); } VPValue *getSplatVFValue() { - // If the recipe has been unrolled (4 operands), return the VPValue for the - // induction increment. - return getNumOperands() == 5 ? getOperand(3) : nullptr; + // If the recipe has been unrolled return the VPValue for the induction + // increment. + return isUnrolled() ? getOperand(getNumOperands() - 2) : nullptr; } /// Returns the first defined value as TruncInst, if it is one or nullptr @@ -1923,7 +1926,7 @@ class VPWidenIntOrFpInductionRecipe : public VPWidenInductionRecipe { /// the last unrolled part, if it exists. Returns itself if unrolling did not /// take place. VPValue *getLastUnrolledPartOperand() { - return getNumOperands() == 5 ? getOperand(4) : this; + return isUnrolled() ? getOperand(getNumOperands() - 1) : this; } };