[llvm] [VP] Provide createAlignedLoad to emit VP load instruction. (PR #101666)

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 2 05:59:07 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-llvm-transforms

Author: Mel Chen (Mel-Chen)

<details>
<summary>Changes</summary>

This patch Introduces a new method `createAlignedLoad` in VectorBuilder to pack the creation of an aligned load instruction. Additionally, changed `VPWidenLoadEVLRecipe::execute` to use `createAlignedLoad` for simplifying the implementation and improving readability and maintainability.  

---
Full diff: https://github.com/llvm/llvm-project/pull/101666.diff


3 Files Affected:

- (modified) llvm/include/llvm/IR/VectorBuilder.h (+7) 
- (modified) llvm/lib/IR/VectorBuilder.cpp (+9) 
- (modified) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp (+1-4) 


``````````diff
diff --git a/llvm/include/llvm/IR/VectorBuilder.h b/llvm/include/llvm/IR/VectorBuilder.h
index dbb9f4c7336d5..80cf5d2cc7016 100644
--- a/llvm/include/llvm/IR/VectorBuilder.h
+++ b/llvm/include/llvm/IR/VectorBuilder.h
@@ -106,6 +106,13 @@ class VectorBuilder {
   Value *createSimpleTargetReduction(Intrinsic::ID RdxID, Type *ValTy,
                                      ArrayRef<Value *> VecOpArray,
                                      const Twine &Name = Twine());
+
+  /// Emit a VP load intrinsic call.
+  /// \param Ty         The return type of the load.
+  /// \param Ptr        The load address.
+  /// \param Alignment  The alignment information of the load.
+  CallInst *createAlignedLoad(Type *Ty, Value *Ptr, Align Alignment,
+                              const Twine &Name = Twine());
 };
 
 } // namespace llvm
diff --git a/llvm/lib/IR/VectorBuilder.cpp b/llvm/lib/IR/VectorBuilder.cpp
index 8dbf25277bf5d..908cd5eac3d74 100644
--- a/llvm/lib/IR/VectorBuilder.cpp
+++ b/llvm/lib/IR/VectorBuilder.cpp
@@ -70,6 +70,15 @@ Value *VectorBuilder::createSimpleTargetReduction(Intrinsic::ID RdxID,
   return createVectorInstructionImpl(VPID, ValTy, InstOpArray, Name);
 }
 
+CallInst *VectorBuilder::createAlignedLoad(Type *Ty, Value *Ptr,
+                                           Align Alignment, const Twine &Name) {
+  auto VPLI =
+      cast<CallInst>(createVectorInstruction(Instruction::Load, Ty, Ptr, Name));
+  VPLI->addParamAttr(
+      0, Attribute::getWithAlignment(VPLI->getContext(), Alignment));
+  return VPLI;
+}
+
 Value *VectorBuilder::createVectorInstructionImpl(Intrinsic::ID VPID,
                                                   Type *ReturnTy,
                                                   ArrayRef<Value *> InstOpArray,
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 6daa8043a3fbf..9394226635d33 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -9364,11 +9364,8 @@ void VPWidenLoadEVLRecipe::execute(VPTransformState &State) {
   } else {
     VectorBuilder VBuilder(Builder);
     VBuilder.setEVL(EVL).setMask(Mask);
-    NewLI = cast<CallInst>(VBuilder.createVectorInstruction(
-        Instruction::Load, DataTy, Addr, "vp.op.load"));
+    NewLI = VBuilder.createAlignedLoad(DataTy, Addr, Alignment, "vp.op.load");
   }
-  NewLI->addParamAttr(
-      0, Attribute::getWithAlignment(NewLI->getContext(), Alignment));
   State.addMetadata(NewLI, LI);
   Instruction *Res = NewLI;
   if (isReverse())

``````````

</details>


https://github.com/llvm/llvm-project/pull/101666


More information about the llvm-commits mailing list