1 ; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7 | FileCheck %s
3 ; Check that DAGCombiner correctly folds the following pairs of shuffles
4 ; using the following rules:
5 ; 1. shuffle(shuffle(x, y), undef) -> x
6 ; 2. shuffle(shuffle(x, y), undef) -> y
7 ; 3. shuffle(shuffle(x, y), undef) -> shuffle(x, undef)
8 ; 4. shuffle(shuffle(x, y), undef) -> shuffle(undef, y)
10 ; Rules 3. and 4. are used only if the resulting shuffle mask is legal.
12 define <4 x i32> @test1(<4 x i32> %A, <4 x i32> %B) {
13 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 0, i32 4, i32 3, i32 1>
14 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 2, i32 4, i32 0, i32 3>
23 define <4 x i32> @test2(<4 x i32> %A, <4 x i32> %B) {
24 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 0, i32 5, i32 2, i32 3>
25 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 2, i32 4, i32 0, i32 3>
34 define <4 x i32> @test3(<4 x i32> %A, <4 x i32> %B) {
35 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 0, i32 6, i32 2, i32 3>
36 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 2, i32 4, i32 0, i32 3>
45 define <4 x i32> @test4(<4 x i32> %A, <4 x i32> %B) {
46 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 0, i32 4, i32 7, i32 1>
47 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 4, i32 4, i32 0, i32 3>
56 define <4 x i32> @test5(<4 x i32> %A, <4 x i32> %B) {
57 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 5, i32 5, i32 2, i32 3>
58 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 2, i32 4, i32 4, i32 3>
67 define <4 x i32> @test6(<4 x i32> %A, <4 x i32> %B) {
68 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 0, i32 6, i32 2, i32 4>
69 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 2, i32 4, i32 0, i32 4>
78 define <4 x i32> @test7(<4 x i32> %A, <4 x i32> %B) {
79 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 0, i32 5, i32 2, i32 7>
80 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 0, i32 2, i32 0, i32 2>
89 define <4 x i32> @test8(<4 x i32> %A, <4 x i32> %B) {
90 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 4, i32 1, i32 6, i32 3>
91 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 1, i32 4, i32 3, i32 4>
100 define <4 x i32> @test9(<4 x i32> %A, <4 x i32> %B) {
101 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 1, i32 3, i32 2, i32 5>
102 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 0, i32 1, i32 4, i32 2>
107 ; CHECK: pshufd $-115
111 define <4 x i32> @test10(<4 x i32> %A, <4 x i32> %B) {
112 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 1, i32 1, i32 5, i32 5>
113 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 0, i32 4, i32 1, i32 4>
116 ; CHECK-LABEL: test10
122 define <4 x i32> @test11(<4 x i32> %A, <4 x i32> %B) {
123 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 1, i32 2, i32 5, i32 4>
124 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 0, i32 4, i32 1, i32 0>
127 ; CHECK-LABEL: test11
133 define <4 x i32> @test12(<4 x i32> %A, <4 x i32> %B) {
134 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 0, i32 0, i32 2, i32 4>
135 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 1, i32 4, i32 0, i32 4>
138 ; CHECK-LABEL: test12
144 ; The following pair of shuffles is folded into vector %A.
145 define <4 x i32> @test13(<4 x i32> %A, <4 x i32> %B) {
146 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 1, i32 4, i32 2, i32 6>
147 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 4, i32 0, i32 2, i32 4>
150 ; CHECK-LABEL: test13
155 ; The following pair of shuffles is folded into vector %B.
156 define <4 x i32> @test14(<4 x i32> %A, <4 x i32> %B) {
157 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 0, i32 6, i32 2, i32 4>
158 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 3, i32 4, i32 1, i32 4>
161 ; CHECK-LABEL: test14
166 ; Verify that we don't optimize the following cases. We expect more than one shuffle.
168 define <4 x i32> @test15(<4 x i32> %A, <4 x i32> %B) {
169 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 0, i32 4, i32 3, i32 1>
170 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 2, i32 1, i32 0, i32 3>
173 ; CHECK-LABEL: test15
175 ; CHECK-NEXT: pshufd $-58
179 define <4 x i32> @test16(<4 x i32> %A, <4 x i32> %B) {
180 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 0, i32 5, i32 2, i32 7>
181 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 2, i32 1, i32 0, i32 3>
184 ; CHECK-LABEL: test16
186 ; CHECK-NEXT: pshufd $-58
190 define <4 x i32> @test17(<4 x i32> %A, <4 x i32> %B) {
191 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 4, i32 1, i32 3, i32 1>
192 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 2, i32 1, i32 0, i32 3>
195 ; CHECK-LABEL: test17
197 ; CHECK-NEXT: pshufd $-58
201 define <4 x i32> @test18(<4 x i32> %A, <4 x i32> %B) {
202 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 4, i32 5, i32 2, i32 7>
203 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 1, i32 1, i32 0, i32 3>
206 ; CHECK-LABEL: test18
208 ; CHECK-NEXT: pshufd $-59
211 define <4 x i32> @test19(<4 x i32> %A, <4 x i32> %B) {
212 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 0, i32 4, i32 5, i32 6>
213 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 2, i32 0, i32 0, i32 0>
216 ; CHECK-LABEL: test19
217 ; CHECK: shufps $-104
218 ; CHECK-NEXT: pshufd $2
222 define <4 x i32> @test20(<4 x i32> %A, <4 x i32> %B) {
223 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 3, i32 2, i32 4, i32 4>
224 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 2, i32 1, i32 0, i32 3>
227 ; CHECK-LABEL: test20
229 ; CHECK-NEXT: pshufd $-58
233 define <4 x i32> @test21(<4 x i32> %A, <4 x i32> %B) {
234 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 4, i32 1, i32 3, i32 1>
235 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 0, i32 1, i32 0, i32 3>
238 ; CHECK-LABEL: test21
240 ; CHECK-NEXT: pshufd $-60
244 define <4 x i32> @test22(<4 x i32> %A, <4 x i32> %B) {
245 %1 = shufflevector <4 x i32> %A, <4 x i32> %B, <4 x i32> <i32 4, i32 5, i32 2, i32 7>
246 %2 = shufflevector <4 x i32> %1, <4 x i32> undef, <4 x i32> <i32 1, i32 1, i32 1, i32 3>
249 ; CHECK-LABEL: test22
251 ; CHECK-NEXT: pshufd $-43