[PATCH] D70054: [LV] Move pointer inspection from ILV to recipe (NFCI)

Gil Rapaport via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 10 09:38:13 PST 2019


gilr created this revision.
gilr added reviewers: rengolin, hsaito, dcaballe, fhahn, Ayal, dorit.
Herald added subscribers: llvm-commits, rogfer01, rkruppe, bollu, hiraditya.
Herald added a project: LLVM.

Record the pointer argument of the memory instruction being vectorized and its
properties in VPWidenMemoryInstructionRecipe, delegating both to ILV on VPlan
execution instead of letting ILV rely on scalar IR's def-use relations. This
reduces ingredient DU usage by ILV as a step towards full VPlan-based def-use
relations.


Repository:
  rL LLVM

https://reviews.llvm.org/D70054

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
@@ -969,12 +969,17 @@
 private:
   Instruction &Instr;
   std::unique_ptr<VPUser> User;
+  bool InBounds = false;
+  Value *Ptr;
 
 public:
   VPWidenMemoryInstructionRecipe(Instruction &Instr, VPValue *Mask)
       : VPRecipeBase(VPWidenMemoryInstructionSC), Instr(Instr) {
     if (Mask) // Create a VPInstruction to register as a user of the mask.
       User.reset(new VPUser({Mask}));
+    Ptr = getLoadStorePointerOperand(&Instr);
+    if (auto *GEP = dyn_cast<GetElementPtrInst>(Ptr->stripPointerCasts()))
+      InBounds = GEP->isInBounds();
   }
 
   /// Method to support type inquiry through isa, cast, and dyn_cast.
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -483,7 +483,7 @@
 
   /// Vectorize Load and Store instructions, optionally masking the vector
   /// operations if \p BlockInMask is non-null.
-  void vectorizeMemoryInstruction(Instruction *Instr,
+  void vectorizeMemoryInstruction(Instruction *Instr, Value *Ptr, bool InBounds,
                                   VectorParts *BlockInMask = nullptr);
 
   /// Set the debug location in the builder using the debug location in
@@ -2342,6 +2342,7 @@
 }
 
 void InnerLoopVectorizer::vectorizeMemoryInstruction(Instruction *Instr,
+                                                     Value *Ptr, bool InBounds,
                                                      VectorParts *BlockInMask) {
   // Attempt to issue a wide load.
   LoadInst *LI = dyn_cast<LoadInst>(Instr);
@@ -2358,7 +2359,6 @@
 
   Type *ScalarDataTy = getMemInstValueType(Instr);
   Type *DataTy = VectorType::get(ScalarDataTy, VF);
-  Value *Ptr = getLoadStorePointerOperand(Instr);
   // An alignment of 0 means target abi alignment. We need to use the scalar's
   // target abi alignment in such a case.
   const DataLayout &DL = Instr->getModule()->getDataLayout();
@@ -2388,11 +2388,6 @@
   if (isMaskRequired)
     Mask = *BlockInMask;
 
-  bool InBounds = false;
-  if (auto *gep = dyn_cast<GetElementPtrInst>(
-          getLoadStorePointerOperand(Instr)->stripPointerCasts()))
-    InBounds = gep->isInBounds();
-
   const auto CreateVecPtr = [&](unsigned Part, Value *Ptr) -> Value * {
     // Calculate the pointer for the specific unroll-part.
     GetElementPtrInst *PartPtr = nullptr;
@@ -7412,12 +7407,12 @@
 void VPWidenMemoryInstructionRecipe::execute(VPTransformState &State) {
   VPValue *Mask = getMask();
   if (!Mask)
-    return State.ILV->vectorizeMemoryInstruction(&Instr);
+    return State.ILV->vectorizeMemoryInstruction(&Instr, Ptr, InBounds);
 
   InnerLoopVectorizer::VectorParts MaskValues(State.UF);
   for (unsigned Part = 0; Part < State.UF; ++Part)
     MaskValues[Part] = State.get(Mask, Part);
-  State.ILV->vectorizeMemoryInstruction(&Instr, &MaskValues);
+  State.ILV->vectorizeMemoryInstruction(&Instr, Ptr, InBounds, &MaskValues);
 }
 
 static ScalarEpilogueLowering


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70054.228611.patch
Type: text/x-patch
Size: 3233 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191110/80eb92a0/attachment-0001.bin>


More information about the llvm-commits mailing list