diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -5457,6 +5457,9 @@ if (match(Op0, m_Intrinsic(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 --- a/llvm/test/Transforms/InstSimplify/named-vector-shuffle-reverse.ll +++ b/llvm/test/Transforms/InstSimplify/named-vector-shuffle-reverse.ll @@ -9,4 +9,17 @@ ret %rev.rev } +; Test reverse of a splat is eliminated. +define @splat_reverse(i32 %a) { +; CHECK-LABEL: @splat_reverse( +; CHECK-NEXT: [[SPLAT_INSERT:%.*]] = insertelement poison, i32 [[A:%.*]], i32 0 +; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector [[SPLAT_INSERT]], poison, zeroinitializer +; CHECK-NEXT: ret [[SPLAT]] +; + %splat_insert = insertelement poison, i32 %a, i32 0 + %splat = shufflevector %splat_insert, poison, zeroinitializer + %rev = tail call @llvm.experimental.vector.reverse.nxv4i32( %splat) + ret %rev +} + declare @llvm.experimental.vector.reverse.nxv4i32()