diff options
author | Philip Reames <preames@rivosinc.com> | 2025-06-12 13:46:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-12 13:46:06 -0700 |
commit | 8ee9646b06cd128a6c55f375e4df431aee053c76 (patch) | |
tree | 5ce8e32d5d20e8aaa9b417e4321034be172b4a94 /llvm/lib/Transforms/Utils/LoopUtils.cpp | |
parent | d65904675ea106713937c9cce24e3d1ec0bc570a (diff) | |
download | llvm-8ee9646b06cd128a6c55f375e4df431aee053c76.zip llvm-8ee9646b06cd128a6c55f375e4df431aee053c76.tar.gz llvm-8ee9646b06cd128a6c55f375e4df431aee053c76.tar.bz2 |
[LV] Simplify creation of vp.load/vp.store/vp.reduce intrinsics (#143804)
The use of VectorBuilder here was simply obscuring what was actually
going on. For vp.load and vp.store, the resulting code is significantly
more idiomatic. For the vp.reduce cases, we remove several layers of
indirection, including passing parameters via implicit state on the
builder. In both cases, the code is significantly easier to follow.
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUtils.cpp | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index ff69fa9..cf6b183 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -1319,18 +1319,19 @@ Value *llvm::createSimpleReduction(IRBuilderBase &Builder, Value *Src, } } -Value *llvm::createSimpleReduction(VectorBuilder &VBuilder, Value *Src, - RecurKind Kind) { +Value *llvm::createSimpleReduction(IRBuilderBase &Builder, Value *Src, + RecurKind Kind, Value *Mask, Value *EVL) { assert(!RecurrenceDescriptor::isAnyOfRecurrenceKind(Kind) && !RecurrenceDescriptor::isFindLastIVRecurrenceKind(Kind) && "AnyOf or FindLastIV reductions are not supported."); Intrinsic::ID Id = getReductionIntrinsicID(Kind); - auto *SrcTy = cast<VectorType>(Src->getType()); - Type *SrcEltTy = SrcTy->getElementType(); - Value *Iden = - getRecurrenceIdentity(Kind, SrcEltTy, VBuilder.getFastMathFlags()); - Value *Ops[] = {Iden, Src}; - return VBuilder.createSimpleReduction(Id, SrcTy, Ops); + auto VPID = VPIntrinsic::getForIntrinsic(Id); + assert(VPReductionIntrinsic::isVPReduction(VPID) && + "No VPIntrinsic for this reduction"); + auto *EltTy = cast<VectorType>(Src->getType())->getElementType(); + Value *Iden = getRecurrenceIdentity(Kind, EltTy, Builder.getFastMathFlags()); + Value *Ops[] = {Iden, Src, Mask, EVL}; + return Builder.CreateIntrinsic(EltTy, VPID, Ops); } Value *llvm::createOrderedReduction(IRBuilderBase &B, RecurKind Kind, @@ -1343,17 +1344,21 @@ Value *llvm::createOrderedReduction(IRBuilderBase &B, RecurKind Kind, return B.CreateFAddReduce(Start, Src); } -Value *llvm::createOrderedReduction(VectorBuilder &VBuilder, RecurKind Kind, - Value *Src, Value *Start) { +Value *llvm::createOrderedReduction(IRBuilderBase &Builder, RecurKind Kind, + Value *Src, Value *Start, Value *Mask, + Value *EVL) { assert((Kind == RecurKind::FAdd || Kind == RecurKind::FMulAdd) && "Unexpected reduction kind"); assert(Src->getType()->isVectorTy() && "Expected a vector type"); assert(!Start->getType()->isVectorTy() && "Expected a scalar type"); Intrinsic::ID Id = getReductionIntrinsicID(RecurKind::FAdd); - auto *SrcTy = cast<VectorType>(Src->getType()); - Value *Ops[] = {Start, Src}; - return VBuilder.createSimpleReduction(Id, SrcTy, Ops); + auto VPID = VPIntrinsic::getForIntrinsic(Id); + assert(VPReductionIntrinsic::isVPReduction(VPID) && + "No VPIntrinsic for this reduction"); + auto *EltTy = cast<VectorType>(Src->getType())->getElementType(); + Value *Ops[] = {Start, Src, Mask, EVL}; + return Builder.CreateIntrinsic(EltTy, VPID, Ops); } void llvm::propagateIRFlags(Value *I, ArrayRef<Value *> VL, Value *OpValue, |