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 --check-prefix=CHECK-257-OFFSET %s
24; RUN: llc %t/g2.ll -verify-machineinstrs -o - | \
25; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-MINUS-257-OFFSET %s
26
27; XFAIL
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
34
35;--- main.ll
36
37target triple = "aarch64-unknown-linux-gnu"
38
39; Verify that we `mrs` from `SP_EL0` twice, rather than load from
40; __stack_chk_guard.
41define dso_local void @foo(i64 %t) local_unnamed_addr #0 {
42; CHECK-LABEL:   foo:
43; CHECK:         // %bb.0: // %entry
44; CHECK-NEXT:    stp x29, x30, [sp, #-16]! // 16-byte Folded Spill
45; CHECK-NEXT:    mov x29, sp
46; CHECK-NEXT:    sub sp, sp, #16
47; CHECK-NEXT:    .cfi_def_cfa w29, 16
48; CHECK-NEXT:    .cfi_offset w30, -8
49; CHECK-NEXT:    .cfi_offset w29, -16
50; CHECK-NEXT:    mrs x8, SP_EL0
51; CHECK-NEXT:    lsl x9, x0, #2
52; CHECK-NO-OFFSET:       ldr x8, [x8]
53; CHECK-POSITIVE-OFFSET: ldr x8, [x8, #8]
54; CHECK-NEGATIVE-OFFSET: ldur x8, [x8, #-8]
55; CHECK-NPOT-OFFSET:     ldur x8, [x8, #1]
56; CHECK-NPOT-NEG-OFFSET: ldur x8, [x8, #-1]
57; CHECK-257-OFFSET:      add x8, x8, #257
58; CHECK-MINUS-257-OFFSET:      sub x8, x8, #257
59; CHECK-NEXT:    add x9, x9, #15
60; CHECK-NEXT:    and x9, x9, #0xfffffffffffffff0
61; CHECK-257-OFFSET-NEXT: ldr x8, [x8]
62; CHECK-MINUS-257-OFFSET-NEXT: ldr x8, [x8]
63; CHECK-NEXT:    stur x8, [x29, #-8]
64; CHECK-NEXT:    mov x8, sp
65; CHECK-NEXT:    sub x0, x8, x9
66; CHECK-NEXT:    mov sp, x0
67; CHECK-NEXT:    bl baz
68; CHECK-NEXT:    mrs x8, SP_EL0
69; CHECK-NO-OFFSET:       ldr x8, [x8]
70; CHECK-POSITIVE-OFFSET: ldr x8, [x8, #8]
71; CHECK-NEGATIVE-OFFSET: ldur x8, [x8, #-8]
72; CHECK-NPOT-OFFSET:     ldur x8, [x8, #1]
73; CHECK-NPOT-NEG-OFFSET: ldur x8, [x8, #-1]
74; CHECK-257-OFFSET:      add x8, x8, #257
75; CHECK-257-OFFSET-NEXT: ldr x8, [x8]
76; CHECK-MINUS-257-OFFSET:      sub x8, x8, #257
77; CHECK-MINUS-257-OFFSET-NEXT: ldr x8, [x8]
78; CHECK-NEXT:    ldur x9, [x29, #-8]
79; CHECK-NEXT:    cmp x8, x9
80; CHECK-NEXT:    b.ne .LBB0_2
81; CHECK-NEXT:  // %bb.1: // %entry
82; CHECK-NEXT:    mov sp, x29
83; CHECK-NEXT:    ldp x29, x30, [sp], #16 // 16-byte Folded Reload
84; CHECK-NEXT:    ret
85; CHECK-NEXT:  .LBB0_2: // %entry
86; CHECK-NEXT:    bl __stack_chk_fail
87; CHECK-NOT: __stack_chk_guard
88entry:
89  %vla = alloca i32, i64 %t, align 4
90  call void @baz(i32* nonnull %vla)
91  ret void
92}
93
94declare void @baz(i32*)
95
96; CHECK-BAD-OFFSET: LLVM ERROR: Unable to encode Stack Protector Guard Offset
97
98attributes #0 = { sspstrong }
99!llvm.module.flags = !{!1, !2, !3}
100
101!1 = !{i32 2, !"stack-protector-guard", !"sysreg"}
102!2 = !{i32 2, !"stack-protector-guard-reg", !"sp_el0"}
103
104;--- a.ll
105!3 = !{i32 2, !"stack-protector-guard-offset", i32 0}
106;--- b.ll
107!3 = !{i32 2, !"stack-protector-guard-offset", i32 8}
108;--- c.ll
109!3 = !{i32 2, !"stack-protector-guard-offset", i32 -8}
110;--- d.ll
111!3 = !{i32 2, !"stack-protector-guard-offset", i32 1}
112;--- e.ll
113!3 = !{i32 2, !"stack-protector-guard-offset", i32 -1}
114;--- f.ll
115!3 = !{i32 2, !"stack-protector-guard-offset", i32 257}
116;--- g.ll
117!3 = !{i32 2, !"stack-protector-guard-offset", i32 -257}
118;--- h.ll
119!3 = !{i32 2, !"stack-protector-guard-offset", i32 32761}
120;--- i.ll
121!3 = !{i32 2, !"stack-protector-guard-offset", i32 -4096}
122;--- j.ll
123!3 = !{i32 2, !"stack-protector-guard-offset", i32 4097}
124