1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc < %s -mtriple=arm64-apple-ios -relocation-model=pic -frame-pointer=all | FileCheck %s
3
4@__stack_chk_guard = external global i64*
5
6; PR20558
7
8define i32 @test_stack_guard_remat2() ssp {
9; CHECK-LABEL: test_stack_guard_remat2:
10; CHECK:       ; %bb.0: ; %entry
11; CHECK-NEXT:    sub sp, sp, #64 ; =64
12; CHECK-NEXT:    stp x29, x30, [sp, #48] ; 16-byte Folded Spill
13; CHECK-NEXT:    add x29, sp, #48 ; =48
14; CHECK-NEXT:    .cfi_def_cfa w29, 16
15; CHECK-NEXT:    .cfi_offset w30, -8
16; CHECK-NEXT:    .cfi_offset w29, -16
17; CHECK-NEXT:  Lloh0:
18; CHECK-NEXT:    adrp x8, ___stack_chk_guard@GOTPAGE
19; CHECK-NEXT:  Lloh1:
20; Load the stack guard for the second time, just in case the previous value gets spilled.
21; CHECK-NEXT:    adrp x9, ___stack_chk_guard@GOTPAGE
22; CHECK-NEXT:  Lloh2:
23; CHECK-NEXT:    ldr x8, [x8, ___stack_chk_guard@GOTPAGEOFF]
24; CHECK-NEXT:  Lloh3:
25; CHECK-NEXT:    ldr x9, [x9, ___stack_chk_guard@GOTPAGEOFF]
26; CHECK-NEXT:  Lloh4:
27; CHECK-NEXT:    ldr x8, [x8]
28; CHECK-NEXT:  Lloh5:
29; CHECK-NEXT:    ldr x9, [x9]
30; CHECK-NEXT:    str x8, [sp]
31; CHECK-NEXT:    stur x9, [x29, #-8]
32; CHECK-NEXT:  Lloh6:
33; CHECK-NEXT:    adrp x9, ___stack_chk_guard@GOTPAGE
34; CHECK-NEXT:    ldur x8, [x29, #-8]
35; CHECK-NEXT:  Lloh7:
36; CHECK-NEXT:    ldr x9, [x9, ___stack_chk_guard@GOTPAGEOFF]
37; CHECK-NEXT:  Lloh8:
38; CHECK-NEXT:    ldr x9, [x9]
39; CHECK-NEXT:    cmp x9, x8
40; CHECK-NEXT:    b.ne LBB0_2
41; CHECK-NEXT:  ; %bb.1: ; %entry
42; CHECK-NEXT:    ldp x29, x30, [sp, #48] ; 16-byte Folded Reload
43; CHECK-NEXT:    mov w0, #-1
44; CHECK-NEXT:    add sp, sp, #64 ; =64
45; CHECK-NEXT:    ret
46; CHECK-NEXT:  LBB0_2: ; %entry
47; CHECK-NEXT:    bl ___stack_chk_fail
48; CHECK-NEXT:    .loh AdrpLdrGotLdr Lloh6, Lloh7, Lloh8
49; CHECK-NEXT:    .loh AdrpLdrGotLdr Lloh1, Lloh3, Lloh5
50; CHECK-NEXT:    .loh AdrpLdrGotLdr Lloh0, Lloh2, Lloh4
51entry:
52  %StackGuardSlot = alloca i8*
53  %StackGuard = load i8*, i8** bitcast (i64** @__stack_chk_guard to i8**)
54  call void @llvm.stackprotector(i8* %StackGuard, i8** %StackGuardSlot)
55  %container = alloca [32 x i8], align 1
56  call void @llvm.stackprotectorcheck(i8** bitcast (i64** @__stack_chk_guard to i8**))
57  ret i32 -1
58}
59
60declare void @llvm.stackprotector(i8*, i8**) ssp
61declare void @llvm.stackprotectorcheck(i8**) ssp
62