1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mattr=avx2 | FileCheck %s
4 ; Test that we correctly fold a shuffle that performs a swizzle of another
5 ; shuffle node according to the rule
6 ; shuffle (shuffle (x, undef, M0), undef, M1) -> shuffle(x, undef, M2)
8 ; We only do this if the resulting mask is legal to avoid introducing an
9 ; illegal shuffle that is expanded into a sub-optimal sequence of instructions
10 ; during lowering stage.
12 ; Check that we produce a single vector permute / shuffle in all cases.
14 define <8 x i32> @swizzle_1(<8 x i32> %v) {
15 ; CHECK-LABEL: swizzle_1:
17 ; CHECK-NEXT: vmovaps {{.*#+}} ymm1 = [1,3,2,0,4,5,6,7]
18 ; CHECK-NEXT: vpermps %ymm0, %ymm1, %ymm0
20 %1 = shufflevector <8 x i32> %v, <8 x i32> undef, <8 x i32> <i32 3, i32 1, i32 2, i32 0, i32 7, i32 5, i32 6, i32 4>
21 %2 = shufflevector <8 x i32> %1, <8 x i32> undef, <8 x i32> <i32 1, i32 0, i32 2, i32 3, i32 7, i32 5, i32 6, i32 4>
25 define <8 x i32> @swizzle_2(<8 x i32> %v) {
26 ; CHECK-LABEL: swizzle_2:
28 ; CHECK-NEXT: vpermilps {{.*#+}} ymm0 = ymm0[2,3,0,1,6,7,4,5]
30 %1 = shufflevector <8 x i32> %v, <8 x i32> undef, <8 x i32> <i32 6, i32 7, i32 4, i32 5, i32 0, i32 1, i32 2, i32 3>
31 %2 = shufflevector <8 x i32> %1, <8 x i32> undef, <8 x i32> <i32 6, i32 7, i32 4, i32 5, i32 0, i32 1, i32 2, i32 3>
35 define <8 x i32> @swizzle_3(<8 x i32> %v) {
36 ; CHECK-LABEL: swizzle_3:
38 ; CHECK-NEXT: vpermilps {{.*#+}} ymm0 = ymm0[2,3,0,1,6,7,4,5]
40 %1 = shufflevector <8 x i32> %v, <8 x i32> undef, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 2, i32 3, i32 0, i32 1>
41 %2 = shufflevector <8 x i32> %1, <8 x i32> undef, <8 x i32> <i32 4, i32 5, i32 6, i32 7, i32 2, i32 3, i32 0, i32 1>
45 define <8 x i32> @swizzle_4(<8 x i32> %v) {
46 ; CHECK-LABEL: swizzle_4:
48 ; CHECK-NEXT: vmovaps {{.*#+}} ymm1 = [3,1,2,0,6,5,4,7]
49 ; CHECK-NEXT: vpermps %ymm0, %ymm1, %ymm0
51 %1 = shufflevector <8 x i32> %v, <8 x i32> undef, <8 x i32> <i32 4, i32 7, i32 5, i32 6, i32 3, i32 2, i32 0, i32 1>
52 %2 = shufflevector <8 x i32> %1, <8 x i32> undef, <8 x i32> <i32 4, i32 7, i32 5, i32 6, i32 3, i32 2, i32 0, i32 1>
56 define <8 x i32> @swizzle_5(<8 x i32> %v) {
57 ; CHECK-LABEL: swizzle_5:
59 ; CHECK-NEXT: vmovaps {{.*#+}} ymm1 = [3,0,1,2,7,6,4,5]
60 ; CHECK-NEXT: vpermps %ymm0, %ymm1, %ymm0
62 %1 = shufflevector <8 x i32> %v, <8 x i32> undef, <8 x i32> <i32 7, i32 4, i32 6, i32 5, i32 0, i32 2, i32 1, i32 3>
63 %2 = shufflevector <8 x i32> %1, <8 x i32> undef, <8 x i32> <i32 7, i32 4, i32 6, i32 5, i32 0, i32 2, i32 1, i32 3>
67 define <8 x i32> @swizzle_6(<8 x i32> %v) {
68 ; CHECK-LABEL: swizzle_6:
70 ; CHECK-NEXT: vmovaps {{.*#+}} ymm1 = [3,1,0,2,4,5,6,7]
71 ; CHECK-NEXT: vpermps %ymm0, %ymm1, %ymm0
73 %1 = shufflevector <8 x i32> %v, <8 x i32> undef, <8 x i32> <i32 2, i32 1, i32 3, i32 0, i32 4, i32 7, i32 6, i32 5>
74 %2 = shufflevector <8 x i32> %1, <8 x i32> undef, <8 x i32> <i32 2, i32 1, i32 3, i32 0, i32 4, i32 7, i32 6, i32 5>
78 define <8 x i32> @swizzle_7(<8 x i32> %v) {
79 ; CHECK-LABEL: swizzle_7:
81 ; CHECK-NEXT: vmovaps {{.*#+}} ymm1 = [0,2,3,1,4,5,6,7]
82 ; CHECK-NEXT: vpermps %ymm0, %ymm1, %ymm0
84 %1 = shufflevector <8 x i32> %v, <8 x i32> undef, <8 x i32> <i32 0, i32 3, i32 1, i32 2, i32 5, i32 4, i32 6, i32 7>
85 %2 = shufflevector <8 x i32> %1, <8 x i32> undef, <8 x i32> <i32 0, i32 3, i32 1, i32 2, i32 5, i32 4, i32 6, i32 7>