[PATCH] D100763: [LoopVectorize] Don't create unnecessary vscale intrinsic calls
David Sherwood via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 19 07:21:25 PDT 2021
david-arm created this revision.
david-arm added reviewers: sdesmalen, c-rhodes, frasercrmck, kmclaughlin.
Herald added a subscriber: hiraditya.
david-arm requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
In quite a few cases in LoopVectorize.cpp we call createStepForVF
with a step value of 0, which leads to unnecessary generation of
llvm.vscale intrinsic calls. I've optimised IRBuilder::CreateVScale
and createStepForVF to return 0 when attempting to multiply
vscale by 0.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D100763
Files:
llvm/lib/IR/IRBuilder.cpp
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -1108,10 +1108,12 @@
/// Return a value for Step multiplied by VF.
static Value *createStepForVF(IRBuilder<> &B, Constant *Step, ElementCount VF) {
assert(isa<ConstantInt>(Step) && "Expected an integer step");
- Constant *StepVal = ConstantInt::get(
- Step->getType(),
- cast<ConstantInt>(Step)->getSExtValue() * VF.getKnownMinValue());
- return VF.isScalable() ? B.CreateVScale(StepVal) : StepVal;
+ uint64_t StepVal = cast<ConstantInt>(Step)->getSExtValue();
+ if (StepVal == 0)
+ return Step;
+ Constant *NewStep =
+ ConstantInt::get(Step->getType(), StepVal * VF.getKnownMinValue());
+ return VF.isScalable() ? B.CreateVScale(NewStep) : NewStep;
}
namespace llvm {
@@ -4768,10 +4770,9 @@
"Currently unsupported for scalable vectors");
unsigned Lanes = IsUniform ? 1 : State.VF.getFixedValue();
- Value *RuntimeVF = getRuntimeVF(Builder, PtrInd->getType(), VF);
for (unsigned Part = 0; Part < UF; ++Part) {
- Value *PartStart = Builder.CreateMul(
- RuntimeVF, ConstantInt::get(PtrInd->getType(), Part));
+ Value *PartStart = createStepForVF(
+ Builder, ConstantInt::get(PtrInd->getType(), Part), VF);
for (unsigned Lane = 0; Lane < Lanes; ++Lane) {
Value *Idx = Builder.CreateAdd(
PartStart, ConstantInt::get(PtrInd->getType(), Lane));
Index: llvm/lib/IR/IRBuilder.cpp
===================================================================
--- llvm/lib/IR/IRBuilder.cpp
+++ llvm/lib/IR/IRBuilder.cpp
@@ -81,8 +81,10 @@
}
Value *IRBuilderBase::CreateVScale(Constant *Scaling, const Twine &Name) {
- Module *M = GetInsertBlock()->getParent()->getParent();
assert(isa<ConstantInt>(Scaling) && "Expected constant integer");
+ if (cast<ConstantInt>(Scaling)->isZero())
+ return Scaling;
+ Module *M = GetInsertBlock()->getParent()->getParent();
Function *TheFn =
Intrinsic::getDeclaration(M, Intrinsic::vscale, {Scaling->getType()});
CallInst *CI = createCallHelper(TheFn, {}, this, Name);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100763.338515.patch
Type: text/x-patch
Size: 2280 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210419/2292137a/attachment.bin>
More information about the llvm-commits
mailing list