diff options
| author | Michael Kruse <llvm-project@meinersbur.de> | 2025-01-03 10:22:51 +0100 |
|---|---|---|
| committer | Michael Kruse <llvm-project@meinersbur.de> | 2025-01-03 10:22:51 +0100 |
| commit | 38500d63e14ce340236840f60d356cdefb56a52c (patch) | |
| tree | 17edbec446ce9b50d2f215a483b83afb293a635d /llvm/lib/Transforms/Utils/LoopUtils.cpp | |
| parent | 1a3d5daaef7a6a63448a497da3eff7fc9e23df26 (diff) | |
| parent | 27f30029741ecf023baece7b3dde1ff9011ffefc (diff) | |
Merge branch 'main' into users/meinersbur/flang_runtime_split-headersusers/meinersbur/flang_runtime_split-headers
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUtils.cpp')
| -rw-r--r-- | llvm/lib/Transforms/Utils/LoopUtils.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index 70047273c3b9..45915c10107b 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -1208,6 +1208,23 @@ Value *llvm::createAnyOfReduction(IRBuilderBase &Builder, Value *Src, return Builder.CreateSelect(AnyOf, NewVal, InitVal, "rdx.select"); } +Value *llvm::createFindLastIVReduction(IRBuilderBase &Builder, Value *Src, + const RecurrenceDescriptor &Desc) { + assert(RecurrenceDescriptor::isFindLastIVRecurrenceKind( + Desc.getRecurrenceKind()) && + "Unexpected reduction kind"); + Value *StartVal = Desc.getRecurrenceStartValue(); + Value *Sentinel = Desc.getSentinelValue(); + Value *MaxRdx = Src->getType()->isVectorTy() + ? Builder.CreateIntMaxReduce(Src, true) + : Src; + // Correct the final reduction result back to the start value if the maximum + // reduction is sentinel value. + Value *Cmp = + Builder.CreateCmp(CmpInst::ICMP_NE, MaxRdx, Sentinel, "rdx.select.cmp"); + return Builder.CreateSelect(Cmp, MaxRdx, StartVal, "rdx.select"); +} + Value *llvm::getReductionIdentity(Intrinsic::ID RdxID, Type *Ty, FastMathFlags Flags) { bool Negative = false; @@ -1315,6 +1332,8 @@ Value *llvm::createReduction(IRBuilderBase &B, RecurKind RK = Desc.getRecurrenceKind(); if (RecurrenceDescriptor::isAnyOfRecurrenceKind(RK)) return createAnyOfReduction(B, Src, Desc, OrigPhi); + if (RecurrenceDescriptor::isFindLastIVRecurrenceKind(RK)) + return createFindLastIVReduction(B, Src, Desc); return createSimpleReduction(B, Src, RK); } |
