[llvm] 8b87edf - [InstSimplify] Ignore mask when combinining vp.reverse(vp.reverse). (#171542)

via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 9 19:44:03 PST 2025


Author: Craig Topper
Date: 2025-12-09T19:44:00-08:00
New Revision: 8b87edfa689a3d02ce85ab908fb510585759dde9

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

LOG: [InstSimplify] Ignore mask when combinining vp.reverse(vp.reverse). (#171542)

The mask doesn't really affect the reverse. It only poisons the masked
off elements in the results. It should be ok to ignore the mask if we
can eliminate the pair.

I don't have a specific use case for this, but it matches what I had
implemented in our downstream before the current upstream
implementation. Submitting upstream so I can remove the delta
in my downstream.

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp
    llvm/test/Transforms/InstSimplify/vp-reverse.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index bd85444d7d2b0..1d82515cd84f9 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -7302,14 +7302,12 @@ static Value *simplifyIntrinsic(CallBase *Call, Value *Callee,
   }
   case Intrinsic::experimental_vp_reverse: {
     Value *Vec = Call->getArgOperand(0);
-    Value *Mask = Call->getArgOperand(1);
     Value *EVL = Call->getArgOperand(2);
 
     Value *X;
-    // vp.reverse(vp.reverse(X)) == X (with all ones mask and matching EVL)
-    if (match(Mask, m_AllOnes()) &&
-        match(Vec, m_Intrinsic<Intrinsic::experimental_vp_reverse>(
-                       m_Value(X), m_AllOnes(), m_Specific(EVL))))
+    // vp.reverse(vp.reverse(X)) == X (mask doesn't matter)
+    if (match(Vec, m_Intrinsic<Intrinsic::experimental_vp_reverse>(
+                       m_Value(X), m_Value(), m_Specific(EVL))))
       return X;
 
     // vp.reverse(splat(X)) -> splat(X) (regardless of mask and EVL)

diff  --git a/llvm/test/Transforms/InstSimplify/vp-reverse.ll b/llvm/test/Transforms/InstSimplify/vp-reverse.ll
index f19a2ac8ca9e1..0a9998a9f64bb 100644
--- a/llvm/test/Transforms/InstSimplify/vp-reverse.ll
+++ b/llvm/test/Transforms/InstSimplify/vp-reverse.ll
@@ -68,3 +68,12 @@ define <vscale x 4 x i32> @rev_of_splat2(i32 %a, <vscale x 4 x i1> %m, i32 %evl)
   %rev = tail call <vscale x 4 x i32> @llvm.experimental.vp.reverse(<vscale x 4 x i32> %a.vec, <vscale x 4 x i1> %m, i32 %evl)
   ret <vscale x 4 x i32> %rev
 }
+
+define <vscale x 4 x i32> @rev_of_rev_
diff mask(<vscale x 4 x i32> %a, <vscale x 4 x i1> %mask1, <vscale x 4 x i1> %mask2, i32 %evl) {
+; CHECK-LABEL: @rev_of_rev_
diff mask(
+; CHECK-NEXT:    ret <vscale x 4 x i32> [[RES:%.*]]
+;
+  %a.rev = tail call <vscale x 4 x i32> @llvm.experimental.vp.reverse(<vscale x 4 x i32> %a, <vscale x 4 x i1> %mask1, i32 %evl)
+  %res = tail call <vscale x 4 x i32> @llvm.experimental.vp.reverse(<vscale x 4 x i32> %a.rev, <vscale x 4 x i1> %mask2, i32 %evl)
+  ret <vscale x 4 x i32> %res
+}


        


More information about the llvm-commits mailing list