blob: 6af0db8e5a442bfa461e934052c420ff9c26373a [file] [log] [blame]
Zvi Rackover38ba75c2017-03-31 07:46:02 +00001; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instsimplify -S | FileCheck %s
3
Zvi Rackovere4799802017-04-02 10:42:21 +00004define <4 x i32> @const_folding(<4 x i32> %x) {
5; CHECK-LABEL: @const_folding(
Zvi Rackover8f460652017-04-03 22:05:30 +00006; CHECK-NEXT: ret <4 x i32> zeroinitializer
Zvi Rackovere4799802017-04-02 10:42:21 +00007;
8 %shuf = shufflevector <4 x i32> %x, <4 x i32> zeroinitializer, <4 x i32> <i32 5, i32 4, i32 5, i32 4>
9 ret <4 x i32> %shuf
10}
11
Zvi Rackover8f460652017-04-03 22:05:30 +000012define <4 x i32> @const_folding1(<4 x i32> %x) {
13; CHECK-LABEL: @const_folding1(
14; CHECK-NEXT: ret <4 x i32> <i32 5, i32 5, i32 5, i32 5>
15;
16 %shuf = shufflevector <4 x i32> <i32 5, i32 4, i32 5, i32 4>, <4 x i32> %x, <4 x i32> zeroinitializer
17 ret <4 x i32> %shuf
18}
19
20define <4 x i32> @const_folding_negative(<3 x i32> %x) {
21; CHECK-LABEL: @const_folding_negative(
22; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <3 x i32> [[X:%.*]], <3 x i32> zeroinitializer, <4 x i32> <i32 2, i32 4, i32 5, i32 4>
23; CHECK-NEXT: ret <4 x i32> [[SHUF]]
24;
25 %shuf = shufflevector <3 x i32> %x, <3 x i32> zeroinitializer, <4 x i32> <i32 2, i32 4, i32 5, i32 4>
26 ret <4 x i32> %shuf
27}
28
Zvi Rackover38ba75c2017-03-31 07:46:02 +000029define <4 x i32> @splat_operand(<4 x i32> %x) {
30; CHECK-LABEL: @splat_operand(
31; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer
Zvi Rackover30efd24d2017-04-11 21:37:02 +000032; CHECK-NEXT: ret <4 x i32> [[SPLAT]]
Zvi Rackover38ba75c2017-03-31 07:46:02 +000033;
34 %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer
35 %shuf = shufflevector <4 x i32> %splat, <4 x i32> undef, <4 x i32> <i32 0, i32 3, i32 2, i32 1>
36 ret <4 x i32> %shuf
37}
38
Zvi Rackover30efd24d2017-04-11 21:37:02 +000039define <4 x i32> @splat_operand1(<4 x i32> %x, <4 x i32> %y) {
40; CHECK-LABEL: @splat_operand1(
41; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> [[Y:%.*]], <4 x i32> zeroinitializer
42; CHECK-NEXT: ret <4 x i32> [[SPLAT]]
43;
44 %splat = shufflevector <4 x i32> %x, <4 x i32> %y, <4 x i32> zeroinitializer
45 %shuf = shufflevector <4 x i32> %splat, <4 x i32> undef, <4 x i32> <i32 0, i32 3, i32 2, i32 1>
46 ret <4 x i32> %shuf
47}
48
49define <4 x i32> @splat_operand2(<4 x i32> %x, <4 x i32> %y) {
50; CHECK-LABEL: @splat_operand2(
51; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer
52; CHECK-NEXT: ret <4 x i32> [[SPLAT]]
53;
54 %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer
55 %shuf = shufflevector <4 x i32> %splat, <4 x i32> %y, <4 x i32> <i32 0, i32 3, i32 2, i32 1>
56 ret <4 x i32> %shuf
57}
58
59define <4 x i32> @splat_operand3(<4 x i32> %x) {
60; CHECK-LABEL: @splat_operand3(
61; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer
62; CHECK-NEXT: ret <4 x i32> [[SPLAT]]
63;
64 %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer
65 %shuf = shufflevector <4 x i32> zeroinitializer, <4 x i32> %splat, <4 x i32> <i32 7, i32 6, i32 5, i32 5>
66 ret <4 x i32> %shuf
67}
68
69define <8 x i32> @splat_operand_negative(<4 x i32> %x) {
70; CHECK-LABEL: @splat_operand_negative(
71; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer
72; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[SPLAT]], <4 x i32> undef, <8 x i32> <i32 0, i32 3, i32 2, i32 1, i32 undef, i32 undef, i32 undef, i32 undef>
73; CHECK-NEXT: ret <8 x i32> [[SHUF]]
74;
75 %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer
76 %shuf = shufflevector <4 x i32> %splat, <4 x i32> undef, <8 x i32> <i32 0, i32 3, i32 2, i32 1, i32 undef, i32 undef, i32 undef, i32 undef>
77 ret <8 x i32> %shuf
78}
79
80define <4 x i32> @splat_operand_negative2(<4 x i32> %x, <4 x i32> %y) {
81; CHECK-LABEL: @splat_operand_negative2(
82; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer
83; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[SPLAT]], <4 x i32> [[Y:%.*]], <4 x i32> <i32 0, i32 3, i32 4, i32 1>
84; CHECK-NEXT: ret <4 x i32> [[SHUF]]
85;
86 %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer
87 %shuf = shufflevector <4 x i32> %splat, <4 x i32> %y, <4 x i32> <i32 0, i32 3, i32 4, i32 1>
88 ret <4 x i32> %shuf
89}
90
91define <4 x i32> @splat_operand_negative3(<4 x i32> %x, <4 x i32> %y) {
92; CHECK-LABEL: @splat_operand_negative3(
93; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> zeroinitializer
94; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[Y:%.*]], <4 x i32> [[SPLAT]], <4 x i32> <i32 0, i32 3, i32 4, i32 1>
95; CHECK-NEXT: ret <4 x i32> [[SHUF]]
96;
97 %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> zeroinitializer
98 %shuf = shufflevector <4 x i32> %y, <4 x i32> %splat, <4 x i32> <i32 0, i32 3, i32 4, i32 1>
99 ret <4 x i32> %shuf
100}
101
102define <4 x i32> @splat_operand_negative4(<4 x i32> %x) {
103; CHECK-LABEL: @splat_operand_negative4(
104; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> <i32 2, i32 undef, i32 2, i32 undef>
105; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[SPLAT]], <4 x i32> undef, <4 x i32> <i32 0, i32 2, i32 undef, i32 undef>
106; CHECK-NEXT: ret <4 x i32> [[SHUF]]
107;
108 %splat = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> <i32 2, i32 undef, i32 2, i32 undef>
109 %shuf = shufflevector <4 x i32> %splat, <4 x i32> undef, <4 x i32> <i32 0, i32 2, i32 undef, i32 undef>
110 ret <4 x i32> %shuf
111}
112
Zvi Rackover38ba75c2017-03-31 07:46:02 +0000113define <4 x i32> @undef_mask(<4 x i32> %x) {
114; CHECK-LABEL: @undef_mask(
Zvi Rackover8f460652017-04-03 22:05:30 +0000115; CHECK-NEXT: ret <4 x i32> undef
Zvi Rackover38ba75c2017-03-31 07:46:02 +0000116;
117 %shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> undef
118 ret <4 x i32> %shuf
119}
120
Zvi Rackover4086e132017-04-30 06:06:26 +0000121define <4 x i32> @undef_mask_1(<4 x i32> %x, <4 x i32> %y) {
122; CHECK-LABEL: @undef_mask_1(
123; CHECK-NEXT: ret <4 x i32> undef
124;
125 %shuf = shufflevector <4 x i32> %x, <4 x i32> %y, <4 x i32> undef
126 ret <4 x i32> %shuf
127}
128
Zvi Rackover38ba75c2017-03-31 07:46:02 +0000129define <4 x i32> @identity_mask_0(<4 x i32> %x) {
130; CHECK-LABEL: @identity_mask_0(
Sanjay Patela3c297d2017-04-19 16:48:22 +0000131; CHECK-NEXT: ret <4 x i32> [[X:%.*]]
Zvi Rackover38ba75c2017-03-31 07:46:02 +0000132;
133 %shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
134 ret <4 x i32> %shuf
135}
136
137define <4 x i32> @identity_mask_1(<4 x i32> %x) {
138; CHECK-LABEL: @identity_mask_1(
Sanjay Patela3c297d2017-04-19 16:48:22 +0000139; CHECK-NEXT: ret <4 x i32> [[X:%.*]]
Zvi Rackover38ba75c2017-03-31 07:46:02 +0000140;
141 %shuf = shufflevector <4 x i32> undef, <4 x i32> %x, <4 x i32> <i32 4, i32 5, i32 6, i32 7>
142 ret <4 x i32> %shuf
143}
144
145define <4 x i32> @pseudo_identity_mask(<4 x i32> %x) {
146; CHECK-LABEL: @pseudo_identity_mask(
Sanjay Patela3c297d2017-04-19 16:48:22 +0000147; CHECK-NEXT: ret <4 x i32> [[X:%.*]]
Zvi Rackover38ba75c2017-03-31 07:46:02 +0000148;
149 %shuf = shufflevector <4 x i32> %x, <4 x i32> %x, <4 x i32> <i32 0, i32 1, i32 2, i32 7>
150 ret <4 x i32> %shuf
151}
152
Sanjay Patela3c297d2017-04-19 16:48:22 +0000153define <4 x i32> @not_identity_mask(<4 x i32> %x) {
154; CHECK-LABEL: @not_identity_mask(
155; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> [[X]], <4 x i32> <i32 0, i32 1, i32 2, i32 6>
156; CHECK-NEXT: ret <4 x i32> [[SHUF]]
157;
158 %shuf = shufflevector <4 x i32> %x, <4 x i32> %x, <4 x i32> <i32 0, i32 1, i32 2, i32 6>
159 ret <4 x i32> %shuf
160}
161
162; TODO: Should we simplify if the mask has an undef element?
163
164define <4 x i32> @possible_identity_mask(<4 x i32> %x) {
165; CHECK-LABEL: @possible_identity_mask(
166; CHECK-NEXT: [[SHUF:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
167; CHECK-NEXT: ret <4 x i32> [[SHUF]]
168;
169 %shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 undef>
170 ret <4 x i32> %shuf
171}
172
Zvi Rackover38ba75c2017-03-31 07:46:02 +0000173define <4 x i32> @const_operand(<4 x i32> %x) {
174; CHECK-LABEL: @const_operand(
Zvi Rackover8f460652017-04-03 22:05:30 +0000175; CHECK-NEXT: ret <4 x i32> <i32 42, i32 45, i32 44, i32 43>
Zvi Rackover38ba75c2017-03-31 07:46:02 +0000176;
177 %shuf = shufflevector <4 x i32> <i32 42, i32 43, i32 44, i32 45>, <4 x i32> %x, <4 x i32> <i32 0, i32 3, i32 2, i32 1>
178 ret <4 x i32> %shuf
179}
180
181define <4 x i32> @merge(<4 x i32> %x) {
182; CHECK-LABEL: @merge(
Sanjay Patela3c297d2017-04-19 16:48:22 +0000183; CHECK-NEXT: ret <4 x i32> [[X:%.*]]
Zvi Rackover38ba75c2017-03-31 07:46:02 +0000184;
185 %lower = shufflevector <4 x i32> %x, <4 x i32> undef, <2 x i32> <i32 1, i32 0>
186 %upper = shufflevector <4 x i32> %x, <4 x i32> undef, <2 x i32> <i32 2, i32 3>
187 %merged = shufflevector <2 x i32> %upper, <2 x i32> %lower, <4 x i32> <i32 3, i32 2, i32 0, i32 1>
188 ret <4 x i32> %merged
189}
Sanjay Patelf0cb5a82017-04-11 20:54:57 +0000190
Sanjay Patela3c297d2017-04-19 16:48:22 +0000191; This crosses lanes from the source op.
192
193define <4 x i32> @not_merge(<4 x i32> %x) {
194; CHECK-LABEL: @not_merge(
195; CHECK-NEXT: [[L:%.*]] = shufflevector <4 x i32> [[X:%.*]], <4 x i32> undef, <2 x i32> <i32 0, i32 1>
196; CHECK-NEXT: [[U:%.*]] = shufflevector <4 x i32> [[X]], <4 x i32> undef, <2 x i32> <i32 2, i32 3>
197; CHECK-NEXT: [[MERGED:%.*]] = shufflevector <2 x i32> [[U]], <2 x i32> [[L]], <4 x i32> <i32 3, i32 2, i32 0, i32 1>
198; CHECK-NEXT: ret <4 x i32> [[MERGED]]
199;
200 %l = shufflevector <4 x i32> %x, <4 x i32> undef, <2 x i32> <i32 0, i32 1>
201 %u = shufflevector <4 x i32> %x, <4 x i32> undef, <2 x i32> <i32 2, i32 3>
202 %merged = shufflevector <2 x i32> %u, <2 x i32> %l, <4 x i32> <i32 3, i32 2, i32 0, i32 1>
203 ret <4 x i32> %merged
204}
205
Sanjay Patelf0cb5a82017-04-11 20:54:57 +0000206define <8 x double> @extract_and_concat(<8 x double> %x) {
207; CHECK-LABEL: @extract_and_concat(
Sanjay Patela3c297d2017-04-19 16:48:22 +0000208; CHECK-NEXT: ret <8 x double> [[X:%.*]]
Sanjay Patelf0cb5a82017-04-11 20:54:57 +0000209;
210 %s1 = shufflevector <8 x double> %x, <8 x double> undef, <2 x i32> <i32 0, i32 1>
211 %s2 = shufflevector <8 x double> %x, <8 x double> undef, <2 x i32> <i32 2, i32 3>
212 %s3 = shufflevector <8 x double> %x, <8 x double> undef, <2 x i32> <i32 4, i32 5>
213 %s4 = shufflevector <8 x double> %x, <8 x double> undef, <2 x i32> <i32 6, i32 7>
214 %s5 = shufflevector <2 x double> %s1, <2 x double> %s2, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
215 %s6 = shufflevector <2 x double> %s3, <2 x double> %s4, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
216 %s7 = shufflevector <4 x double> %s5, <4 x double> %s6, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
217 ret <8 x double> %s7
218}
219
220; This case has intermediate lane crossings.
221
222define <8 x i64> @PR30630(<8 x i64> %x) {
223; CHECK-LABEL: @PR30630(
Sanjay Patela3c297d2017-04-19 16:48:22 +0000224; CHECK-NEXT: ret <8 x i64> [[X:%.*]]
Sanjay Patelf0cb5a82017-04-11 20:54:57 +0000225;
226 %s1 = shufflevector <8 x i64> %x, <8 x i64> undef, <2 x i32> <i32 0, i32 4>
227 %s2 = shufflevector <8 x i64> %x, <8 x i64> undef, <2 x i32> <i32 1, i32 5>
228 %s3 = shufflevector <8 x i64> %x, <8 x i64> undef, <2 x i32> <i32 2, i32 6>
229 %s4 = shufflevector <8 x i64> %x, <8 x i64> undef, <2 x i32> <i32 3, i32 7>
230 %s5 = shufflevector <2 x i64> %s1, <2 x i64> %s2, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
231 %s6 = shufflevector <2 x i64> %s3, <2 x i64> %s4, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
232 %s7 = shufflevector <4 x i64> %s5, <4 x i64> %s6, <8 x i32> <i32 0, i32 2, i32 4, i32 6, i32 1, i32 3, i32 5, i32 7>
233 ret <8 x i64> %s7
234}
235