blob: 7c7d654599386c99c199ba8d06d20a179ddfb36b [file] [log] [blame]
Tim Northover5896b062014-05-16 09:42:04 +00001; RUN: llc -verify-machineinstrs %s -o - -mtriple=arm64-apple-ios7.0 | FileCheck %s
Tim Northovere0e3aef2013-01-31 12:12:40 +00002
3@var32 = global i32 0
4@var64 = global i64 0
5
6define void @test_lsl_arith(i32 %lhs32, i32 %rhs32, i64 %lhs64, i64 %rhs64) {
Stephen Linf799e3f2013-07-13 20:38:47 +00007; CHECK-LABEL: test_lsl_arith:
Tim Northovere0e3aef2013-01-31 12:12:40 +00008
David Blaikiea79ac142015-02-27 21:17:42 +00009 %rhs1 = load volatile i32, i32* @var32
Tim Northovere0e3aef2013-01-31 12:12:40 +000010 %shift1 = shl i32 %rhs1, 18
11 %val1 = add i32 %lhs32, %shift1
12 store volatile i32 %val1, i32* @var32
13; CHECK: add {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, lsl #18
14
David Blaikiea79ac142015-02-27 21:17:42 +000015 %rhs2 = load volatile i32, i32* @var32
Tim Northovere0e3aef2013-01-31 12:12:40 +000016 %shift2 = shl i32 %rhs2, 31
17 %val2 = add i32 %shift2, %lhs32
18 store volatile i32 %val2, i32* @var32
19; CHECK: add {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, lsl #31
20
David Blaikiea79ac142015-02-27 21:17:42 +000021 %rhs3 = load volatile i32, i32* @var32
Tim Northovere0e3aef2013-01-31 12:12:40 +000022 %shift3 = shl i32 %rhs3, 5
23 %val3 = sub i32 %lhs32, %shift3
24 store volatile i32 %val3, i32* @var32
25; CHECK: sub {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, lsl #5
26
27; Subtraction is not commutative!
David Blaikiea79ac142015-02-27 21:17:42 +000028 %rhs4 = load volatile i32, i32* @var32
Tim Northovere0e3aef2013-01-31 12:12:40 +000029 %shift4 = shl i32 %rhs4, 19
30 %val4 = sub i32 %shift4, %lhs32
31 store volatile i32 %val4, i32* @var32
32; CHECK-NOT: sub {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, lsl #19
33
David Blaikiea79ac142015-02-27 21:17:42 +000034 %lhs4a = load volatile i32, i32* @var32
Tim Northovere0e3aef2013-01-31 12:12:40 +000035 %shift4a = shl i32 %lhs4a, 15
36 %val4a = sub i32 0, %shift4a
37 store volatile i32 %val4a, i32* @var32
Tim Northover5896b062014-05-16 09:42:04 +000038; CHECK: neg {{w[0-9]+}}, {{w[0-9]+}}, lsl #15
Tim Northovere0e3aef2013-01-31 12:12:40 +000039
David Blaikiea79ac142015-02-27 21:17:42 +000040 %rhs5 = load volatile i64, i64* @var64
Tim Northovere0e3aef2013-01-31 12:12:40 +000041 %shift5 = shl i64 %rhs5, 18
42 %val5 = add i64 %lhs64, %shift5
43 store volatile i64 %val5, i64* @var64
44; CHECK: add {{x[0-9]+}}, {{x[0-9]+}}, {{x[0-9]+}}, lsl #18
45
David Blaikiea79ac142015-02-27 21:17:42 +000046 %rhs6 = load volatile i64, i64* @var64
Tim Northovere0e3aef2013-01-31 12:12:40 +000047 %shift6 = shl i64 %rhs6, 31
48 %val6 = add i64 %shift6, %lhs64
49 store volatile i64 %val6, i64* @var64
50; CHECK: add {{x[0-9]+}}, {{x[0-9]+}}, {{x[0-9]+}}, lsl #31
51
David Blaikiea79ac142015-02-27 21:17:42 +000052 %rhs7 = load volatile i64, i64* @var64
Tim Northovere0e3aef2013-01-31 12:12:40 +000053 %shift7 = shl i64 %rhs7, 5
54 %val7 = sub i64 %lhs64, %shift7
55 store volatile i64 %val7, i64* @var64
56; CHECK: sub {{x[0-9]+}}, {{x[0-9]+}}, {{x[0-9]+}}, lsl #5
57
58; Subtraction is not commutative!
David Blaikiea79ac142015-02-27 21:17:42 +000059 %rhs8 = load volatile i64, i64* @var64
Tim Northovere0e3aef2013-01-31 12:12:40 +000060 %shift8 = shl i64 %rhs8, 19
61 %val8 = sub i64 %shift8, %lhs64
62 store volatile i64 %val8, i64* @var64
63; CHECK-NOT: sub {{x[0-9]+}}, {{x[0-9]+}}, {{x[0-9]+}}, lsl #19
64
David Blaikiea79ac142015-02-27 21:17:42 +000065 %lhs8a = load volatile i64, i64* @var64
Tim Northovere0e3aef2013-01-31 12:12:40 +000066 %shift8a = shl i64 %lhs8a, 60
67 %val8a = sub i64 0, %shift8a
68 store volatile i64 %val8a, i64* @var64
Tim Northover5896b062014-05-16 09:42:04 +000069; CHECK: neg {{x[0-9]+}}, {{x[0-9]+}}, lsl #60
Tim Northovere0e3aef2013-01-31 12:12:40 +000070
71 ret void
72; CHECK: ret
73}
74
75define void @test_lsr_arith(i32 %lhs32, i32 %rhs32, i64 %lhs64, i64 %rhs64) {
Stephen Linf799e3f2013-07-13 20:38:47 +000076; CHECK-LABEL: test_lsr_arith:
Tim Northovere0e3aef2013-01-31 12:12:40 +000077
78 %shift1 = lshr i32 %rhs32, 18
79 %val1 = add i32 %lhs32, %shift1
80 store volatile i32 %val1, i32* @var32
81; CHECK: add {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, lsr #18
82
83 %shift2 = lshr i32 %rhs32, 31
84 %val2 = add i32 %shift2, %lhs32
85 store volatile i32 %val2, i32* @var32
86; CHECK: add {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, lsr #31
87
88 %shift3 = lshr i32 %rhs32, 5
89 %val3 = sub i32 %lhs32, %shift3
90 store volatile i32 %val3, i32* @var32
91; CHECK: sub {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, lsr #5
92
93; Subtraction is not commutative!
94 %shift4 = lshr i32 %rhs32, 19
95 %val4 = sub i32 %shift4, %lhs32
96 store volatile i32 %val4, i32* @var32
97; CHECK-NOT: sub {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, lsr #19
98
99 %shift4a = lshr i32 %lhs32, 15
100 %val4a = sub i32 0, %shift4a
101 store volatile i32 %val4a, i32* @var32
Tim Northover5896b062014-05-16 09:42:04 +0000102; CHECK: neg {{w[0-9]+}}, {{w[0-9]+}}, lsr #15
Tim Northovere0e3aef2013-01-31 12:12:40 +0000103
104 %shift5 = lshr i64 %rhs64, 18
105 %val5 = add i64 %lhs64, %shift5
106 store volatile i64 %val5, i64* @var64
107; CHECK: add {{x[0-9]+}}, {{x[0-9]+}}, {{x[0-9]+}}, lsr #18
108
109 %shift6 = lshr i64 %rhs64, 31
110 %val6 = add i64 %shift6, %lhs64
111 store volatile i64 %val6, i64* @var64
112; CHECK: add {{x[0-9]+}}, {{x[0-9]+}}, {{x[0-9]+}}, lsr #31
113
114 %shift7 = lshr i64 %rhs64, 5
115 %val7 = sub i64 %lhs64, %shift7
116 store volatile i64 %val7, i64* @var64
117; CHECK: sub {{x[0-9]+}}, {{x[0-9]+}}, {{x[0-9]+}}, lsr #5
118
119; Subtraction is not commutative!
120 %shift8 = lshr i64 %rhs64, 19
121 %val8 = sub i64 %shift8, %lhs64
122 store volatile i64 %val8, i64* @var64
123; CHECK-NOT: sub {{x[0-9]+}}, {{x[0-9]+}}, {{x[0-9]+}}, lsr #19
124
125 %shift8a = lshr i64 %lhs64, 45
126 %val8a = sub i64 0, %shift8a
127 store volatile i64 %val8a, i64* @var64
Tim Northover5896b062014-05-16 09:42:04 +0000128; CHECK: neg {{x[0-9]+}}, {{x[0-9]+}}, lsr #45
Tim Northovere0e3aef2013-01-31 12:12:40 +0000129
130 ret void
131; CHECK: ret
132}
133
134define void @test_asr_arith(i32 %lhs32, i32 %rhs32, i64 %lhs64, i64 %rhs64) {
Stephen Linf799e3f2013-07-13 20:38:47 +0000135; CHECK-LABEL: test_asr_arith:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000136
137 %shift1 = ashr i32 %rhs32, 18
138 %val1 = add i32 %lhs32, %shift1
139 store volatile i32 %val1, i32* @var32
140; CHECK: add {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, asr #18
141
142 %shift2 = ashr i32 %rhs32, 31
143 %val2 = add i32 %shift2, %lhs32
144 store volatile i32 %val2, i32* @var32
145; CHECK: add {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, asr #31
146
147 %shift3 = ashr i32 %rhs32, 5
148 %val3 = sub i32 %lhs32, %shift3
149 store volatile i32 %val3, i32* @var32
150; CHECK: sub {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, asr #5
151
152; Subtraction is not commutative!
153 %shift4 = ashr i32 %rhs32, 19
154 %val4 = sub i32 %shift4, %lhs32
155 store volatile i32 %val4, i32* @var32
156; CHECK-NOT: sub {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}, asr #19
157
158 %shift4a = ashr i32 %lhs32, 15
159 %val4a = sub i32 0, %shift4a
160 store volatile i32 %val4a, i32* @var32
Tim Northover5896b062014-05-16 09:42:04 +0000161; CHECK: neg {{w[0-9]+}}, {{w[0-9]+}}, asr #15
Tim Northovere0e3aef2013-01-31 12:12:40 +0000162
163 %shift5 = ashr i64 %rhs64, 18
164 %val5 = add i64 %lhs64, %shift5
165 store volatile i64 %val5, i64* @var64
166; CHECK: add {{x[0-9]+}}, {{x[0-9]+}}, {{x[0-9]+}}, asr #18
167
168 %shift6 = ashr i64 %rhs64, 31
169 %val6 = add i64 %shift6, %lhs64
170 store volatile i64 %val6, i64* @var64
171; CHECK: add {{x[0-9]+}}, {{x[0-9]+}}, {{x[0-9]+}}, asr #31
172
173 %shift7 = ashr i64 %rhs64, 5
174 %val7 = sub i64 %lhs64, %shift7
175 store volatile i64 %val7, i64* @var64
176; CHECK: sub {{x[0-9]+}}, {{x[0-9]+}}, {{x[0-9]+}}, asr #5
177
178; Subtraction is not commutative!
179 %shift8 = ashr i64 %rhs64, 19
180 %val8 = sub i64 %shift8, %lhs64
181 store volatile i64 %val8, i64* @var64
182; CHECK-NOT: sub {{x[0-9]+}}, {{x[0-9]+}}, {{x[0-9]+}}, asr #19
183
184 %shift8a = ashr i64 %lhs64, 45
185 %val8a = sub i64 0, %shift8a
186 store volatile i64 %val8a, i64* @var64
Tim Northover5896b062014-05-16 09:42:04 +0000187; CHECK: neg {{x[0-9]+}}, {{x[0-9]+}}, asr #45
Tim Northovere0e3aef2013-01-31 12:12:40 +0000188
189 ret void
190; CHECK: ret
191}
192
Matthias Braun8ab86902015-02-05 23:52:14 +0000193define void @test_cmp(i32 %lhs32, i32 %rhs32, i64 %lhs64, i64 %rhs64, i32 %v) {
Stephen Linf799e3f2013-07-13 20:38:47 +0000194; CHECK-LABEL: test_cmp:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000195
196 %shift1 = shl i32 %rhs32, 13
197 %tst1 = icmp uge i32 %lhs32, %shift1
198 br i1 %tst1, label %t2, label %end
199; CHECK: cmp {{w[0-9]+}}, {{w[0-9]+}}, lsl #13
200
201t2:
Matthias Braun8ab86902015-02-05 23:52:14 +0000202 store volatile i32 %v, i32* @var32
Tim Northovere0e3aef2013-01-31 12:12:40 +0000203 %shift2 = lshr i32 %rhs32, 20
204 %tst2 = icmp ne i32 %lhs32, %shift2
205 br i1 %tst2, label %t3, label %end
206; CHECK: cmp {{w[0-9]+}}, {{w[0-9]+}}, lsr #20
207
208t3:
Matthias Braun8ab86902015-02-05 23:52:14 +0000209 store volatile i32 %v, i32* @var32
Tim Northovere0e3aef2013-01-31 12:12:40 +0000210 %shift3 = ashr i32 %rhs32, 9
211 %tst3 = icmp ne i32 %lhs32, %shift3
212 br i1 %tst3, label %t4, label %end
213; CHECK: cmp {{w[0-9]+}}, {{w[0-9]+}}, asr #9
214
215t4:
Matthias Braun8ab86902015-02-05 23:52:14 +0000216 store volatile i32 %v, i32* @var32
Tim Northovere0e3aef2013-01-31 12:12:40 +0000217 %shift4 = shl i64 %rhs64, 43
218 %tst4 = icmp uge i64 %lhs64, %shift4
219 br i1 %tst4, label %t5, label %end
220; CHECK: cmp {{x[0-9]+}}, {{x[0-9]+}}, lsl #43
221
222t5:
Matthias Braun8ab86902015-02-05 23:52:14 +0000223 store volatile i32 %v, i32* @var32
Tim Northovere0e3aef2013-01-31 12:12:40 +0000224 %shift5 = lshr i64 %rhs64, 20
225 %tst5 = icmp ne i64 %lhs64, %shift5
226 br i1 %tst5, label %t6, label %end
227; CHECK: cmp {{x[0-9]+}}, {{x[0-9]+}}, lsr #20
228
229t6:
Matthias Braun8ab86902015-02-05 23:52:14 +0000230 store volatile i32 %v, i32* @var32
Tim Northovere0e3aef2013-01-31 12:12:40 +0000231 %shift6 = ashr i64 %rhs64, 59
232 %tst6 = icmp ne i64 %lhs64, %shift6
233 br i1 %tst6, label %t7, label %end
234; CHECK: cmp {{x[0-9]+}}, {{x[0-9]+}}, asr #59
235
236t7:
Matthias Braun8ab86902015-02-05 23:52:14 +0000237 store volatile i32 %v, i32* @var32
238 br label %end
Tim Northovere0e3aef2013-01-31 12:12:40 +0000239
Matthias Braun8ab86902015-02-05 23:52:14 +0000240end:
241 ret void
Tim Northovere0e3aef2013-01-31 12:12:40 +0000242; CHECK: ret
243}
244
245define i32 @test_cmn(i32 %lhs32, i32 %rhs32, i64 %lhs64, i64 %rhs64) {
Stephen Linf799e3f2013-07-13 20:38:47 +0000246; CHECK-LABEL: test_cmn:
Tim Northovere0e3aef2013-01-31 12:12:40 +0000247
248 %shift1 = shl i32 %rhs32, 13
249 %val1 = sub i32 0, %shift1
250 %tst1 = icmp uge i32 %lhs32, %val1
251 br i1 %tst1, label %t2, label %end
252 ; Important that this isn't lowered to a cmn instruction because if %rhs32 ==
253 ; 0 then the results will differ.
Tim Northover5896b062014-05-16 09:42:04 +0000254; CHECK: neg [[RHS:w[0-9]+]], {{w[0-9]+}}, lsl #13
Tim Northovere0e3aef2013-01-31 12:12:40 +0000255; CHECK: cmp {{w[0-9]+}}, [[RHS]]
256
257t2:
258 %shift2 = lshr i32 %rhs32, 20
259 %val2 = sub i32 0, %shift2
260 %tst2 = icmp ne i32 %lhs32, %val2
261 br i1 %tst2, label %t3, label %end
262; CHECK: cmn {{w[0-9]+}}, {{w[0-9]+}}, lsr #20
263
264t3:
265 %shift3 = ashr i32 %rhs32, 9
266 %val3 = sub i32 0, %shift3
267 %tst3 = icmp eq i32 %lhs32, %val3
268 br i1 %tst3, label %t4, label %end
269; CHECK: cmn {{w[0-9]+}}, {{w[0-9]+}}, asr #9
270
271t4:
272 %shift4 = shl i64 %rhs64, 43
273 %val4 = sub i64 0, %shift4
274 %tst4 = icmp slt i64 %lhs64, %val4
275 br i1 %tst4, label %t5, label %end
276 ; Again, it's important that cmn isn't used here in case %rhs64 == 0.
Tim Northover5896b062014-05-16 09:42:04 +0000277; CHECK: neg [[RHS:x[0-9]+]], {{x[0-9]+}}, lsl #43
Tim Northovere0e3aef2013-01-31 12:12:40 +0000278; CHECK: cmp {{x[0-9]+}}, [[RHS]]
279
280t5:
281 %shift5 = lshr i64 %rhs64, 20
282 %val5 = sub i64 0, %shift5
283 %tst5 = icmp ne i64 %lhs64, %val5
284 br i1 %tst5, label %t6, label %end
285; CHECK: cmn {{x[0-9]+}}, {{x[0-9]+}}, lsr #20
286
287t6:
288 %shift6 = ashr i64 %rhs64, 59
289 %val6 = sub i64 0, %shift6
290 %tst6 = icmp ne i64 %lhs64, %val6
291 br i1 %tst6, label %t7, label %end
292; CHECK: cmn {{x[0-9]+}}, {{x[0-9]+}}, asr #59
293
294t7:
295 ret i32 1
296end:
297
298 ret i32 0
299; CHECK: ret
300}
301