[PATCH] D100101: [VPlan] Add VPBasicBlock::phis() helper (NFC).

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 8 06:30:12 PDT 2021


fhahn created this revision.
fhahn added reviewers: gilr, rengolin, Ayal.
Herald added subscribers: tschuett, psnobl, rogfer01, bollu, hiraditya.
fhahn requested review of this revision.
Herald added a subscriber: vkmr.
Herald added a project: LLVM.

This patch introduces a helper to obtain an iterator range for the
PHI-like recipes in a block.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100101

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


Index: llvm/lib/Transforms/Vectorize/VPlan.h
===================================================================
--- llvm/lib/Transforms/Vectorize/VPlan.h
+++ llvm/lib/Transforms/Vectorize/VPlan.h
@@ -1475,6 +1475,18 @@
   inline const VPRecipeBase &back() const { return Recipes.back(); }
   inline VPRecipeBase &back() { return Recipes.back(); }
 
+  /// Returns an iterator range over the PHI-like recipes in the block.
+  iterator_range<iterator> phis() {
+    auto FirstNonPhi = begin();
+    for (auto E = end(); FirstNonPhi != E; ++FirstNonPhi) {
+      VPRecipeBase *R = &*FirstNonPhi;
+      if (!isa<VPWidenIntOrFpInductionRecipe>(R) && !isa<VPWidenPHIRecipe>(R))
+        break;
+    }
+
+    return make_range(begin(), FirstNonPhi);
+  }
+
   /// Returns a reference to the list of recipes.
   RecipeListTy &getRecipeList() { return Recipes; }
 
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -4068,13 +4068,10 @@
   // original loop is widened to a vector form so we can use them to construct
   // the incoming edges.
   VPBasicBlock *Header = State.Plan->getEntry()->getEntryBasicBlock();
-  for (VPRecipeBase &R : *Header) {
-    if (isa<VPWidenIntOrFpInductionRecipe>(&R))
-      continue;
+  for (VPRecipeBase &R : Header->phis()) {
     VPWidenPHIRecipe *PhiR = dyn_cast<VPWidenPHIRecipe>(&R);
     if (!PhiR)
-      break;
-
+      continue;
     auto *OrigPhi = cast<PHINode>(PhiR->getUnderlyingValue());
     if (PhiR->getRecurrenceDescriptor()) {
       fixReduction(PhiR, State);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100101.336081.patch
Type: text/x-patch
Size: 1687 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210408/e6b28023/attachment.bin>


More information about the llvm-commits mailing list