1 ; RUN: llc -mtriple=armv7-linux-gnueabihf %s -o - | FileCheck %s --check-prefix=CHECK-ARM --check-prefix=CHECK-COMMON
2 ; RUN: llc -mtriple=armv7eb-linux-gnueabihf %s -o - | FileCheck %s --check-prefix=CHECK-BE
3 ; RUN: llc -mtriple=thumbv7-linux-gnueabihf %s -o - | FileCheck %s --check-prefix=CHECK-THUMB --check-prefix=CHECK-COMMON
4 ; RUN: llc -mtriple=thumbv7m %s -o - | FileCheck %s --check-prefix=CHECK-THUMB --check-prefix=CHECK-COMMON
5 ; RUN: llc -mtriple=thumbv7m -mattr=+strict-align %s -o - | FileCheck %s --check-prefix=CHECK-ALIGN --check-prefix=CHECK-COMMON
6 ; RUN: llc -mtriple=thumbv6m %s -o - | FileCheck %s --check-prefix=CHECK-V6M
8 @array = weak global [4 x i32] zeroinitializer
10 define i32 @test_lshr_and1(i32 %x) {
12 ;CHECK-LABEL: test_lshr_and1:
13 ;CHECK-COMMON: movw r1, :lower16:array
14 ;CHECK-COMMON-NEXT: and r0, r0, #12
15 ;CHECK-COMMON-NEXT: movt r1, :upper16:array
16 ;CHECK-COMMON-NEXT: ldr r0, [r1, r0]
17 ;CHECK-COMMON-NEXT: bx lr
18 %tmp2 = lshr i32 %x, 2
19 %tmp3 = and i32 %tmp2, 3
20 %tmp4 = getelementptr [4 x i32], [4 x i32]* @array, i32 0, i32 %tmp3
21 %tmp5 = load i32, i32* %tmp4, align 4
24 define i32 @test_lshr_and2(i32 %x) {
26 ;CHECK-LABEL: test_lshr_and2:
27 ;CHECK-COMMON: ubfx r0, r0, #1, #15
28 ;CHECK-ARM: add r0, r0, r0
29 ;CHECK-THUMB: add r0, r0
31 %a = and i32 %x, 65534
33 %c = and i32 %x, 65535
39 ; CHECK-LABEL: test_lshr_load1
40 ; CHECK-BE: ldrb r0, [r0]
41 ; CHECK-COMMON: ldrb r0, [r0, #1]
42 ; CHECK-COMMON-NEXT: bx
43 define arm_aapcscc i32 @test_lshr_load1(i16* %a) {
45 %0 = load i16, i16* %a, align 2
46 %conv1 = zext i16 %0 to i32
47 %1 = lshr i32 %conv1, 8
51 ; CHECK-LABEL: test_lshr_load1_sext
52 ; CHECK-ARM: ldrsh r0, [r0]
53 ; CHECK-ARM-NEXT: lsr r0, r0, #8
54 ; CHECK-THUMB: ldrsh.w r0, [r0]
55 ; CHECK-THUMB-NEXT: lsrs r0, r0, #8
57 define arm_aapcscc i32 @test_lshr_load1_sext(i16* %a) {
59 %0 = load i16, i16* %a, align 2
60 %conv1 = sext i16 %0 to i32
61 %1 = lshr i32 %conv1, 8
65 ; CHECK-LABEL: test_lshr_load1_fail
66 ; CHECK-COMMON: ldrh r0, [r0]
67 ; CHECK-ARM: lsr r0, r0, #9
68 ; CHECK-THUMB: lsrs r0, r0, #9
70 define arm_aapcscc i32 @test_lshr_load1_fail(i16* %a) {
72 %0 = load i16, i16* %a, align 2
73 %conv1 = zext i16 %0 to i32
74 %1 = lshr i32 %conv1, 9
78 ; CHECK-LABEL: test_lshr_load32
79 ; CHECK-COMMON: ldr r0, [r0]
80 ; CHECK-ARM: lsr r0, r0, #8
81 ; CHECK-THUMB: lsrs r0, r0, #8
83 define arm_aapcscc i32 @test_lshr_load32(i32* %a) {
85 %0 = load i32, i32* %a, align 4
90 ; CHECK-LABEL: test_lshr_load32_2
91 ; CHECK-BE: ldrh r0, [r0]
92 ; CHECK-COMMON: ldrh r0, [r0, #2]
93 ; CHECK-COMMON-NEXT: bx
94 define arm_aapcscc i32 @test_lshr_load32_2(i32* %a) {
96 %0 = load i32, i32* %a, align 4
101 ; CHECK-LABEL: test_lshr_load32_1
102 ; CHECK-BE: ldrb r0, [r0]
103 ; CHECK-COMMON: ldrb r0, [r0, #3]
104 ; CHECK-COMMON-NEXT: bx
105 define arm_aapcscc i32 @test_lshr_load32_1(i32* %a) {
107 %0 = load i32, i32* %a, align 4
112 ; CHECK-LABEL: test_lshr_load32_fail
113 ; CHECK-BE: ldr r0, [r0]
114 ; CHECK-BE-NEXT: lsr r0, r0, #15
115 ; CHECK-COMMON: ldr r0, [r0]
116 ; CHECK-ARM: lsr r0, r0, #15
117 ; CHECK-THUMB: lsrs r0, r0, #15
119 define arm_aapcscc i32 @test_lshr_load32_fail(i32* %a) {
121 %0 = load i32, i32* %a, align 4
126 ; CHECK-LABEL: test_lshr_load64_4_unaligned
127 ; CHECK-BE: ldr [[HIGH:r[0-9]+]], [r0]
128 ; CHECK-BE-NEXT: ldrh [[LOW:r[0-9]+]], [r0, #4]
129 ; CHECK-BE-NEXT: orr r0, [[LOW]], [[HIGH]], lsl #16
130 ; CHECK-V6M: ldrh [[LOW:r[0-9]+]], [r0, #2]
131 ; CHECK-V6M: ldr [[HIGH:r[0-9]+]], [r0, #4]
132 ; CHECK-V6M-NEXT: lsls [[HIGH]], [[HIGH]], #16
133 ; CHECK-V6M-NEXT: adds r0, r1, r0
134 ; CHECK-ALIGN: ldr [[HIGH:r[0-9]+]], [r0, #4]
135 ; CHECK-ALIGN-NEXT: ldrh [[LOW:r[0-9]+]], [r0, #2]
136 ; CHECK-ALIGN-NEXT: orr.w r0, [[LOW]], [[HIGH]], lsl #16
137 ; CHECK-ARM: ldr r0, [r0, #2]
138 ; CHECK-THUMB: ldr.w r0, [r0, #2]
140 define arm_aapcscc i32 @test_lshr_load64_4_unaligned(i64* %a) {
142 %0 = load i64, i64* %a, align 8
144 %conv = trunc i64 %1 to i32
148 ; CHECK-LABEL: test_lshr_load64_1_lsb
149 ; CHECK-BE: ldr r1, [r0]
150 ; CHECK-BE-NEXT: ldrb r0, [r0, #4]
151 ; CHECK-BE-NEXT: orr r0, r0, r1, lsl #8
152 ; CHECK-ARM: ldr r0, [r0, #3]
153 ; CHECK-THUMB: ldr.w r0, [r0, #3]
154 ; CHECK-ALIGN: ldr [[HIGH:r[0-9]+]], [r0, #4]
155 ; CHECK-ALIGN-NEXT: ldrb [[LOW:r[0-9]+]], [r0, #3]
156 ; CHECK-ALIGN-NEXT: orr.w r0, [[LOW]], [[HIGH]], lsl #8
158 define arm_aapcscc i32 @test_lshr_load64_1_lsb(i64* %a) {
160 %0 = load i64, i64* %a, align 8
162 %conv = trunc i64 %1 to i32
166 ; CHECK-LABEL: test_lshr_load64_1_msb
167 ; CHECK-BE: ldrb r0, [r0]
169 ; CHECK-COMMON: ldrb r0, [r0, #7]
170 ; CHECK-COMMON-NEXT: bx
171 define arm_aapcscc i32 @test_lshr_load64_1_msb(i64* %a) {
173 %0 = load i64, i64* %a, align 8
175 %conv = trunc i64 %1 to i32
179 ; CHECK-LABEL: test_lshr_load64_4
180 ; CHECK-BE: ldr r0, [r0]
182 ; CHECK-COMMON: ldr r0, [r0, #4]
183 ; CHECK-COMMON-NEXT: bx
184 define arm_aapcscc i32 @test_lshr_load64_4(i64* %a) {
186 %0 = load i64, i64* %a, align 8
188 %conv = trunc i64 %1 to i32
192 ; CHECK-LABEL: test_lshr_load64_2
193 ; CHECK-BE: ldrh r0, [r0]
195 ; CHECK-COMMON: ldrh r0, [r0, #6]
196 ; CHECK-COMMON-NEXT:bx
197 define arm_aapcscc i32 @test_lshr_load64_2(i64* %a) {
199 %0 = load i64, i64* %a, align 8
201 %conv = trunc i64 %1 to i32
205 ; CHECK-LABEL: test_lshr_load4_fail
206 ; CHECK-COMMON: ldrd r0, r1, [r0]
207 ; CHECK-ARM: lsr r0, r0, #8
208 ; CHECK-ARM-NEXT: orr r0, r0, r1, lsl #24
209 ; CHECK-THUMB: lsrs r0, r0, #8
210 ; CHECK-THUMB-NEXT: orr.w r0, r0, r1, lsl #24
212 define arm_aapcscc i32 @test_lshr_load4_fail(i64* %a) {
214 %0 = load i64, i64* %a, align 8
216 %conv = trunc i64 %1 to i32
220 ; CHECK-LABEL: test_shift7_mask8
221 ; CHECK-BE: ldr r1, [r0]
222 ; CHECK-COMMON: ldr r1, [r0]
223 ; CHECK-COMMON: ubfx r1, r1, #7, #8
224 ; CHECK-COMMON: str r1, [r0]
225 define arm_aapcscc void @test_shift7_mask8(i32* nocapture %p) {
227 %0 = load i32, i32* %p, align 4
228 %shl = lshr i32 %0, 7
229 %and = and i32 %shl, 255
230 store i32 %and, i32* %p, align 4
234 ; CHECK-LABEL: test_shift8_mask8
235 ; CHECK-BE: ldrb r1, [r0, #2]
236 ; CHECK-COMMON: ldrb r1, [r0, #1]
237 ; CHECK-COMMON: str r1, [r0]
238 define arm_aapcscc void @test_shift8_mask8(i32* nocapture %p) {
240 %0 = load i32, i32* %p, align 4
241 %shl = lshr i32 %0, 8
242 %and = and i32 %shl, 255
243 store i32 %and, i32* %p, align 4
247 ; CHECK-LABEL: test_shift8_mask7
248 ; CHECK-BE: ldr r1, [r0]
249 ; CHECK-COMMON: ldr r1, [r0]
250 ; CHECK-COMMON: ubfx r1, r1, #8, #7
251 ; CHECK-COMMON: str r1, [r0]
252 define arm_aapcscc void @test_shift8_mask7(i32* nocapture %p) {
254 %0 = load i32, i32* %p, align 4
255 %shl = lshr i32 %0, 8
256 %and = and i32 %shl, 127
257 store i32 %and, i32* %p, align 4
261 ; CHECK-LABEL: test_shift9_mask8
262 ; CHECK-BE: ldr r1, [r0]
263 ; CHECK-COMMON: ldr r1, [r0]
264 ; CHECK-COMMON: ubfx r1, r1, #9, #8
265 ; CHECK-COMMON: str r1, [r0]
266 define arm_aapcscc void @test_shift9_mask8(i32* nocapture %p) {
268 %0 = load i32, i32* %p, align 4
269 %shl = lshr i32 %0, 9
270 %and = and i32 %shl, 255
271 store i32 %and, i32* %p, align 4
275 ; CHECK-LABEL: test_shift8_mask16
276 ; CHECK-ALIGN: ldr r1, [r0]
277 ; CHECK-ALIGN: ubfx r1, r1, #8, #16
278 ; CHECK-BE: ldrh r1, [r0, #1]
279 ; CHECK-ARM: ldrh r1, [r0, #1]
280 ; CHECK-THUMB: ldrh.w r1, [r0, #1]
281 ; CHECK-COMMON: str r1, [r0]
282 define arm_aapcscc void @test_shift8_mask16(i32* nocapture %p) {
284 %0 = load i32, i32* %p, align 4
285 %shl = lshr i32 %0, 8
286 %and = and i32 %shl, 65535
287 store i32 %and, i32* %p, align 4
291 ; CHECK-LABEL: test_shift15_mask16
292 ; CHECK-COMMON: ldr r1, [r0]
293 ; CHECK-COMMON: ubfx r1, r1, #15, #16
294 ; CHECK-COMMON: str r1, [r0]
295 define arm_aapcscc void @test_shift15_mask16(i32* nocapture %p) {
297 %0 = load i32, i32* %p, align 4
298 %shl = lshr i32 %0, 15
299 %and = and i32 %shl, 65535
300 store i32 %and, i32* %p, align 4
304 ; CHECK-LABEL: test_shift16_mask15
305 ; CHECK-BE: ldrh r1, [r0]
306 ; CHECK-COMMON: ldrh r1, [r0, #2]
307 ; CHECK-COMMON: bfc r1, #15, #17
308 ; CHECK-COMMON: str r1, [r0]
309 define arm_aapcscc void @test_shift16_mask15(i32* nocapture %p) {
311 %0 = load i32, i32* %p, align 4
312 %shl = lshr i32 %0, 16
313 %and = and i32 %shl, 32767
314 store i32 %and, i32* %p, align 4
318 ; CHECK-LABEL: test_shift8_mask24
319 ; CHECK-BE: ldr r1, [r0]
320 ; CHECK-COMMON: ldr r1, [r0]
321 ; CHECK-ARM: lsr r1, r1, #8
322 ; CHECK-THUMB: lsrs r1, r1, #8
323 ; CHECK-COMMON: str r1, [r0]
324 define arm_aapcscc void @test_shift8_mask24(i32* nocapture %p) {
326 %0 = load i32, i32* %p, align 4
327 %shl = lshr i32 %0, 8
328 %and = and i32 %shl, 16777215
329 store i32 %and, i32* %p, align 4
333 ; CHECK-LABEL: test_shift24_mask16
334 ; CHECK-BE: ldrb r1, [r0]
335 ; CHECK-COMMON: ldrb r1, [r0, #3]
336 ; CHECK-COMMON: str r1, [r0]
337 define arm_aapcscc void @test_shift24_mask16(i32* nocapture %p) {
339 %0 = load i32, i32* %p, align 4
340 %shl = lshr i32 %0, 24
341 %and = and i32 %shl, 65535
342 store i32 %and, i32* %p, align 4
346 ; CHECK-LABEL: test_sext_shift8_mask8
347 ; CHECK-BE: ldrb r0, [r0]
348 ; CHECK-COMMON: ldrb r0, [r0, #1]
349 ; CHECK-COMMON: str r0, [r1]
350 define arm_aapcscc void @test_sext_shift8_mask8(i16* %p, i32* %q) {
352 %0 = load i16, i16* %p, align 4
353 %1 = sext i16 %0 to i32
354 %shl = lshr i32 %1, 8
355 %and = and i32 %shl, 255
356 store i32 %and, i32* %q, align 4
360 ; CHECK-LABEL: test_sext_shift8_mask16
361 ; CHECK-ARM: ldrsh r0, [r0]
362 ; CHECK-BE: ldrsh r0, [r0]
363 ; CHECK-THUMB: ldrsh.w r0, [r0]
364 ; CHECK-COMMON: ubfx r0, r0, #8, #16
365 ; CHECK-COMMON: str r0, [r1]
366 define arm_aapcscc void @test_sext_shift8_mask16(i16* %p, i32* %q) {
368 %0 = load i16, i16* %p, align 4
369 %1 = sext i16 %0 to i32
370 %shl = lshr i32 %1, 8
371 %and = and i32 %shl, 65535
372 store i32 %and, i32* %q, align 4
376 ; CHECK-LABEL: trunc_i64_mask_srl
377 ; CHECK-ARM: ldrh r2, [r1, #4]
378 ; CHECK-BE: ldrh r2, [r1, #2]
379 define i1 @trunc_i64_mask_srl(i32 zeroext %AttrArgNo, i64* %ptr) {
381 %bf.load.i = load i64, i64* %ptr, align 8
382 %bf.lshr.i = lshr i64 %bf.load.i, 32
383 %0 = trunc i64 %bf.lshr.i to i32
384 %bf.cast.i = and i32 %0, 65535
385 %cmp.i = icmp ugt i32 %bf.cast.i, %AttrArgNo