1 ; RUN: llc -mtriple=aarch64-apple-darwin -fast-isel -fast-isel-abort=1 -aarch64-enable-atomic-cfg-tidy=false -disable-cgp-branch-opts -verify-machineinstrs < %s | FileCheck %s
4 ; Test folding of the sign-/zero-extend into the load instruction.
8 define i32 @load_unscaled_zext_i8_to_i32(i64 %a) {
9 ; CHECK-LABEL: load_unscaled_zext_i8_to_i32
10 ; CHECK: ldurb w0, [x0, #-8]
13 %2 = inttoptr i64 %1 to i8*
18 %4 = zext i8 %3 to i32
22 define i32 @load_unscaled_zext_i16_to_i32(i64 %a) {
23 ; CHECK-LABEL: load_unscaled_zext_i16_to_i32
24 ; CHECK: ldurh w0, [x0, #-8]
27 %2 = inttoptr i64 %1 to i16*
28 %3 = load i16, i16* %2
32 %4 = zext i16 %3 to i32
36 define i64 @load_unscaled_zext_i8_to_i64(i64 %a) {
37 ; CHECK-LABEL: load_unscaled_zext_i8_to_i64
38 ; CHECK: ldurb w0, [x0, #-8]
41 %2 = inttoptr i64 %1 to i8*
46 %4 = zext i8 %3 to i64
50 define i64 @load_unscaled_zext_i16_to_i64(i64 %a) {
51 ; CHECK-LABEL: load_unscaled_zext_i16_to_i64
52 ; CHECK: ldurh w0, [x0, #-8]
55 %2 = inttoptr i64 %1 to i16*
56 %3 = load i16, i16* %2
60 %4 = zext i16 %3 to i64
64 define i64 @load_unscaled_zext_i32_to_i64(i64 %a) {
65 ; CHECK-LABEL: load_unscaled_zext_i32_to_i64
66 ; CHECK: ldur w0, [x0, #-8]
69 %2 = inttoptr i64 %1 to i32*
70 %3 = load i32, i32* %2
74 %4 = zext i32 %3 to i64
78 define i32 @load_unscaled_sext_i8_to_i32(i64 %a) {
79 ; CHECK-LABEL: load_unscaled_sext_i8_to_i32
80 ; CHECK: ldursb w0, [x0, #-8]
83 %2 = inttoptr i64 %1 to i8*
88 %4 = sext i8 %3 to i32
92 define i32 @load_unscaled_sext_i16_to_i32(i64 %a) {
93 ; CHECK-LABEL: load_unscaled_sext_i16_to_i32
94 ; CHECK: ldursh w0, [x0, #-8]
97 %2 = inttoptr i64 %1 to i16*
98 %3 = load i16, i16* %2
102 %4 = sext i16 %3 to i32
106 define i64 @load_unscaled_sext_i8_to_i64(i64 %a) {
107 ; CHECK-LABEL: load_unscaled_sext_i8_to_i64
108 ; CHECK: ldursb x0, [x0, #-8]
111 %2 = inttoptr i64 %1 to i8*
116 %4 = sext i8 %3 to i64
120 define i64 @load_unscaled_sext_i16_to_i64(i64 %a) {
121 ; CHECK-LABEL: load_unscaled_sext_i16_to_i64
122 ; CHECK: ldursh x0, [x0, #-8]
125 %2 = inttoptr i64 %1 to i16*
126 %3 = load i16, i16* %2
130 %4 = sext i16 %3 to i64
134 define i64 @load_unscaled_sext_i32_to_i64(i64 %a) {
135 ; CHECK-LABEL: load_unscaled_sext_i32_to_i64
136 ; CHECK: ldursw x0, [x0, #-8]
139 %2 = inttoptr i64 %1 to i32*
140 %3 = load i32, i32* %2
144 %4 = sext i32 %3 to i64
149 define i32 @load_register_zext_i8_to_i32(i64 %a, i64 %b) {
150 ; CHECK-LABEL: load_register_zext_i8_to_i32
151 ; CHECK: ldrb w0, [x0, x1]
154 %2 = inttoptr i64 %1 to i8*
159 %4 = zext i8 %3 to i32
163 define i32 @load_register_zext_i16_to_i32(i64 %a, i64 %b) {
164 ; CHECK-LABEL: load_register_zext_i16_to_i32
165 ; CHECK: ldrh w0, [x0, x1]
168 %2 = inttoptr i64 %1 to i16*
169 %3 = load i16, i16* %2
173 %4 = zext i16 %3 to i32
177 define i64 @load_register_zext_i8_to_i64(i64 %a, i64 %b) {
178 ; CHECK-LABEL: load_register_zext_i8_to_i64
179 ; CHECK: ldrb w0, [x0, x1]
182 %2 = inttoptr i64 %1 to i8*
187 %4 = zext i8 %3 to i64
191 define i64 @load_register_zext_i16_to_i64(i64 %a, i64 %b) {
192 ; CHECK-LABEL: load_register_zext_i16_to_i64
193 ; CHECK: ldrh w0, [x0, x1]
196 %2 = inttoptr i64 %1 to i16*
197 %3 = load i16, i16* %2
201 %4 = zext i16 %3 to i64
205 define i64 @load_register_zext_i32_to_i64(i64 %a, i64 %b) {
206 ; CHECK-LABEL: load_register_zext_i32_to_i64
207 ; CHECK: ldr w0, [x0, x1]
210 %2 = inttoptr i64 %1 to i32*
211 %3 = load i32, i32* %2
215 %4 = zext i32 %3 to i64
219 define i32 @load_register_sext_i8_to_i32(i64 %a, i64 %b) {
220 ; CHECK-LABEL: load_register_sext_i8_to_i32
221 ; CHECK: ldrsb w0, [x0, x1]
224 %2 = inttoptr i64 %1 to i8*
229 %4 = sext i8 %3 to i32
233 define i32 @load_register_sext_i16_to_i32(i64 %a, i64 %b) {
234 ; CHECK-LABEL: load_register_sext_i16_to_i32
235 ; CHECK: ldrsh w0, [x0, x1]
238 %2 = inttoptr i64 %1 to i16*
239 %3 = load i16, i16* %2
243 %4 = sext i16 %3 to i32
247 define i64 @load_register_sext_i8_to_i64(i64 %a, i64 %b) {
248 ; CHECK-LABEL: load_register_sext_i8_to_i64
249 ; CHECK: ldrsb x0, [x0, x1]
252 %2 = inttoptr i64 %1 to i8*
257 %4 = sext i8 %3 to i64
261 define i64 @load_register_sext_i16_to_i64(i64 %a, i64 %b) {
262 ; CHECK-LABEL: load_register_sext_i16_to_i64
263 ; CHECK: ldrsh x0, [x0, x1]
266 %2 = inttoptr i64 %1 to i16*
267 %3 = load i16, i16* %2
271 %4 = sext i16 %3 to i64
275 define i64 @load_register_sext_i32_to_i64(i64 %a, i64 %b) {
276 ; CHECK-LABEL: load_register_sext_i32_to_i64
277 ; CHECK: ldrsw x0, [x0, x1]
280 %2 = inttoptr i64 %1 to i32*
281 %3 = load i32, i32* %2
285 %4 = sext i32 %3 to i64
290 define i32 @load_extend_zext_i8_to_i32(i64 %a, i32 %b) {
291 ; CHECK-LABEL: load_extend_zext_i8_to_i32
292 ; CHECK: ldrb w0, [x0, w1, sxtw]
294 %1 = sext i32 %b to i64
296 %3 = inttoptr i64 %2 to i8*
301 %5 = zext i8 %4 to i32
305 define i32 @load_extend_zext_i16_to_i32(i64 %a, i32 %b) {
306 ; CHECK-LABEL: load_extend_zext_i16_to_i32
307 ; CHECK: ldrh w0, [x0, w1, sxtw]
309 %1 = sext i32 %b to i64
311 %3 = inttoptr i64 %2 to i16*
312 %4 = load i16, i16* %3
316 %5 = zext i16 %4 to i32
320 define i64 @load_extend_zext_i8_to_i64(i64 %a, i32 %b) {
321 ; CHECK-LABEL: load_extend_zext_i8_to_i64
322 ; CHECK: ldrb w0, [x0, w1, sxtw]
324 %1 = sext i32 %b to i64
326 %3 = inttoptr i64 %2 to i8*
331 %5 = zext i8 %4 to i64
335 define i64 @load_extend_zext_i16_to_i64(i64 %a, i32 %b) {
336 ; CHECK-LABEL: load_extend_zext_i16_to_i64
337 ; CHECK: ldrh w0, [x0, w1, sxtw]
339 %1 = sext i32 %b to i64
341 %3 = inttoptr i64 %2 to i16*
342 %4 = load i16, i16* %3
346 %5 = zext i16 %4 to i64
350 define i64 @load_extend_zext_i32_to_i64(i64 %a, i32 %b) {
351 ; CHECK-LABEL: load_extend_zext_i32_to_i64
352 ; CHECK: ldr w0, [x0, w1, sxtw]
354 %1 = sext i32 %b to i64
356 %3 = inttoptr i64 %2 to i32*
357 %4 = load i32, i32* %3
361 %5 = zext i32 %4 to i64
365 define i32 @load_extend_sext_i8_to_i32(i64 %a, i32 %b) {
366 ; CHECK-LABEL: load_extend_sext_i8_to_i32
367 ; CHECK: ldrsb w0, [x0, w1, sxtw]
369 %1 = sext i32 %b to i64
371 %3 = inttoptr i64 %2 to i8*
376 %5 = sext i8 %4 to i32
380 define i32 @load_extend_sext_i16_to_i32(i64 %a, i32 %b) {
381 ; CHECK-LABEL: load_extend_sext_i16_to_i32
382 ; CHECK: ldrsh w0, [x0, w1, sxtw]
384 %1 = sext i32 %b to i64
386 %3 = inttoptr i64 %2 to i16*
387 %4 = load i16, i16* %3
391 %5 = sext i16 %4 to i32
395 define i64 @load_extend_sext_i8_to_i64(i64 %a, i32 %b) {
396 ; CHECK-LABEL: load_extend_sext_i8_to_i64
397 ; CHECK: ldrsb x0, [x0, w1, sxtw]
399 %1 = sext i32 %b to i64
401 %3 = inttoptr i64 %2 to i8*
406 %5 = sext i8 %4 to i64
410 define i64 @load_extend_sext_i16_to_i64(i64 %a, i32 %b) {
411 ; CHECK-LABEL: load_extend_sext_i16_to_i64
412 ; CHECK: ldrsh x0, [x0, w1, sxtw]
414 %1 = sext i32 %b to i64
416 %3 = inttoptr i64 %2 to i16*
417 %4 = load i16, i16* %3
421 %5 = sext i16 %4 to i64
425 define i64 @load_extend_sext_i32_to_i64(i64 %a, i32 %b) {
426 ; CHECK-LABEL: load_extend_sext_i32_to_i64
427 ; CHECK: ldrsw x0, [x0, w1, sxtw]
429 %1 = sext i32 %b to i64
431 %3 = inttoptr i64 %2 to i32*
432 %4 = load i32, i32* %3
436 %5 = sext i32 %4 to i64