1 ; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s --check-prefix=X64
2 ; RUN: llc -mtriple=i686-windows-msvc < %s | FileCheck %s --check-prefix=X86
4 declare ptr @llvm.frameaddress(i32)
5 declare void @llvm.localescape(...)
6 declare ptr @llvm.localaddress()
7 declare ptr @llvm.localrecover(ptr, ptr, i32)
8 declare i32 @printf(ptr, ...)
10 @str = internal constant [10 x i8] c"asdf: %d\0A\00"
12 define void @print_framealloc_from_fp(ptr %fp) {
13 %a.i8 = call ptr @llvm.localrecover(ptr @alloc_func, ptr %fp, i32 0)
14 %a.val = load i32, ptr %a.i8
15 call i32 (ptr, ...) @printf(ptr @str, i32 %a.val)
16 %b.i8 = call ptr @llvm.localrecover(ptr @alloc_func, ptr %fp, i32 1)
17 %b.val = load i32, ptr %b.i8
18 call i32 (ptr, ...) @printf(ptr @str, i32 %b.val)
19 store i32 42, ptr %b.i8
20 %b2 = getelementptr i32, ptr %b.i8, i32 1
21 %b2.val = load i32, ptr %b2
22 call i32 (ptr, ...) @printf(ptr @str, i32 %b2.val)
26 ; X64-LABEL: print_framealloc_from_fp:
27 ; X64: movq %rcx, %[[parent_fp:[a-z]+]]
28 ; X64: movl .Lalloc_func$frame_escape_0(%rcx), %edx
29 ; X64: leaq {{.*}}(%rip), %[[str:[a-z]+]]
30 ; X64: movq %[[str]], %rcx
32 ; X64: movl .Lalloc_func$frame_escape_1(%[[parent_fp]]), %edx
33 ; X64: movq %[[str]], %rcx
35 ; X64: movl $42, .Lalloc_func$frame_escape_1(%[[parent_fp]])
38 ; X86-LABEL: print_framealloc_from_fp:
40 ; X86: movl 8(%esp), %esi
41 ; X86: pushl Lalloc_func$frame_escape_0(%esi)
45 ; X86: pushl Lalloc_func$frame_escape_1(%esi)
49 ; X86: movl $42, Lalloc_func$frame_escape_1(%esi)
51 ; X86: pushl Lalloc_func$frame_escape_1(%esi,%eax)
58 define void @alloc_func(i32 %n) {
60 %b = alloca i32, i32 2
61 call void (...) @llvm.localescape(ptr %a, ptr %b)
65 ; Force usage of EBP with a dynamic alloca.
68 %lp = call ptr @llvm.localaddress()
69 call void @print_framealloc_from_fp(ptr %lp)
73 ; X64-LABEL: alloc_func:
76 ; X64: .seh_stackalloc 16
77 ; X64: leaq 16(%rsp), %rbp
78 ; X64: .seh_setframe %rbp, 16
79 ; X64: .set .Lalloc_func$frame_escape_0, -4
80 ; X64: .set .Lalloc_func$frame_escape_1, -12
81 ; X64: movl $42, -4(%rbp)
82 ; X64: movl $13, -12(%rbp)
83 ; X64: movq %rbp, %rcx
84 ; X64: callq print_framealloc_from_fp
87 ; X86-LABEL: alloc_func:
89 ; X86: movl %esp, %ebp
91 ; X86: .set Lalloc_func$frame_escape_0, -4
92 ; X86: .set Lalloc_func$frame_escape_1, -12
93 ; X86: movl $42, -4(%ebp)
94 ; X86: movl $13, -12(%ebp)
96 ; X86: calll _print_framealloc_from_fp
97 ; X86: movl %ebp, %esp
101 ; Helper to make this a complete program so it can be compiled and tested.
103 call void @alloc_func(i32 3)
107 define void @alloc_func_no_frameaddr() {
110 call void (...) @llvm.localescape(ptr %a, ptr %b)
113 call void @print_framealloc_from_fp(ptr null)
117 ; X64-LABEL: alloc_func_no_frameaddr:
118 ; X64: subq $40, %rsp
119 ; X64: .seh_stackalloc 40
120 ; X64: .seh_endprologue
121 ; X64: .set .Lalloc_func_no_frameaddr$frame_escape_0, 36
122 ; X64: .set .Lalloc_func_no_frameaddr$frame_escape_1, 32
123 ; X64: movl $42, 36(%rsp)
124 ; X64: movl $13, 32(%rsp)
125 ; X64: xorl %ecx, %ecx
126 ; X64: callq print_framealloc_from_fp
127 ; X64: addq $40, %rsp
130 ; X86-LABEL: alloc_func_no_frameaddr:
132 ; X86: .set Lalloc_func_no_frameaddr$frame_escape_0, 4
133 ; X86: .set Lalloc_func_no_frameaddr$frame_escape_1, 0
134 ; X86: movl $42, 4(%esp)
135 ; X86: movl $13, (%esp)
137 ; X86: calll _print_framealloc_from_fp
138 ; X86: addl $12, %esp