diff options
author | Florian Hahn <flo@fhahn.com> | 2025-06-29 11:17:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-29 11:17:03 +0100 |
commit | 20fbbd76755c2ddee515f09e96c59d519aef13e5 (patch) | |
tree | d99bb14d0763ba92965681532c79968cd5028292 /llvm/lib/Transforms/Utils/LoopUtils.cpp | |
parent | 8bd6d36a44134f23000762f3cb192a325c4cfd91 (diff) | |
download | llvm-20fbbd76755c2ddee515f09e96c59d519aef13e5.zip llvm-20fbbd76755c2ddee515f09e96c59d519aef13e5.tar.gz llvm-20fbbd76755c2ddee515f09e96c59d519aef13e5.tar.bz2 |
[LV] Add support for cmp reductions with decreasing IVs. (#140451)
Similar to FindLastIV, add FindFirstIVSMin to support select (icmp(), x, y)
reductions where one of x or y is a decreasing induction, producing a SMin
reduction. It uses signed max as sentinel value.
PR: https://github.com/llvm/llvm-project/pull/140451
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUtils.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index c50bb4a..e44fa6a 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -1227,8 +1227,10 @@ Value *llvm::createFindLastIVReduction(IRBuilderBase &Builder, Value *Src, RecurKind RdxKind, Value *Start, Value *Sentinel) { bool IsSigned = RecurrenceDescriptor::isSignedRecurrenceKind(RdxKind); + bool IsMaxRdx = RecurrenceDescriptor::isFindLastIVRecurrenceKind(RdxKind); Value *MaxRdx = Src->getType()->isVectorTy() - ? Builder.CreateIntMaxReduce(Src, IsSigned) + ? (IsMaxRdx ? Builder.CreateIntMaxReduce(Src, IsSigned) + : Builder.CreateIntMinReduce(Src, IsSigned)) : Src; // Correct the final reduction result back to the start value if the maximum // reduction is sentinel value. @@ -1324,8 +1326,8 @@ Value *llvm::createSimpleReduction(IRBuilderBase &Builder, Value *Src, 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."); + !RecurrenceDescriptor::isFindIVRecurrenceKind(Kind) && + "AnyOf and FindIV reductions are not supported."); Intrinsic::ID Id = getReductionIntrinsicID(Kind); auto VPID = VPIntrinsic::getForIntrinsic(Id); assert(VPReductionIntrinsic::isVPReduction(VPID) && |