[llvm] a7c4e9b - [InstSimplify] Eliminate vector reverse of a splat vector

Usman Nadeem via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 11 11:30:14 PDT 2021


Author: Usman Nadeem
Date: 2021-08-11T11:27:58-07:00
New Revision: a7c4e9b1f783ae9beb4c66e7af6a0cd3e086dafa

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

LOG: [InstSimplify] Eliminate vector reverse of a splat vector

    experimental.vector.reverse(splat(X)) -> splat(X)

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

Change-Id: Id29ba88fd669ff8686712e96b1bdc46dda5b853c

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp
    llvm/test/Transforms/InstSimplify/named-vector-shuffle-reverse.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 42e443383d26f..b30cd799f8c5d 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5473,6 +5473,9 @@ static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0,
     if (match(Op0,
               m_Intrinsic<Intrinsic::experimental_vector_reverse>(m_Value(X))))
       return X;
+    // experimental.vector.reverse(splat(X)) -> splat(X)
+    if (isSplatValue(Op0))
+      return Op0;
     break;
   default:
     break;

diff  --git a/llvm/test/Transforms/InstSimplify/named-vector-shuffle-reverse.ll b/llvm/test/Transforms/InstSimplify/named-vector-shuffle-reverse.ll
index c8dae3e1c4f6d..c2216e4d3ea2a 100644
--- a/llvm/test/Transforms/InstSimplify/named-vector-shuffle-reverse.ll
+++ b/llvm/test/Transforms/InstSimplify/named-vector-shuffle-reverse.ll
@@ -9,4 +9,17 @@ define <vscale x 4 x i32> @shuffle_b2b_reverse(<vscale x 4 x i32> %a) {
   ret <vscale x 4 x i32> %rev.rev
 }
 
+; Test reverse of a splat is eliminated.
+define <vscale x 4 x i32> @splat_reverse(i32 %a) {
+; CHECK-LABEL: @splat_reverse(
+; CHECK-NEXT:    [[SPLAT_INSERT:%.*]] = insertelement <vscale x 4 x i32> poison, i32 [[A:%.*]], i32 0
+; CHECK-NEXT:    [[SPLAT:%.*]] = shufflevector <vscale x 4 x i32> [[SPLAT_INSERT]], <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
+; CHECK-NEXT:    ret <vscale x 4 x i32> [[SPLAT]]
+;
+  %splat_insert = insertelement <vscale x 4 x i32> poison, i32 %a, i32 0
+  %splat = shufflevector <vscale x 4 x i32> %splat_insert, <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
+  %rev = tail call <vscale x 4 x i32> @llvm.experimental.vector.reverse.nxv4i32(<vscale x 4 x i32> %splat)
+  ret <vscale x 4 x i32> %rev
+}
+
 declare <vscale x 4 x i32> @llvm.experimental.vector.reverse.nxv4i32(<vscale x 4 x i32>)


        


More information about the llvm-commits mailing list