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: stp x30, x23, [sp, #-48]! // 16-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 w23, -40
19 ; CHECK-NEXT: .cfi_offset w30, -48
20 ; CHECK-NEXT: mov x21, #1 // =0x1
21 ; CHECK-NEXT: mov x19, x1
22 ; CHECK-NEXT: mov x20, x0
23 ; CHECK-NEXT: movk x21, #22136, lsl #16
24 ; CHECK-NEXT: mov x22, xzr
25 ; CHECK-NEXT: movk x21, #4660, lsl #48
26 ; CHECK-NEXT: cmp x22, x19
27 ; CHECK-NEXT: b.ge .LBB0_2
28 ; CHECK-NEXT: .LBB0_1: // %loop.body
29 ; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
30 ; CHECK-NEXT: lsl x23, x22, #2
31 ; CHECK-NEXT: mov x1, x21
32 ; CHECK-NEXT: ldr w0, [x20, x23]
34 ; CHECK-NEXT: str w0, [x20, x23]
35 ; CHECK-NEXT: add x22, x22, #1
36 ; CHECK-NEXT: cmp x22, x19
37 ; CHECK-NEXT: b.lt .LBB0_1
38 ; CHECK-NEXT: .LBB0_2: // %exit
39 ; CHECK-NEXT: ldp x20, x19, [sp, #32] // 16-byte Folded Reload
40 ; CHECK-NEXT: ldp x22, x21, [sp, #16] // 16-byte Folded Reload
41 ; CHECK-NEXT: ldp x30, x23, [sp], #48 // 16-byte Folded Reload
47 %i = phi i64 [0, %entry], [%i.next, %loop.body]
48 %c = icmp slt i64 %i, %n
49 br i1 %c, label %loop.body, label %exit
52 %p = getelementptr i32, ptr %a, i64 %i
54 %w = call i32 @g(i32 %v, i64 1311673392922361857) ; 0x1234000056780001
56 %i.next = add i64 %i, 1
63 ; Check a "cheap" to construct constant is materialised inside a loop.
64 define void @f1(ptr %a, i64 %n) {
66 ; CHECK: // %bb.0: // %entry
67 ; CHECK-NEXT: str x30, [sp, #-48]! // 8-byte Folded Spill
68 ; CHECK-NEXT: stp x22, x21, [sp, #16] // 16-byte Folded Spill
69 ; CHECK-NEXT: stp x20, x19, [sp, #32] // 16-byte Folded Spill
70 ; CHECK-NEXT: .cfi_def_cfa_offset 48
71 ; CHECK-NEXT: .cfi_offset w19, -8
72 ; CHECK-NEXT: .cfi_offset w20, -16
73 ; CHECK-NEXT: .cfi_offset w21, -24
74 ; CHECK-NEXT: .cfi_offset w22, -32
75 ; CHECK-NEXT: .cfi_offset w30, -48
76 ; CHECK-NEXT: mov x19, x1
77 ; CHECK-NEXT: mov x20, x0
78 ; CHECK-NEXT: mov x21, xzr
79 ; CHECK-NEXT: cmp x21, x19
80 ; CHECK-NEXT: b.ge .LBB1_2
81 ; CHECK-NEXT: .LBB1_1: // %loop.body
82 ; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
83 ; CHECK-NEXT: lsl x22, x21, #2
84 ; CHECK-NEXT: mov x1, #1450704896 // =0x56780000
85 ; CHECK-NEXT: movk x1, #4660, lsl #48
86 ; CHECK-NEXT: ldr w0, [x20, x22]
88 ; CHECK-NEXT: str w0, [x20, x22]
89 ; CHECK-NEXT: add x21, x21, #1
90 ; CHECK-NEXT: cmp x21, x19
91 ; CHECK-NEXT: b.lt .LBB1_1
92 ; CHECK-NEXT: .LBB1_2: // %exit
93 ; CHECK-NEXT: ldp x20, x19, [sp, #32] // 16-byte Folded Reload
94 ; CHECK-NEXT: ldp x22, x21, [sp, #16] // 16-byte Folded Reload
95 ; CHECK-NEXT: ldr x30, [sp], #48 // 8-byte Folded Reload
101 %i = phi i64 [0, %entry], [%i.next, %loop.body]
102 %c = icmp slt i64 %i, %n
103 br i1 %c, label %loop.body, label %exit
106 %p = getelementptr i32, ptr %a, i64 %i
107 %v = load i32, ptr %p
108 %w = call i32 @g(i32 %v, i64 1311673392922361856) ; 0x1234000056780000
110 %i.next = add i64 %i, 1
117 declare i32 @g(i32, i64)