[llvm-branch-commits] [llvm] 65f578f - [VPlan] Keep start value of VPWidenPHIRecipe as VPValue.

Florian Hahn via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Jan 9 08:41:54 PST 2021


Author: Florian Hahn
Date: 2021-01-09T16:34:15Z
New Revision: 65f578fc0e6fb10bb84f3dea906f8fb1230c1ab3

URL: https://github.com/llvm/llvm-project/commit/65f578fc0e6fb10bb84f3dea906f8fb1230c1ab3
DIFF: https://github.com/llvm/llvm-project/commit/65f578fc0e6fb10bb84f3dea906f8fb1230c1ab3.diff

LOG: [VPlan] Keep start value of VPWidenPHIRecipe as VPValue.

Similar to D92129, update VPWidenPHIRecipe  to manage the start value as
VPValue. This allows adjusting the start value as a VPlan transform,
which will be used in a follow-up patch to support reductions during
epilogue vectorization.

Reviewed By: gilr

Differential Revision: https://reviews.llvm.org/D93975

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
    llvm/lib/Transforms/Vectorize/VPlan.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index fe86a52bef9a..180cbb8ef847 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8383,7 +8383,9 @@ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(Instruction *Instr,
 
     if (Legal->isReductionVariable(Phi)) {
       RecurrenceDescriptor &RdxDesc = Legal->getReductionVars()[Phi];
-      return new VPWidenPHIRecipe(Phi, RdxDesc);
+      VPValue *StartV =
+          Plan->getOrAddVPValue(RdxDesc.getRecurrenceStartValue());
+      return new VPWidenPHIRecipe(Phi, RdxDesc, *StartV);
     }
 
     return new VPWidenPHIRecipe(Phi);
@@ -8802,9 +8804,8 @@ void VPWidenIntOrFpInductionRecipe::execute(VPTransformState &State) {
 }
 
 void VPWidenPHIRecipe::execute(VPTransformState &State) {
-  Value *StartV = nullptr;
-  if (RdxDesc)
-    StartV = RdxDesc->getRecurrenceStartValue();
+  Value *StartV =
+      getStartValue() ? getStartValue()->getLiveInIRValue() : nullptr;
   State.ILV->widenPHIInstruction(Phi, RdxDesc, StartV, State.UF, State.VF);
 }
 

diff  --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 2f01dafaec3c..332bd9b79ab4 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -972,8 +972,8 @@ class VPWidenIntOrFpInductionRecipe : public VPRecipeBase, public VPUser {
 
 /// A recipe for handling all phi nodes except for integer and FP inductions.
 /// For reduction PHIs, RdxDesc must point to the corresponding recurrence
-/// descriptor.
-class VPWidenPHIRecipe : public VPRecipeBase {
+/// descriptor and the start value is the first operand of the recipe.
+class VPWidenPHIRecipe : public VPRecipeBase, public VPUser {
   PHINode *Phi;
 
   /// Descriptor for a reduction PHI.
@@ -982,9 +982,10 @@ class VPWidenPHIRecipe : public VPRecipeBase {
 public:
   /// Create a new VPWidenPHIRecipe for the reduction \p Phi described by \p
   /// RdxDesc.
-  VPWidenPHIRecipe(PHINode *Phi, RecurrenceDescriptor &RdxDesc)
+  VPWidenPHIRecipe(PHINode *Phi, RecurrenceDescriptor &RdxDesc, VPValue &Start)
       : VPWidenPHIRecipe(Phi) {
     this->RdxDesc = &RdxDesc;
+    addOperand(&Start);
   }
 
   /// Create a VPWidenPHIRecipe for \p Phi
@@ -1004,6 +1005,11 @@ class VPWidenPHIRecipe : public VPRecipeBase {
   /// Print the recipe.
   void print(raw_ostream &O, const Twine &Indent,
              VPSlotTracker &SlotTracker) const override;
+
+  /// Returns the start value of the phi, if it is a reduction.
+  VPValue *getStartValue() {
+    return getNumOperands() == 0 ? nullptr : getOperand(0);
+  }
 };
 
 /// A recipe for vectorizing a phi-node as a sequence of mask-based select


        


More information about the llvm-branch-commits mailing list