1 ; RUN: split-file %s %t
2 ; RUN: cat %t/main.ll %t/a.ll > %t/a2.ll
3 ; RUN: cat %t/main.ll %t/b.ll > %t/b2.ll
4 ; RUN: cat %t/main.ll %t/c.ll > %t/c2.ll
5 ; RUN: cat %t/main.ll %t/d.ll > %t/d2.ll
6 ; RUN: cat %t/main.ll %t/e.ll > %t/e2.ll
7 ; RUN: cat %t/main.ll %t/f.ll > %t/f2.ll
8 ; RUN: cat %t/main.ll %t/g.ll > %t/g2.ll
9 ; RUN: cat %t/main.ll %t/h.ll > %t/h2.ll
10 ; RUN: cat %t/main.ll %t/i.ll > %t/i2.ll
11 ; RUN: cat %t/main.ll %t/j.ll > %t/j2.ll
12 ; RUN: llc %t/a2.ll -verify-machineinstrs -o - | \
13 ; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NO-OFFSET %s
14 ; RUN: llc %t/b2.ll -verify-machineinstrs -o - | \
15 ; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-POSITIVE-OFFSET %s
16 ; RUN: llc %t/c2.ll -verify-machineinstrs -o - | \
17 ; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NEGATIVE-OFFSET %s
18 ; RUN: llc %t/d2.ll -verify-machineinstrs -o - | \
19 ; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NPOT-OFFSET %s
20 ; RUN: llc %t/e2.ll -verify-machineinstrs -o - | \
21 ; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NPOT-NEG-OFFSET %s
22 ; RUN: llc %t/f2.ll -verify-machineinstrs -o - | \
23 ; RUN: FileCheck --check-prefix=CHECK-ADD --check-prefix=CHECK-257-OFFSET %s
24 ; RUN: llc %t/g2.ll -verify-machineinstrs -o - | \
25 ; RUN: FileCheck --check-prefix=CHECK-ADD --check-prefix=CHECK-MINUS-257-OFFSET %s
28 ; RUN: not --crash llc %t/h2.ll -o - 2>&1 | \
29 ; RUN: FileCheck --check-prefix=CHECK-BAD-OFFSET %s
30 ; RUN: not --crash llc %t/i2.ll -o - 2>&1 | \
31 ; RUN: FileCheck --check-prefix=CHECK-BAD-OFFSET %s
32 ; RUN: not --crash llc %t/j2.ll -o - 2>&1 | \
33 ; RUN: FileCheck --check-prefix=CHECK-BAD-OFFSET %s
37 target triple = "aarch64-unknown-linux-gnu"
39 ; Verify that we `mrs` from `SP_EL0` twice, rather than load from
41 define dso_local void @foo(i64 %t) local_unnamed_addr #0 {
42 ; CHECK-LABEL: foo: // @foo
43 ; CHECK: .cfi_startproc
44 ; CHECK: // %bb.0: // %entry
45 ; CHECK-NEXT: stp x29, x30, [sp, #-16]! // 16-byte Folded Spill
46 ; CHECK-NEXT: .cfi_def_cfa_offset 16
47 ; CHECK-NEXT: mov x29, sp
48 ; CHECK-NEXT: .cfi_def_cfa w29, 16
49 ; CHECK-NEXT: .cfi_offset w30, -8
50 ; CHECK-NEXT: .cfi_offset w29, -16
51 ; CHECK-NEXT: .cfi_remember_state
52 ; CHECK-NEXT: sub sp, sp, #16
53 ; CHECK-NEXT: mrs x8, SP_EL0
54 ; CHECK-NEXT: lsl x9, x0, #2
55 ; CHECK-NO-OFFSET: ldr x8, [x8]
56 ; CHECK-POSITIVE-OFFSET: ldr x8, [x8, #8]
57 ; CHECK-NEGATIVE-OFFSET: ldur x8, [x8, #-8]
58 ; CHECK-NPOT-OFFSET: ldur x8, [x8, #1]
59 ; CHECK-NPOT-NEG-OFFSET: ldur x8, [x8, #-1]
60 ; CHECK-NEXT: add x9, x9, #15
61 ; CHECK-NEXT: stur x8, [x29, #-8]
62 ; CHECK-NEXT mov x8, sp
63 ; CHECK-NEXT and x9, x9, #0xfffffffffffffff0
64 ; CHECK-NEXT sub x0, x8, x9
65 ; CHECK-NEXT mov sp, x0
67 ; CHECK-NEXT mrs x8, SP_EL0
68 ; CHECK-NO-OFFSET: ldr x8, [x8]
69 ; CHECK-POSITIVE-OFFSET: ldr x8, [x8, #8]
70 ; CHECK-NEGATIVE-OFFSET: ldur x8, [x8, #-8]
71 ; CHECK-NPOT-OFFSET: ldur x8, [x8, #1]
72 ; CHECK-NPOT-NEG-OFFSET: ldur x8, [x8, #-1]
73 ; CHECK-NEXT: ldur x9, [x29, #-8]
74 ; CHECK-NEXT: cmp x8, x9
75 ; CHECK-NEXT: b.ne .LBB0_2
76 ; CHECK-NEXT: // %bb.1: // %entry
77 ; CHECK-NEXT: mov sp, x29
78 ; CHECK-NEXT: .cfi_def_cfa wsp, 16
79 ; CHECK-NEXT: ldp x29, x30, [sp], #16 // 16-byte Folded Reload
80 ; CHECK-NEXT: .cfi_def_cfa_offset 0
81 ; CHECK-NEXT: .cfi_restore w30
82 ; CHECK-NEXT: .cfi_restore w29
84 ; CHECK-NEXT: .LBB0_2: // %entry
85 ; CHECK-NEXT: .cfi_restore_state
86 ; CHECK-NEXT: bl __stack_chk_fail
87 ; CHECK-NEXT: .Lfunc_end0:
88 ; CHECK-NEXT: .size foo, .Lfunc_end0-foo
89 ; CHECK-NEXT: .cfi_endproc
90 ; CHECK-NEXT: // -- End function
91 ; CHECK-NEXT: .section ".note.GNU-stack","",@progbits
94 ; CHECK-ADD: stp x29, x30, [sp, #-16]! // 16-byte Folded Spill
95 ; CHECK-ADD-NEXT: .cfi_def_cfa_offset 16
96 ; CHECK-ADD-NEXT: mov x29, sp
97 ; CHECK-ADD-NEXT: .cfi_def_cfa w29, 16
98 ; CHECK-ADD-NEXT: .cfi_offset w30, -8
99 ; CHECK-ADD-NEXT: .cfi_offset w29, -16
100 ; CHECK-ADD-NEXT: .cfi_remember_state
101 ; CHECK-ADD-NEXT: sub sp, sp, #16
102 ; CHECK-ADD-NEXT: mrs x8, SP_EL0
103 ; CHECK-ADD-NEXT: lsl x9, x0, #2
104 ; CHECK-MINUS-257-OFFSET: sub x8, x8, #257
105 ; CHECK-257-OFFSET: add x8, x8, #257
106 ; CHECK-ADD-NEXT: ldr x8, [x8]
107 ; CHECK-ADD-NEXT: add x9, x9, #15
108 ; CHECK-ADD-NEXT: and x9, x9, #0xfffffffffffffff0
109 ; CHECK-ADD-NEXT: stur x8, [x29, #-8]
110 ; CHECK-ADD-NEXT: mov x8, sp
111 ; CHECK-ADD-NEXT: sub x0, x8, x9
112 ; CHECK-ADD-NEXT: mov sp, x0
113 ; CHECK-ADD-NEXT: bl baz
114 ; CHECK-ADD-NEXT: mrs x8, SP_EL0
115 ; CHECK-257-OFFSET: add x8, x8, #257
116 ; CHECK-MINUS-257-OFFSET: sub x8, x8, #257
117 ; CHECK-ADD-NEXT: ldr x8, [x8]
118 ; CHECK-ADD-NEXT: ldur x9, [x29, #-8]
119 ; CHECK-ADD-NEXT: cmp x8, x9
120 ; CHECK-ADD-NEXT: b.ne .LBB0_2
121 ; CHECK-ADD-NEXT: // %bb.1: // %entry
122 ; CHECK-ADD-NEXT: mov sp, x29
123 ; CHECK-ADD-NEXT: .cfi_def_cfa wsp, 16
124 ; CHECK-ADD-NEXT: ldp x29, x30, [sp], #16 // 16-byte Folded Reload
125 ; CHECK-ADD-NEXT: .cfi_def_cfa_offset 0
126 ; CHECK-ADD-NEXT: .cfi_restore w30
127 ; CHECK-ADD-NEXT: .cfi_restore w29
128 ; CHECK-ADD-NEXT: ret
129 ; CHECK-ADD-NEXT: .LBB0_2: // %entry
130 ; CHECK-ADD-NEXT: .cfi_restore_state
131 ; CHECK-ADD-NEXT: bl __stack_chk_fail
132 ; CHECK-ADD-NEXT: .Lfunc_end0:
133 ; CHECK-ADD-NEXT: .size foo, .Lfunc_end0-foo
134 ; CHECK-ADD-NEXT: .cfi_endproc
135 ; CHECK-ADD-NEXT: // -- End function
136 ; CHECK-ADD-NEXT: .section ".note.GNU-stack","",@progbits
138 %vla = alloca i32, i64 %t, align 4
139 call void @baz(ptr nonnull %vla)
143 declare void @baz(ptr)
145 ; CHECK-BAD-OFFSET: LLVM ERROR: Unable to encode Stack Protector Guard Offset
147 attributes #0 = { sspstrong uwtable }
148 !llvm.module.flags = !{!1, !2, !3}
150 !1 = !{i32 2, !"stack-protector-guard", !"sysreg"}
151 !2 = !{i32 2, !"stack-protector-guard-reg", !"sp_el0"}
154 !3 = !{i32 2, !"stack-protector-guard-offset", i32 0}
156 !3 = !{i32 2, !"stack-protector-guard-offset", i32 8}
158 !3 = !{i32 2, !"stack-protector-guard-offset", i32 -8}
160 !3 = !{i32 2, !"stack-protector-guard-offset", i32 1}
162 !3 = !{i32 2, !"stack-protector-guard-offset", i32 -1}
164 !3 = !{i32 2, !"stack-protector-guard-offset", i32 257}
166 !3 = !{i32 2, !"stack-protector-guard-offset", i32 -257}
168 !3 = !{i32 2, !"stack-protector-guard-offset", i32 32761}
170 !3 = !{i32 2, !"stack-protector-guard-offset", i32 -4096}
172 !3 = !{i32 2, !"stack-protector-guard-offset", i32 4097}