1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
2 ; RUN: llc < %s | FileCheck %s
4 target triple = "aarch64-unknown-linux"
6 ; Check an "expensive" construction of a constant is hoisted out of a loop
7 define void @f0(ptr %a, i64 %n) {
9 ; CHECK: // %bb.0: // %entry
10 ; CHECK-NEXT: str x30, [sp, #-48]! // 8-byte Folded Spill
11 ; CHECK-NEXT: stp x22, x21, [sp, #16] // 16-byte Folded Spill
12 ; CHECK-NEXT: stp x20, x19, [sp, #32] // 16-byte Folded Spill
13 ; CHECK-NEXT: .cfi_def_cfa_offset 48
14 ; CHECK-NEXT: .cfi_offset w19, -8
15 ; CHECK-NEXT: .cfi_offset w20, -16
16 ; CHECK-NEXT: .cfi_offset w21, -24
17 ; CHECK-NEXT: .cfi_offset w22, -32
18 ; CHECK-NEXT: .cfi_offset w30, -48
19 ; CHECK-NEXT: mov x21, #1 // =0x1
20 ; CHECK-NEXT: mov x19, x1
21 ; CHECK-NEXT: mov x20, x0
22 ; CHECK-NEXT: movk x21, #22136, lsl #16
23 ; CHECK-NEXT: mov x22, xzr
24 ; CHECK-NEXT: movk x21, #4660, lsl #48
25 ; CHECK-NEXT: cmp x22, x19
26 ; CHECK-NEXT: b.ge .LBB0_2
27 ; CHECK-NEXT: .LBB0_1: // %loop.body
28 ; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
29 ; CHECK-NEXT: ldr w0, [x20, x22, lsl #2]
30 ; CHECK-NEXT: mov x1, x21
32 ; CHECK-NEXT: str w0, [x20, x22, lsl #2]
33 ; CHECK-NEXT: add x22, x22, #1
34 ; CHECK-NEXT: cmp x22, x19
35 ; CHECK-NEXT: b.lt .LBB0_1
36 ; CHECK-NEXT: .LBB0_2: // %exit
37 ; CHECK-NEXT: ldp x20, x19, [sp, #32] // 16-byte Folded Reload
38 ; CHECK-NEXT: ldp x22, x21, [sp, #16] // 16-byte Folded Reload
39 ; CHECK-NEXT: ldr x30, [sp], #48 // 8-byte Folded Reload
45 %i = phi i64 [0, %entry], [%i.next, %loop.body]
46 %c = icmp slt i64 %i, %n
47 br i1 %c, label %loop.body, label %exit
50 %p = getelementptr i32, ptr %a, i64 %i
52 %w = call i32 @g(i32 %v, i64 1311673392922361857) ; 0x1234000056780001
54 %i.next = add i64 %i, 1
61 ; Check a "cheap" to construct constant is materialised inside a loop.
62 define void @f1(ptr %a, i64 %n) {
64 ; CHECK: // %bb.0: // %entry
65 ; CHECK-NEXT: stp x30, x21, [sp, #-32]! // 16-byte Folded Spill
66 ; CHECK-NEXT: stp x20, x19, [sp, #16] // 16-byte Folded Spill
67 ; CHECK-NEXT: .cfi_def_cfa_offset 32
68 ; CHECK-NEXT: .cfi_offset w19, -8
69 ; CHECK-NEXT: .cfi_offset w20, -16
70 ; CHECK-NEXT: .cfi_offset w21, -24
71 ; CHECK-NEXT: .cfi_offset w30, -32
72 ; CHECK-NEXT: mov x19, x1
73 ; CHECK-NEXT: mov x20, x0
74 ; CHECK-NEXT: mov x21, xzr
75 ; CHECK-NEXT: cmp x21, x19
76 ; CHECK-NEXT: b.ge .LBB1_2
77 ; CHECK-NEXT: .LBB1_1: // %loop.body
78 ; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
79 ; CHECK-NEXT: ldr w0, [x20, x21, lsl #2]
80 ; CHECK-NEXT: mov x1, #1450704896 // =0x56780000
81 ; CHECK-NEXT: movk x1, #4660, lsl #48
83 ; CHECK-NEXT: str w0, [x20, x21, lsl #2]
84 ; CHECK-NEXT: add x21, x21, #1
85 ; CHECK-NEXT: cmp x21, x19
86 ; CHECK-NEXT: b.lt .LBB1_1
87 ; CHECK-NEXT: .LBB1_2: // %exit
88 ; CHECK-NEXT: ldp x20, x19, [sp, #16] // 16-byte Folded Reload
89 ; CHECK-NEXT: ldp x30, x21, [sp], #32 // 16-byte Folded Reload
95 %i = phi i64 [0, %entry], [%i.next, %loop.body]
96 %c = icmp slt i64 %i, %n
97 br i1 %c, label %loop.body, label %exit
100 %p = getelementptr i32, ptr %a, i64 %i
101 %v = load i32, ptr %p
102 %w = call i32 @g(i32 %v, i64 1311673392922361856) ; 0x1234000056780000
104 %i.next = add i64 %i, 1
111 declare i32 @g(i32, i64)