Skip to content

Commit 9fffd90

Browse files
ylzsxmikolaj-pirog
authored andcommitted
[LoongArch] Move widenShuffleMask before lowerVECTOR_SHUFFLE_XVPERMI to improve code quality (llvm#164219)
1 parent 4dd6f98 commit 9fffd90

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,6 +2614,9 @@ static SDValue lower256BitShuffle(const SDLoc &DL, ArrayRef<int> Mask, MVT VT,
26142614
if ((Result = lowerVECTOR_SHUFFLE_XVSHUF4I(DL, Mask, VT, V1, V2, DAG,
26152615
Subtarget)))
26162616
return Result;
2617+
// Try to widen vectors to gain more optimization opportunities.
2618+
if (SDValue NewShuffle = widenShuffleMask(DL, Mask, VT, V1, V2, DAG))
2619+
return NewShuffle;
26172620
if ((Result =
26182621
lowerVECTOR_SHUFFLE_XVPERMI(DL, Mask, VT, V1, DAG, Subtarget)))
26192622
return Result;

llvm/test/CodeGen/LoongArch/lasx/shuffle-as-permute-and-shuffle.ll

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ define <16 x i16> @shuffle_v16i16(<16 x i16> %a) {
3232
; CHECK: # %bb.0:
3333
; CHECK-NEXT: pcalau12i $a0, %pc_hi20(.LCPI2_0)
3434
; CHECK-NEXT: xvld $xr1, $a0, %pc_lo12(.LCPI2_0)
35-
; CHECK-NEXT: xvpermi.d $xr2, $xr0, 78
36-
; CHECK-NEXT: xvshuf.w $xr1, $xr2, $xr0
37-
; CHECK-NEXT: xvori.b $xr0, $xr1, 0
35+
; CHECK-NEXT: xvperm.w $xr0, $xr0, $xr1
3836
; CHECK-NEXT: ret
3937
%shuffle = shufflevector <16 x i16> %a, <16 x i16> poison, <16 x i32> <i32 8, i32 9, i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
4038
ret <16 x i16> %shuffle
@@ -55,9 +53,7 @@ define <16 x i16> @shuffle_v16i16_same_lane(<16 x i16> %a) {
5553
define <8 x i32> @shuffle_v8i32(<8 x i32> %a) {
5654
; CHECK-LABEL: shuffle_v8i32:
5755
; CHECK: # %bb.0:
58-
; CHECK-NEXT: pcalau12i $a0, %pc_hi20(.LCPI4_0)
59-
; CHECK-NEXT: xvld $xr1, $a0, %pc_lo12(.LCPI4_0)
60-
; CHECK-NEXT: xvperm.w $xr0, $xr0, $xr1
56+
; CHECK-NEXT: xvpermi.d $xr0, $xr0, 226
6157
; CHECK-NEXT: ret
6258
%shuffle = shufflevector <8 x i32> %a, <8 x i32> poison, <8 x i32> <i32 4, i32 5, i32 0, i32 1, i32 4, i32 5, i32 6, i32 7>
6359
ret <8 x i32> %shuffle
@@ -93,9 +89,7 @@ define <4 x i64> @shuffle_v4i64_same_lane(<4 x i64> %a) {
9389
define <8 x float> @shuffle_v8f32(<8 x float> %a) {
9490
; CHECK-LABEL: shuffle_v8f32:
9591
; CHECK: # %bb.0:
96-
; CHECK-NEXT: pcalau12i $a0, %pc_hi20(.LCPI8_0)
97-
; CHECK-NEXT: xvld $xr1, $a0, %pc_lo12(.LCPI8_0)
98-
; CHECK-NEXT: xvperm.w $xr0, $xr0, $xr1
92+
; CHECK-NEXT: xvpermi.d $xr0, $xr0, 226
9993
; CHECK-NEXT: ret
10094
%shuffle = shufflevector <8 x float> %a, <8 x float> poison, <8 x i32> <i32 4, i32 5, i32 0, i32 1, i32 4, i32 5, i32 6, i32 7>
10195
ret <8 x float> %shuffle

0 commit comments

Comments
 (0)