diff options
author | Rajveer Singh Bharadwaj <rajveer.developer@icloud.com> | 2025-08-24 14:21:48 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-24 14:21:48 +0530 |
commit | 93c96849c89507579a77980ff03adbeabb413573 (patch) | |
tree | 2dde9ea3d61ec5a1fad3d473e98161e0ebf096cd /llvm/lib/Transforms/Utils/LoopUtils.cpp | |
parent | 3054e06c33ac8977b355bf2cff14617a342dbce9 (diff) | |
download | llvm-93c96849c89507579a77980ff03adbeabb413573.zip llvm-93c96849c89507579a77980ff03adbeabb413573.tar.gz llvm-93c96849c89507579a77980ff03adbeabb413573.tar.bz2 |
[VectorCombine] New folding pattern for extract/binop/shuffle chains (#145232)
Resolves #144654
Part of #143088
This adds a new `foldShuffleChainsToReduce` for horizontal reduction of
patterns like:
```llvm
define i16 @test_reduce_v8i16(<8 x i16> %a0) local_unnamed_addr #0 {
%1 = shufflevector <8 x i16> %a0, <8 x i16> poison, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 poison, i32 poison, i32 poison, i32 poison>
%2 = tail call <8 x i16> @llvm.umin.v8i16(<8 x i16> %a0, <8 x i16> %1)
%3 = shufflevector <8 x i16> %2, <8 x i16> poison, <8 x i32> <i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
%4 = tail call <8 x i16> @llvm.umin.v8i16(<8 x i16> %2, <8 x i16> %3)
%5 = shufflevector <8 x i16> %4, <8 x i16> poison, <8 x i32> <i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
%6 = tail call <8 x i16> @llvm.umin.v8i16(<8 x i16> %4, <8 x i16> %5)
%7 = extractelement <8 x i16> %6, i64 0
ret i16 %7
}
```
...which can be reduced to a llvm.vector.reduce.umin.v8i16(%a0)
intrinsic call.
Similar transformation for other ops when costs permit to do so.
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUtils.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index 2d830f3..843364e 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -956,6 +956,21 @@ constexpr Intrinsic::ID llvm::getReductionIntrinsicID(RecurKind RK) { } } +Intrinsic::ID llvm::getMinMaxReductionIntrinsicID(Intrinsic::ID IID) { + switch (IID) { + default: + llvm_unreachable("Unexpected intrinsic id"); + case Intrinsic::umin: + return Intrinsic::vector_reduce_umin; + case Intrinsic::umax: + return Intrinsic::vector_reduce_umax; + case Intrinsic::smin: + return Intrinsic::vector_reduce_smin; + case Intrinsic::smax: + return Intrinsic::vector_reduce_smax; + } +} + // This is the inverse to getReductionForBinop unsigned llvm::getArithmeticReductionInstruction(Intrinsic::ID RdxID) { switch (RdxID) { |