[llvm] [VP] Provide createAlignedLoad to emit VP load instruction. (PR #101666)
Mel Chen via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 2 05:58:35 PDT 2024
https://github.com/Mel-Chen created https://github.com/llvm/llvm-project/pull/101666
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.
>From aab22562e4334a9334517ebfed1b18d8c4ad9a7f Mon Sep 17 00:00:00 2001
From: Mel Chen <mel.chen at sifive.com>
Date: Fri, 2 Aug 2024 05:17:34 -0700
Subject: [PATCH] [VP] Provide createAlignedLoad to emit VP load instruction.
---
llvm/include/llvm/IR/VectorBuilder.h | 7 +++++++
llvm/lib/IR/VectorBuilder.cpp | 9 +++++++++
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 5 +----
3 files changed, 17 insertions(+), 4 deletions(-)
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())
More information about the llvm-commits
mailing list