Skip to content

Commit 8b87edf

Browse files
authored
[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.
1 parent c642fa0 commit 8b87edf

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7302,14 +7302,12 @@ static Value *simplifyIntrinsic(CallBase *Call, Value *Callee,
73027302
}
73037303
case Intrinsic::experimental_vp_reverse: {
73047304
Value *Vec = Call->getArgOperand(0);
7305-
Value *Mask = Call->getArgOperand(1);
73067305
Value *EVL = Call->getArgOperand(2);
73077306

73087307
Value *X;
7309-
// vp.reverse(vp.reverse(X)) == X (with all ones mask and matching EVL)
7310-
if (match(Mask, m_AllOnes()) &&
7311-
match(Vec, m_Intrinsic<Intrinsic::experimental_vp_reverse>(
7312-
m_Value(X), m_AllOnes(), m_Specific(EVL))))
7308+
// vp.reverse(vp.reverse(X)) == X (mask doesn't matter)
7309+
if (match(Vec, m_Intrinsic<Intrinsic::experimental_vp_reverse>(
7310+
m_Value(X), m_Value(), m_Specific(EVL))))
73137311
return X;
73147312

73157313
// vp.reverse(splat(X)) -> splat(X) (regardless of mask and EVL)

llvm/test/Transforms/InstSimplify/vp-reverse.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,12 @@ define <vscale x 4 x i32> @rev_of_splat2(i32 %a, <vscale x 4 x i1> %m, i32 %evl)
6868
%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)
6969
ret <vscale x 4 x i32> %rev
7070
}
71+
72+
define <vscale x 4 x i32> @rev_of_rev_diffmask(<vscale x 4 x i32> %a, <vscale x 4 x i1> %mask1, <vscale x 4 x i1> %mask2, i32 %evl) {
73+
; CHECK-LABEL: @rev_of_rev_diffmask(
74+
; CHECK-NEXT: ret <vscale x 4 x i32> [[RES:%.*]]
75+
;
76+
%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)
77+
%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)
78+
ret <vscale x 4 x i32> %res
79+
}

0 commit comments

Comments
 (0)