[PATCH] D144125: [VPlan] Improve VPRecipeBase::isPhi checking

Michael Maitland via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 15 10:45:52 PST 2023


michaelmaitland created this revision.
michaelmaitland added reviewers: fhahn, nikolaypanchenko, reames.
Herald added subscribers: StephenFan, tschuett, psnobl, rogfer01, bollu, hiraditya.
Herald added a project: All.
michaelmaitland requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead, vkmr.
Herald added a project: LLVM.

VPWidenIntOrFpInductionSC is not a VPHeaderPHIRecipe and needs its
VPRecipeTy to be moved out of that section so it does not break
classof checks for VPHeaderPHIRecipe.

Additionally, the current way of checking for phi-like recipes
prohibits VPInstructions from being phi like because they will fail
the isPhi check. To resolve this, recipes should report for themselves
whether or not they are phi-like, allowing VPInstructions that are phi-like
to override and correctly report.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144125

Files:
  llvm/lib/Transforms/Vectorize/VPlan.h
  llvm/lib/Transforms/Vectorize/VPlanValue.h


Index: llvm/lib/Transforms/Vectorize/VPlanValue.h
===================================================================
--- llvm/lib/Transforms/Vectorize/VPlanValue.h
+++ llvm/lib/Transforms/Vectorize/VPlanValue.h
@@ -346,21 +346,20 @@
     VPWidenMemoryInstructionSC,
     VPWidenSC,
     VPWidenSelectSC,
-
-    // Phi-like recipes. Need to be kept together.
     VPBlendSC,
     VPPredInstPHISC,
-    // Header-phi recipes. Need to be kept together.
+    VPWidenIntOrFpInductionSC,
+    // START: SubclassID for recipes that inherit VPHeaderPHIRecipe.
+    // VPHeaderPHIRecipe need to be kept together.
     VPCanonicalIVPHISC,
     VPActiveLaneMaskPHISC,
     VPFirstOrderRecurrencePHISC,
     VPWidenPHISC,
-    VPWidenIntOrFpInductionSC,
     VPWidenPointerInductionSC,
     VPReductionPHISC,
-    VPFirstPHISC = VPBlendSC,
+    // END: SubclassID for recipes that inherit VPHeaderPHIRecipe
     VPFirstHeaderPHISC = VPCanonicalIVPHISC,
-    VPLastPHISC = VPReductionPHISC,
+    VPLastHeaderPHISC = VPReductionPHISC,
   };
 
   VPDef(const unsigned char SC) : SubclassID(SC) {}
Index: llvm/lib/Transforms/Vectorize/VPlan.h
===================================================================
--- llvm/lib/Transforms/Vectorize/VPlan.h
+++ llvm/lib/Transforms/Vectorize/VPlan.h
@@ -739,9 +739,7 @@
   bool mayHaveSideEffects() const;
 
   /// Returns true for PHI-like recipes.
-  bool isPhi() const {
-    return getVPDefID() >= VPFirstPHISC && getVPDefID() <= VPLastPHISC;
-  }
+  virtual bool isPhi() const { return false; }
 
   /// Returns true if the recipe may read from memory.
   bool mayReadFromMemory() const;
@@ -1094,6 +1092,8 @@
 
   /// Returns true if a vector phi needs to be created for the induction.
   bool needsVectorIV() const { return NeedsVectorIV; }
+
+  bool isPhi() const override { return true; }
 };
 
 /// A pure virtual base class for all recipes modeling header phis, including
@@ -1134,12 +1134,12 @@
   /// Method to support type inquiry through isa, cast, and dyn_cast.
   static inline bool classof(const VPRecipeBase *B) {
     return B->getVPDefID() >= VPDef::VPFirstHeaderPHISC &&
-           B->getVPDefID() <= VPDef::VPLastPHISC;
+           B->getVPDefID() <= VPDef::VPLastHeaderPHISC;
   }
   static inline bool classof(const VPValue *V) {
     auto *B = V->getDefiningRecipe();
     return B && B->getVPDefID() >= VPRecipeBase::VPFirstHeaderPHISC &&
-           B->getVPDefID() <= VPRecipeBase::VPLastPHISC;
+           B->getVPDefID() <= VPRecipeBase::VPLastHeaderPHISC;
   }
 
   /// Generate the phi nodes.
@@ -1172,6 +1172,8 @@
   VPRecipeBase &getBackedgeRecipe() {
     return *getBackedgeValue()->getDefiningRecipe();
   }
+
+  bool isPhi() const override { return true; }
 };
 
 class VPWidenPointerInductionRecipe : public VPHeaderPHIRecipe {
@@ -1374,6 +1376,8 @@
     return all_of(users(),
                   [this](VPUser *U) { return U->onlyFirstLaneUsed(this); });
   }
+
+  bool isPhi() const override { return true; }
 };
 
 /// VPInterleaveRecipe is a recipe for transforming an interleave group of load
@@ -1634,6 +1638,8 @@
            "Op must be an operand of the recipe");
     return true;
   }
+
+  bool isPhi() const override { return true; }
 };
 
 /// A Recipe for widening load/store operations.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144125.497743.patch
Type: text/x-patch
Size: 3272 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230215/93b16375/attachment.bin>


More information about the llvm-commits mailing list