[llvm] 1522440 - [VPlan] Use VPUser for VPWidenSelectRecipe operands (NFC).

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sun May 24 06:04:29 PDT 2020


Author: Florian Hahn
Date: 2020-05-24T13:58:08+01:00
New Revision: 15224408f0d49ddd2716080c52a9d0f9f64a2b5a

URL: https://github.com/llvm/llvm-project/commit/15224408f0d49ddd2716080c52a9d0f9f64a2b5a
DIFF: https://github.com/llvm/llvm-project/commit/15224408f0d49ddd2716080c52a9d0f9f64a2b5a.diff

LOG: [VPlan] Use VPUser for VPWidenSelectRecipe operands (NFC).

VPWidenSelectRecipe already contains a VPUser, but it is not used. This
patch updates the code related to VPWidenSelectRecipe to use VPUser for
its operands.

Reviewers: Ayal, gilr, rengolin

Reviewed By: gilr

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

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 4eefe9a92a47..5fc2f86095ab 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -415,7 +415,8 @@ class InnerLoopVectorizer {
                             VPTransformState &State);
 
   /// Widen a single select instruction within the innermost loop.
-  void widenSelectInstruction(SelectInst &I, bool InvariantCond);
+  void widenSelectInstruction(SelectInst &I, VPUser &Operands,
+                              bool InvariantCond, VPTransformState &State);
 
   /// Fix the vectorized code, taking care of header phi's, live-outs, and more.
   void fixVectorizedLoop();
@@ -4412,7 +4413,9 @@ void InnerLoopVectorizer::widenCallInstruction(CallInst &I, VPUser &ArgOperands,
 }
 
 void InnerLoopVectorizer::widenSelectInstruction(SelectInst &I,
-                                                 bool InvariantCond) {
+                                                 VPUser &Operands,
+                                                 bool InvariantCond,
+                                                 VPTransformState &State) {
   setDebugLocFromInst(Builder, &I);
 
   // The condition can be loop invariant  but still defined inside the
@@ -4420,12 +4423,12 @@ void InnerLoopVectorizer::widenSelectInstruction(SelectInst &I,
   // We have to take the 'vectorized' value and pick the first lane.
   // Instcombine will make this a no-op.
 
-  auto *ScalarCond = getOrCreateScalarValue(I.getOperand(0), {0, 0});
+  auto *ScalarCond = State.get(Operands.getOperand(0), {0, 0});
 
   for (unsigned Part = 0; Part < UF; ++Part) {
-    Value *Cond = getOrCreateVectorValue(I.getOperand(0), Part);
-    Value *Op0 = getOrCreateVectorValue(I.getOperand(1), Part);
-    Value *Op1 = getOrCreateVectorValue(I.getOperand(2), Part);
+    Value *Cond = State.get(Operands.getOperand(0), Part);
+    Value *Op0 = State.get(Operands.getOperand(1), Part);
+    Value *Op1 = State.get(Operands.getOperand(2), Part);
     Value *Sel =
         Builder.CreateSelect(InvariantCond ? ScalarCond : Cond, Op0, Op1);
     VectorLoopValueMap.setVectorValue(&I, Part, Sel);
@@ -7134,7 +7137,8 @@ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(Instruction *Instr,
   if (auto *SI = dyn_cast<SelectInst>(Instr)) {
     bool InvariantCond =
         PSE.getSE()->isLoopInvariant(PSE.getSCEV(SI->getOperand(0)), OrigLoop);
-    return new VPWidenSelectRecipe(*SI, InvariantCond);
+    return new VPWidenSelectRecipe(*SI, Plan->mapToVPValues(SI->operands()),
+                                   InvariantCond);
   }
 
   return tryToWiden(Instr, *Plan);
@@ -7429,7 +7433,7 @@ void VPWidenCallRecipe::execute(VPTransformState &State) {
 }
 
 void VPWidenSelectRecipe::execute(VPTransformState &State) {
-  State.ILV->widenSelectInstruction(Ingredient, InvariantCond);
+  State.ILV->widenSelectInstruction(Ingredient, User, InvariantCond, State);
 }
 
 void VPWidenRecipe::execute(VPTransformState &State) {

diff  --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index a9da0af59ae0..1d07d5cff8a3 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -823,15 +823,17 @@ class VPWidenSelectRecipe : public VPRecipeBase {
   /// Hold the select to be widened.
   SelectInst &Ingredient;
 
-  /// Is the condition of the select loop invariant?
-  bool InvariantCond;
-
   /// Hold VPValues for the operands of the select.
   VPUser User;
 
+  /// Is the condition of the select loop invariant?
+  bool InvariantCond;
+
 public:
-  VPWidenSelectRecipe(SelectInst &I, bool InvariantCond)
-      : VPRecipeBase(VPWidenSelectSC), Ingredient(I),
+  template <typename IterT>
+  VPWidenSelectRecipe(SelectInst &I, iterator_range<IterT> Operands,
+                      bool InvariantCond)
+      : VPRecipeBase(VPWidenSelectSC), Ingredient(I), User(Operands),
         InvariantCond(InvariantCond) {}
 
   ~VPWidenSelectRecipe() override = default;


        


More information about the llvm-commits mailing list