[llvm] a3a9ba8 - [X86] lowerShuffleAsVTRUNC - ensure we peek through bitcasts when looking for freely-concatable subvectors
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 15 07:41:37 PDT 2024
Author: Simon Pilgrim
Date: 2024-10-15T15:40:52+01:00
New Revision: a3a9ba80337ec1b276a7571049eda6ea03276ea3
URL: https://github.com/llvm/llvm-project/commit/a3a9ba80337ec1b276a7571049eda6ea03276ea3
DIFF: https://github.com/llvm/llvm-project/commit/a3a9ba80337ec1b276a7571049eda6ea03276ea3.diff
LOG: [X86] lowerShuffleAsVTRUNC - ensure we peek through bitcasts when looking for freely-concatable subvectors
Fixes #111611
Added:
Modified:
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/shuffle-vs-trunc-128.ll
llvm/test/CodeGen/X86/shuffle-vs-trunc-512.ll
llvm/test/CodeGen/X86/x86-interleaved-access.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index e70fbd8b23f2ab..a24c65bcf1383f 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -10356,7 +10356,7 @@ static SDValue lowerShuffleAsVTRUNC(const SDLoc &DL, MVT VT, SDValue V1,
}
return false;
};
- if (!IsCheapConcat(V1, V2))
+ if (!IsCheapConcat(peekThroughBitcasts(V1), peekThroughBitcasts(V2)))
continue;
}
diff --git a/llvm/test/CodeGen/X86/shuffle-vs-trunc-128.ll b/llvm/test/CodeGen/X86/shuffle-vs-trunc-128.ll
index 68749d6cb8feee..9642e5e4c9f868 100644
--- a/llvm/test/CodeGen/X86/shuffle-vs-trunc-128.ll
+++ b/llvm/test/CodeGen/X86/shuffle-vs-trunc-128.ll
@@ -797,69 +797,12 @@ define <16 x i8> @oddelts_v32i16_shuffle_v16i16_to_v16i8(<32 x i16> %n2) nounwin
; AVX2-NEXT: vzeroupper
; AVX2-NEXT: retq
;
-; AVX512F-LABEL: oddelts_v32i16_shuffle_v16i16_to_v16i8:
-; AVX512F: # %bb.0:
-; AVX512F-NEXT: vextracti64x4 $1, %zmm0, %ymm1
-; AVX512F-NEXT: vextracti128 $1, %ymm1, %xmm2
-; AVX512F-NEXT: vpbroadcastd {{.*#+}} xmm3 = [2,6,10,14,2,6,10,14,2,6,10,14,2,6,10,14]
-; AVX512F-NEXT: vpshufb %xmm3, %xmm2, %xmm2
-; AVX512F-NEXT: vpshufb %xmm3, %xmm1, %xmm1
-; AVX512F-NEXT: vpunpckldq {{.*#+}} xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
-; AVX512F-NEXT: vpsrld $16, %ymm0, %ymm0
-; AVX512F-NEXT: vpmovdb %zmm0, %xmm0
-; AVX512F-NEXT: vpblendd {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
-; AVX512F-NEXT: vzeroupper
-; AVX512F-NEXT: retq
-;
-; AVX512VL-LABEL: oddelts_v32i16_shuffle_v16i16_to_v16i8:
-; AVX512VL: # %bb.0:
-; AVX512VL-NEXT: vextracti64x4 $1, %zmm0, %ymm1
-; AVX512VL-NEXT: vextracti128 $1, %ymm1, %xmm2
-; AVX512VL-NEXT: vpbroadcastd {{.*#+}} xmm3 = [2,6,10,14,2,6,10,14,2,6,10,14,2,6,10,14]
-; AVX512VL-NEXT: vpshufb %xmm3, %xmm2, %xmm2
-; AVX512VL-NEXT: vpshufb %xmm3, %xmm1, %xmm1
-; AVX512VL-NEXT: vpunpckldq {{.*#+}} xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
-; AVX512VL-NEXT: vpsrld $16, %ymm0, %ymm0
-; AVX512VL-NEXT: vpmovdb %ymm0, %xmm0
-; AVX512VL-NEXT: vpblendd {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
-; AVX512VL-NEXT: vzeroupper
-; AVX512VL-NEXT: retq
-;
-; AVX512BW-LABEL: oddelts_v32i16_shuffle_v16i16_to_v16i8:
-; AVX512BW: # %bb.0:
-; AVX512BW-NEXT: vextracti64x4 $1, %zmm0, %ymm1
-; AVX512BW-NEXT: vextracti128 $1, %ymm1, %xmm2
-; AVX512BW-NEXT: vpbroadcastd {{.*#+}} xmm3 = [2,6,10,14,2,6,10,14,2,6,10,14,2,6,10,14]
-; AVX512BW-NEXT: vpshufb %xmm3, %xmm2, %xmm2
-; AVX512BW-NEXT: vpshufb %xmm3, %xmm1, %xmm1
-; AVX512BW-NEXT: vpunpckldq {{.*#+}} xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
-; AVX512BW-NEXT: vpsrld $16, %ymm0, %ymm0
-; AVX512BW-NEXT: vpmovdb %zmm0, %xmm0
-; AVX512BW-NEXT: vpblendd {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
-; AVX512BW-NEXT: vzeroupper
-; AVX512BW-NEXT: retq
-;
-; AVX512BWVL-ONLY-LABEL: oddelts_v32i16_shuffle_v16i16_to_v16i8:
-; AVX512BWVL-ONLY: # %bb.0:
-; AVX512BWVL-ONLY-NEXT: vextracti64x4 $1, %zmm0, %ymm1
-; AVX512BWVL-ONLY-NEXT: vextracti128 $1, %ymm1, %xmm2
-; AVX512BWVL-ONLY-NEXT: vpbroadcastd {{.*#+}} xmm3 = [2,6,10,14,2,6,10,14,2,6,10,14,2,6,10,14]
-; AVX512BWVL-ONLY-NEXT: vpshufb %xmm3, %xmm2, %xmm2
-; AVX512BWVL-ONLY-NEXT: vpshufb %xmm3, %xmm1, %xmm1
-; AVX512BWVL-ONLY-NEXT: vpunpckldq {{.*#+}} xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
-; AVX512BWVL-ONLY-NEXT: vpsrld $16, %ymm0, %ymm0
-; AVX512BWVL-ONLY-NEXT: vpmovdb %ymm0, %xmm0
-; AVX512BWVL-ONLY-NEXT: vpblendd {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
-; AVX512BWVL-ONLY-NEXT: vzeroupper
-; AVX512BWVL-ONLY-NEXT: retq
-;
-; AVX512VBMI-LABEL: oddelts_v32i16_shuffle_v16i16_to_v16i8:
-; AVX512VBMI: # %bb.0:
-; AVX512VBMI-NEXT: vmovdqa {{.*#+}} xmm1 = [2,6,10,14,18,22,26,30,34,38,42,46,50,54,58,62]
-; AVX512VBMI-NEXT: vpermb %zmm0, %zmm1, %zmm0
-; AVX512VBMI-NEXT: # kill: def $xmm0 killed $xmm0 killed $zmm0
-; AVX512VBMI-NEXT: vzeroupper
-; AVX512VBMI-NEXT: retq
+; AVX512-LABEL: oddelts_v32i16_shuffle_v16i16_to_v16i8:
+; AVX512: # %bb.0:
+; AVX512-NEXT: vpsrld $16, %zmm0, %zmm0
+; AVX512-NEXT: vpmovdb %zmm0, %xmm0
+; AVX512-NEXT: vzeroupper
+; AVX512-NEXT: retq
%n0 = bitcast <32 x i16> %n2 to <64 x i8>
%p = shufflevector <64 x i8> %n0, <64 x i8> poison, <16 x i32> <i32 2, i32 6, i32 10, i32 14, i32 18, i32 22, i32 26, i32 30, i32 34, i32 38, i32 42, i32 46, i32 50, i32 54, i32 58, i32 62>
ret <16 x i8> %p
@@ -1548,3 +1491,5 @@ define <16 x i8> @oddelts_v32i16_trunc_v16i16_to_v16i8(<32 x i16> %n2) nounwind
%n1 = trunc <16 x i16> %n0 to <16 x i8>
ret <16 x i8> %n1
}
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; AVX512VBMI: {{.*}}
diff --git a/llvm/test/CodeGen/X86/shuffle-vs-trunc-512.ll b/llvm/test/CodeGen/X86/shuffle-vs-trunc-512.ll
index 41d5738c171e0c..445468d06fb042 100644
--- a/llvm/test/CodeGen/X86/shuffle-vs-trunc-512.ll
+++ b/llvm/test/CodeGen/X86/shuffle-vs-trunc-512.ll
@@ -389,57 +389,28 @@ define <32 x i8> @trunc_shuffle_v32i16_v32i8_ofs1(<32 x i16> %a0) {
; AVX512VL-FAST-PERLANE-NEXT: vpermq {{.*#+}} ymm0 = ymm0[0,2,1,3]
; AVX512VL-FAST-PERLANE-NEXT: retq
;
-; AVX512BW-FAST-ALL-LABEL: trunc_shuffle_v32i16_v32i8_ofs1:
-; AVX512BW-FAST-ALL: # %bb.0:
-; AVX512BW-FAST-ALL-NEXT: vpmovsxbq {{.*#+}} ymm1 = [0,2,9,11]
-; AVX512BW-FAST-ALL-NEXT: vextracti64x4 $1, %zmm0, %ymm2
-; AVX512BW-FAST-ALL-NEXT: vpshufb {{.*#+}} ymm2 = ymm2[u,u,u,u,u,u,u,u,1,3,5,7,9,11,13,15,u,u,u,u,u,u,u,u,17,19,21,23,25,27,29,31]
-; AVX512BW-FAST-ALL-NEXT: vpshufb {{.*#+}} ymm0 = ymm0[1,3,5,7,9,11,13,15,u,u,u,u,u,u,u,u,17,19,21,23,25,27,29,31,u,u,u,u,u,u,u,u]
-; AVX512BW-FAST-ALL-NEXT: vpermt2q %zmm2, %zmm1, %zmm0
-; AVX512BW-FAST-ALL-NEXT: # kill: def $ymm0 killed $ymm0 killed $zmm0
-; AVX512BW-FAST-ALL-NEXT: retq
-;
-; AVX512BW-FAST-PERLANE-LABEL: trunc_shuffle_v32i16_v32i8_ofs1:
-; AVX512BW-FAST-PERLANE: # %bb.0:
-; AVX512BW-FAST-PERLANE-NEXT: vextracti64x4 $1, %zmm0, %ymm1
-; AVX512BW-FAST-PERLANE-NEXT: vpbroadcastq {{.*#+}} ymm2 = [1,3,5,7,9,11,13,15,1,3,5,7,9,11,13,15,1,3,5,7,9,11,13,15,1,3,5,7,9,11,13,15]
-; AVX512BW-FAST-PERLANE-NEXT: vpshufb %ymm2, %ymm1, %ymm1
-; AVX512BW-FAST-PERLANE-NEXT: vpshufb %ymm2, %ymm0, %ymm0
-; AVX512BW-FAST-PERLANE-NEXT: vpblendd {{.*#+}} ymm0 = ymm0[0,1],ymm1[2,3],ymm0[4,5],ymm1[6,7]
-; AVX512BW-FAST-PERLANE-NEXT: vpermq {{.*#+}} ymm0 = ymm0[0,2,1,3]
-; AVX512BW-FAST-PERLANE-NEXT: retq
-;
-; AVX512BWVL-FAST-ALL-LABEL: trunc_shuffle_v32i16_v32i8_ofs1:
-; AVX512BWVL-FAST-ALL: # %bb.0:
-; AVX512BWVL-FAST-ALL-NEXT: vextracti64x4 $1, %zmm0, %ymm1
-; AVX512BWVL-FAST-ALL-NEXT: vpshufb {{.*#+}} ymm1 = ymm1[u,u,u,u,u,u,u,u,1,3,5,7,9,11,13,15,u,u,u,u,u,u,u,u,17,19,21,23,25,27,29,31]
-; AVX512BWVL-FAST-ALL-NEXT: vpshufb {{.*#+}} ymm2 = ymm0[1,3,5,7,9,11,13,15,u,u,u,u,u,u,u,u,17,19,21,23,25,27,29,31,u,u,u,u,u,u,u,u]
-; AVX512BWVL-FAST-ALL-NEXT: vpmovsxbq {{.*#+}} ymm0 = [0,2,5,7]
-; AVX512BWVL-FAST-ALL-NEXT: vpermi2q %ymm1, %ymm2, %ymm0
-; AVX512BWVL-FAST-ALL-NEXT: retq
+; AVX512BW-LABEL: trunc_shuffle_v32i16_v32i8_ofs1:
+; AVX512BW: # %bb.0:
+; AVX512BW-NEXT: vpsrlw $8, %zmm0, %zmm0
+; AVX512BW-NEXT: vpmovwb %zmm0, %ymm0
+; AVX512BW-NEXT: retq
;
-; AVX512BWVL-FAST-PERLANE-LABEL: trunc_shuffle_v32i16_v32i8_ofs1:
-; AVX512BWVL-FAST-PERLANE: # %bb.0:
-; AVX512BWVL-FAST-PERLANE-NEXT: vextracti64x4 $1, %zmm0, %ymm1
-; AVX512BWVL-FAST-PERLANE-NEXT: vpbroadcastq {{.*#+}} ymm2 = [1,3,5,7,9,11,13,15,1,3,5,7,9,11,13,15,1,3,5,7,9,11,13,15,1,3,5,7,9,11,13,15]
-; AVX512BWVL-FAST-PERLANE-NEXT: vpshufb %ymm2, %ymm1, %ymm1
-; AVX512BWVL-FAST-PERLANE-NEXT: vpshufb %ymm2, %ymm0, %ymm0
-; AVX512BWVL-FAST-PERLANE-NEXT: vpblendd {{.*#+}} ymm0 = ymm0[0,1],ymm1[2,3],ymm0[4,5],ymm1[6,7]
-; AVX512BWVL-FAST-PERLANE-NEXT: vpermq {{.*#+}} ymm0 = ymm0[0,2,1,3]
-; AVX512BWVL-FAST-PERLANE-NEXT: retq
+; AVX512BWVL-LABEL: trunc_shuffle_v32i16_v32i8_ofs1:
+; AVX512BWVL: # %bb.0:
+; AVX512BWVL-NEXT: vpsrlw $8, %zmm0, %zmm0
+; AVX512BWVL-NEXT: vpmovwb %zmm0, %ymm0
+; AVX512BWVL-NEXT: retq
;
; AVX512VBMI-LABEL: trunc_shuffle_v32i16_v32i8_ofs1:
; AVX512VBMI: # %bb.0:
-; AVX512VBMI-NEXT: vmovdqa {{.*#+}} ymm1 = [1,3,5,7,9,11,13,15,97,99,101,103,105,107,109,111,17,19,21,23,25,27,29,31,113,115,117,119,121,123,125,127]
-; AVX512VBMI-NEXT: vpermi2b %zmm0, %zmm0, %zmm1
-; AVX512VBMI-NEXT: vpermq {{.*#+}} ymm0 = ymm1[0,2,1,3]
+; AVX512VBMI-NEXT: vpsrlw $8, %zmm0, %zmm0
+; AVX512VBMI-NEXT: vpmovwb %zmm0, %ymm0
; AVX512VBMI-NEXT: retq
;
; AVX512VBMIVL-LABEL: trunc_shuffle_v32i16_v32i8_ofs1:
; AVX512VBMIVL: # %bb.0:
-; AVX512VBMIVL-NEXT: vmovdqa {{.*#+}} ymm1 = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63]
-; AVX512VBMIVL-NEXT: vpermb %zmm0, %zmm1, %zmm0
-; AVX512VBMIVL-NEXT: # kill: def $ymm0 killed $ymm0 killed $zmm0
+; AVX512VBMIVL-NEXT: vpsrlw $8, %zmm0, %zmm0
+; AVX512VBMIVL-NEXT: vpmovwb %zmm0, %ymm0
; AVX512VBMIVL-NEXT: retq
%bc = bitcast <32 x i16> %a0 to <64 x i8>
%res = shufflevector <64 x i8> %bc, <64 x i8> poison, <32 x i32> <i32 1, i32 3, i32 5, i32 7, i32 9, i32 11, i32 13, i32 15, i32 17, i32 19, i32 21, i32 23, i32 25, i32 27, i32 29, i32 31, i32 33, i32 35, i32 37, i32 39, i32 41, i32 43, i32 45, i32 47, i32 49, i32 51, i32 53, i32 55, i32 57, i32 59, i32 61, i32 63>
@@ -523,3 +494,8 @@ define <16 x i8> @trunc_v8i64_to_v8i8_return_v16i8(<8 x i64> %vec) nounwind {
ret <16 x i8> %result
}
+;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+; AVX512BW-FAST-ALL: {{.*}}
+; AVX512BW-FAST-PERLANE: {{.*}}
+; AVX512BWVL-FAST-ALL: {{.*}}
+; AVX512BWVL-FAST-PERLANE: {{.*}}
diff --git a/llvm/test/CodeGen/X86/x86-interleaved-access.ll b/llvm/test/CodeGen/X86/x86-interleaved-access.ll
index 49947eddc61b9d..cf2b1117581ddd 100644
--- a/llvm/test/CodeGen/X86/x86-interleaved-access.ll
+++ b/llvm/test/CodeGen/X86/x86-interleaved-access.ll
@@ -405,14 +405,13 @@ define <8 x i8> @interleaved_load_vf8_i8_stride4(ptr %ptr) nounwind {
; AVX512-NEXT: vmovdqu (%rdi), %ymm0
; AVX512-NEXT: vmovdqa 16(%rdi), %xmm1
; AVX512-NEXT: vpmovsxbw {{.*#+}} xmm2 = [3,7,11,15,7,15,6,7]
-; AVX512-NEXT: vpshufb %xmm2, %xmm1, %xmm3
+; AVX512-NEXT: vpshufb %xmm2, %xmm1, %xmm1
; AVX512-NEXT: vpshufb %xmm2, %xmm0, %xmm2
-; AVX512-NEXT: vpunpcklqdq {{.*#+}} xmm2 = xmm2[0],xmm3[0]
-; AVX512-NEXT: vpsrld $16, %xmm1, %xmm1
-; AVX512-NEXT: vpsrld $16, %xmm0, %xmm3
-; AVX512-NEXT: vpackusdw %xmm1, %xmm3, %xmm1
-; AVX512-NEXT: vpaddb %xmm1, %xmm2, %xmm1
+; AVX512-NEXT: vpunpcklqdq {{.*#+}} xmm1 = xmm2[0],xmm1[0]
; AVX512-NEXT: vmovdqu (%rdi), %ymm2
+; AVX512-NEXT: vpsrld $16, %ymm2, %ymm3
+; AVX512-NEXT: vpmovdw %zmm3, %ymm3
+; AVX512-NEXT: vpaddb %xmm3, %xmm1, %xmm1
; AVX512-NEXT: vpmovdw %zmm2, %ymm2
; AVX512-NEXT: vpsrlw $8, %ymm0, %ymm0
; AVX512-NEXT: vpmovwb %zmm0, %ymm0
More information about the llvm-commits
mailing list