[PATCH] D77973: [VPlan] Move widening check for non-memory/non-calls to function (NFC).

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 12 08:32:23 PDT 2020


fhahn created this revision.
fhahn added reviewers: gilr, rengolin, Ayal, hsaito.
Herald added subscribers: psnobl, rogfer01, rkruppe, tschuett, bollu, hiraditya.
Herald added a project: LLVM.

After introducing VPWidenSelectRecipe, the duplicated logic can be
shared.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77973

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


Index: llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h
===================================================================
--- llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h
+++ llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h
@@ -64,6 +64,11 @@
     Ingredient2Recipe[I] = R;
   }
 
+  /// Check if \p I can be widened at the start of \p Range and possibly
+  /// decrease the range such that the returned value holds for the entire \p
+  /// Range. The function should not be called for memory instructions or calls.
+  bool shouldWiden(Instruction *I, VFRange &Range) const;
+
 public:
   /// A helper function that computes the predicate of the block BB, assuming
   /// that the header block of the loop is set to True. It returns the *entry*
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -6936,20 +6936,23 @@
   return new VPWidenCallRecipe(*CI, VPValues);
 }
 
+bool VPRecipeBuilder::shouldWiden(Instruction *I, VFRange &Range) const {
+  assert(!isa<CallInst>(I) && !isa<StoreInst>(I) && !isa<LoadInst>(I) &&
+         "Called with unsupported instruction");
+  // Instruction should be widened, unless it is scalar after vectorization,
+  // scalarization is profitable or it is predicated.
+  auto willWiden = [this, I](unsigned VF) -> bool {
+    return !CM.isScalarAfterVectorization(I, VF) &&
+           !CM.isProfitableToScalarize(I, VF) &&
+           !CM.isScalarWithPredication(I, VF);
+  };
+  return LoopVectorizationPlanner::getDecisionAndClampRange(willWiden, Range);
+}
+
 VPWidenSelectRecipe *VPRecipeBuilder::tryToWidenSelect(Instruction *I,
                                                        VFRange &Range) {
   auto *SI = dyn_cast<SelectInst>(I);
-  if (!SI)
-    return nullptr;
-
-  // SI should be widened, unless it is scalar after vectorization,
-  // scalarization is profitable or it is predicated.
-  auto willWiden = [this, SI](unsigned VF) -> bool {
-    return !CM.isScalarAfterVectorization(SI, VF) &&
-           !CM.isProfitableToScalarize(SI, VF) &&
-           !CM.isScalarWithPredication(SI, VF);
-  };
-  if (!LoopVectorizationPlanner::getDecisionAndClampRange(willWiden, Range))
+  if (!SI || !shouldWiden(I, Range))
     return nullptr;
 
   auto *SE = PSE.getSE();
@@ -6961,12 +6964,6 @@
 
 VPWidenRecipe *VPRecipeBuilder::tryToWiden(Instruction *I, VFRange &Range,
                                            VPlan &Plan) {
-  bool IsPredicated = LoopVectorizationPlanner::getDecisionAndClampRange(
-      [&](unsigned VF) { return CM.isScalarWithPredication(I, VF); }, Range);
-
-  if (IsPredicated)
-    return nullptr;
-
   auto IsVectorizableOpcode = [](unsigned Opcode) {
     switch (Opcode) {
     case Instruction::Add:
@@ -7010,17 +7007,7 @@
     return false;
   };
 
-  if (!IsVectorizableOpcode(I->getOpcode()))
-    return nullptr;
-
-  auto willWiden = [&](unsigned VF) -> bool {
-    if (!isa<PHINode>(I) && (CM.isScalarAfterVectorization(I, VF) ||
-                             CM.isProfitableToScalarize(I, VF)))
-      return false;
-    return true;
-  };
-
-  if (!LoopVectorizationPlanner::getDecisionAndClampRange(willWiden, Range))
+  if (!IsVectorizableOpcode(I->getOpcode()) || !shouldWiden(I, Range))
     return nullptr;
 
   // Success: widen this instruction.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77973.256858.patch
Type: text/x-patch
Size: 3428 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200412/b2f14199/attachment-0001.bin>


More information about the llvm-commits mailing list