[llvm] eb1a512 - [AArch64][SVE][InstCombine] last{a, b} of a splat vector

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 20 01:49:30 PDT 2021


Author: Sander de Smalen
Date: 2021-07-20T09:44:43+01:00
New Revision: eb1a5120b8d52ac3c33f404cf4c428c2de5f8a13

URL: https://github.com/llvm/llvm-project/commit/eb1a5120b8d52ac3c33f404cf4c428c2de5f8a13
DIFF: https://github.com/llvm/llvm-project/commit/eb1a5120b8d52ac3c33f404cf4c428c2de5f8a13.diff

LOG: [AArch64][SVE][InstCombine] last{a,b} of a splat vector

Replace last{a,b}(splat(X)) with X, irrespective of the predicate.

Patch by/Committing on behalf of: Usman Nadeem (mnadeem)

Reviewed By: sdesmalen

Differential Revision: https://reviews.llvm.org/D105520

Added: 
    

Modified: 
    llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
    llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-opts-lasta-lastb.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
index 6b2b830e56494..5f1b28a8f9a3b 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -551,6 +551,10 @@ static Optional<Instruction *> instCombineSVELast(InstCombiner &IC,
   Value *Vec = II.getArgOperand(1);
   bool IsAfter = II.getIntrinsicID() == Intrinsic::aarch64_sve_lasta;
 
+  // lastX(splat(X)) --> X
+  if (auto *SplatVal = getSplatValue(Vec))
+    return IC.replaceInstUsesWith(II, SplatVal);
+
   auto *C = dyn_cast<Constant>(Pg);
   if (IsAfter && C && C->isNullValue()) {
     // The intrinsic is extracting lane 0 so use an extract instead.

diff  --git a/llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-opts-lasta-lastb.ll b/llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-opts-lasta-lastb.ll
index c5919792b45d7..58c65bd9f24ad 100644
--- a/llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-opts-lasta-lastb.ll
+++ b/llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-opts-lasta-lastb.ll
@@ -144,6 +144,25 @@ define i8 @lastb_extractelement_invalid_predicate_pattern(<vscale x 16 x i8> %v)
   ret i8 %e
 }
 
+; Return the splatted value irrespective of the predicate.
+define i8 @lasta_splat(<vscale x 16 x i1> %pg, i8 %a) #0 {
+; OPT-LABEL: @lasta_splat(
+; OPT-NEXT:    ret i8 %a
+  %splat_insert = insertelement <vscale x 16 x i8> poison, i8 %a, i32 0
+  %splat = shufflevector <vscale x 16 x i8> %splat_insert, <vscale x 16 x i8> poison, <vscale x 16 x i32> zeroinitializer
+  %last = tail call i8 @llvm.aarch64.sve.lasta.nxv16i8(<vscale x 16 x i1> %pg, <vscale x 16 x i8> %splat)
+  ret i8 %last
+}
+
+define i8 @lastb_splat(<vscale x 16 x i1> %pg, i8 %a) #0 {
+; OPT-LABEL: @lastb_splat(
+; OPT-NEXT:    ret i8 %a
+  %splat_insert = insertelement <vscale x 16 x i8> poison, i8 %a, i32 0
+  %splat = shufflevector <vscale x 16 x i8> %splat_insert, <vscale x 16 x i8> poison, <vscale x 16 x i32> zeroinitializer
+  %last = tail call i8 @llvm.aarch64.sve.lastb.nxv16i8(<vscale x 16 x i1> %pg, <vscale x 16 x i8> %splat)
+  ret i8 %last
+}
+
 declare <vscale x 16 x i1> @llvm.aarch64.sve.ptrue.nxv16i1(i32)
 declare i8 @llvm.aarch64.sve.lasta.nxv16i8(<vscale x 16 x i1>, <vscale x 16 x i8>)
 declare i8 @llvm.aarch64.sve.lastb.nxv16i8(<vscale x 16 x i1>, <vscale x 16 x i8>)


        


More information about the llvm-commits mailing list