aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target
diff options
context:
space:
mode:
authorAmara Emerson <amara@apple.com>2021-08-18 00:19:58 -0700
committerAmara Emerson <amara@apple.com>2021-08-19 16:38:52 -0700
commit95ac3d15e9fe86d9b51b51d02cb3c1640bf30dee (patch)
treeeb928600c2d369838959eb0ada71055ff07e0dcb /llvm/lib/Target
parentfbb8e772ec501a1b71643db90e9c6445e17d7cac (diff)
downloadllvm-95ac3d15e9fe86d9b51b51d02cb3c1640bf30dee.zip
llvm-95ac3d15e9fe86d9b51b51d02cb3c1640bf30dee.tar.gz
llvm-95ac3d15e9fe86d9b51b51d02cb3c1640bf30dee.tar.bz2
[AArch64][GlobalISel] Add G_VECREDUCE fewerElements support for full scalarization.
For some reductions like G_VECREDUCE_OR on AArch64, we need to scalarize completely if the source is <= 64b. This change adds support for that in the legalizer. If the source has a pow-2 num elements, then we can do a tree reduction using the scalar operation in the individual elements. Otherwise, we just create a sequential chain of operations. For AArch64, we only need to scalarize if the input is <64b. If it's great than 64b then we can first do a fewElements step to 64b, taking advantage of vector instructions until we reach the point of scalarization. I also had to relax the verifier checks for reductions because the intrinsics support <1 x EltTy> types, which we lower to scalars for GlobalISel. Differential Revision: https://reviews.llvm.org/D108276
Diffstat (limited to 'llvm/lib/Target')
-rw-r--r--llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
index 5320f44..d68467b 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
@@ -691,6 +691,27 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
.clampMaxNumElements(1, s32, 4)
.lower();
+ getActionDefinitionsBuilder(G_VECREDUCE_OR)
+ // Try to break down into smaller vectors as long as they're at least 64
+ // bits. This lets us use vector operations for some parts of the
+ // reduction.
+ .fewerElementsIf(
+ [=](const LegalityQuery &Q) {
+ LLT SrcTy = Q.Types[1];
+ if (SrcTy.isScalar())
+ return false;
+ if (!isPowerOf2_32(SrcTy.getNumElements()))
+ return false;
+ // We can usually perform 64b vector operations.
+ return SrcTy.getSizeInBits() > 64;
+ },
+ [=](const LegalityQuery &Q) {
+ LLT SrcTy = Q.Types[1];
+ return std::make_pair(1, SrcTy.divide(2));
+ })
+ .scalarize(1)
+ .lower();
+
getActionDefinitionsBuilder({G_UADDSAT, G_USUBSAT})
.lowerIf([=](const LegalityQuery &Q) { return Q.Types[0].isScalar(); });