1 ; RUN: llc -mtriple=x86_64-unknown-unknown < %s | FileCheck %s
2 ; RUN: llc -mtriple=x86_64-unknown-unknown -O0 < %s | FileCheck %s -check-prefix=CHECK0
4 %struct.interrupt_frame = type { i64, i64, i64, i64, i64 }
6 @sink_address = dso_local global ptr null
7 @sink_i32 = dso_local global i64 0
9 ; Spills rax, putting original esp at +8.
10 ; No stack adjustment if declared with no error code
11 define x86_intrcc void @test_isr_no_ecode(ptr byval(%struct.interrupt_frame) %frame) {
12 ; CHECK-LABEL: test_isr_no_ecode:
14 ; CHECK: movq 24(%rsp), %rax
17 ; CHECK0-LABEL: test_isr_no_ecode:
19 ; CHECK0: leaq 8(%rsp), %rax
20 ; CHECK0: movq 16(%rax), %rax
23 %pflags = getelementptr inbounds %struct.interrupt_frame, ptr %frame, i32 0, i32 2
24 %flags = load i64, ptr %pflags, align 4
25 call void asm sideeffect "", "r"(i64 %flags)
29 ; Spills rax and rcx, putting original rsp at +16. Stack is adjusted up another 8 bytes
30 ; before return, popping the error code.
31 define x86_intrcc void @test_isr_ecode(ptr byval(%struct.interrupt_frame) %frame, i64 %ecode) {
32 ; CHECK-LABEL: test_isr_ecode
36 ; CHECK: movq 24(%rsp), %rax
37 ; CHECK: movq 48(%rsp), %rcx
40 ; CHECK: addq $16, %rsp
42 ; CHECK0-LABEL: test_isr_ecode
46 ; CHECK0: movq 24(%rsp), %rcx
47 ; CHECK0: leaq 32(%rsp), %rax
48 ; CHECK0: movq 16(%rax), %rax
51 ; CHECK0: addq $16, %rsp
53 %pflags = getelementptr inbounds %struct.interrupt_frame, ptr %frame, i32 0, i32 2
54 %flags = load i64, ptr %pflags, align 4
55 call void asm sideeffect "", "r,r"(i64 %flags, i64 %ecode)
59 ; All clobbered registers must be saved
60 define x86_intrcc void @test_isr_clobbers(ptr byval(%struct.interrupt_frame) %frame, i64 %ecode) {
61 call void asm sideeffect "", "~{rax},~{rbx},~{rbp},~{r11},~{xmm0}"()
62 ; CHECK-LABEL: test_isr_clobbers
69 ; CHECK: movaps {{.*}}, %xmm0
74 ; CHECK: addq $16, %rsp
76 ; CHECK0-LABEL: test_isr_clobbers
82 ; CHECK0: movaps %xmm0
83 ; CHECK0: movaps {{.*}}, %xmm0
88 ; CHECK0: addq $16, %rsp
93 @f80 = common dso_local global x86_fp80 0xK00000000000000000000, align 4
95 ; Test that the presence of x87 does not crash the FP stackifier
96 define x86_intrcc void @test_isr_x87(ptr byval(%struct.interrupt_frame) %frame) {
97 ; CHECK-LABEL: test_isr_x87
101 ; CHECK-NEXT: fstpt f80
104 %ld = load x86_fp80, ptr @f80, align 4
105 %add = fadd x86_fp80 %ld, 0xK3FFF8000000000000000
106 store x86_fp80 %add, ptr @f80, align 4
110 ; Use a frame pointer to check the offsets. No return address, arguments start
112 define dso_local x86_intrcc void @test_fp_1(ptr byval(%struct.interrupt_frame) %p) #0 {
113 ; CHECK-LABEL: test_fp_1:
114 ; CHECK: # %bb.0: # %entry
115 ; CHECK-NEXT: pushq %rbp
116 ; CHECK-NEXT: movq %rsp, %rbp
118 ; CHECK-DAG: leaq 8(%rbp), %[[R1:[^ ]*]]
119 ; CHECK-DAG: leaq 40(%rbp), %[[R2:[^ ]*]]
120 ; CHECK: movq %[[R1]], sink_address
121 ; CHECK: movq %[[R2]], sink_address
125 %arrayidx2 = getelementptr inbounds %struct.interrupt_frame, ptr %p, i64 0, i32 4
126 store volatile ptr %p, ptr @sink_address
127 store volatile ptr %arrayidx2, ptr @sink_address
131 ; The error code is between RBP and the interrupt_frame.
132 define dso_local x86_intrcc void @test_fp_2(ptr byval(%struct.interrupt_frame) %p, i64 %err) #0 {
133 ; CHECK-LABEL: test_fp_2:
134 ; CHECK: # %bb.0: # %entry
135 ; This RAX push is just to align the stack.
136 ; CHECK-NEXT: pushq %rax
137 ; CHECK-NEXT: pushq %rbp
138 ; CHECK-NEXT: movq %rsp, %rbp
140 ; CHECK-DAG: movq 16(%rbp), %[[R3:[^ ]*]]
141 ; CHECK-DAG: leaq 24(%rbp), %[[R1:[^ ]*]]
142 ; CHECK-DAG: leaq 56(%rbp), %[[R2:[^ ]*]]
143 ; CHECK: movq %[[R1]], sink_address(%rip)
144 ; CHECK: movq %[[R2]], sink_address(%rip)
145 ; CHECK: movq %[[R3]], sink_i32(%rip)
147 ; Pop off both the error code and the 8 byte alignment adjustment from the
149 ; CHECK: addq $16, %rsp
152 %arrayidx2 = getelementptr inbounds %struct.interrupt_frame, ptr %p, i64 0, i32 4
153 store volatile ptr %p, ptr @sink_address
154 store volatile ptr %arrayidx2, ptr @sink_address
155 store volatile i64 %err, ptr @sink_i32
159 ; Test argument copy elision when copied to a local alloca.
160 define x86_intrcc void @test_copy_elide(ptr byval(%struct.interrupt_frame) %frame, i64 %err) #0 {
161 ; CHECK-LABEL: test_copy_elide:
162 ; CHECK: # %bb.0: # %entry
163 ; This RAX push is just to align the stack.
164 ; CHECK-NEXT: pushq %rax
165 ; CHECK-NEXT: pushq %rbp
166 ; CHECK-NEXT: movq %rsp, %rbp
168 ; CHECK: leaq 16(%rbp), %[[R1:[^ ]*]]
169 ; CHECK: movq %[[R1]], sink_address(%rip)
171 %err.addr = alloca i64, align 4
172 store i64 %err, ptr %err.addr, align 4
173 store volatile ptr %err.addr, ptr @sink_address
177 define x86_intrcc void @test_stack_allocation(ptr byval(%struct.interrupt_frame) %frame, i64 %err) #1 {
178 ; CHECK-LABEL: test_stack_allocation:
179 ; CHECK: # %bb.0: # %entry
181 ;; Ensure that STACKALLOC_W_PROBING isn't emitted.
182 ; CHECK-NOT: # fixed size alloca with probing
183 ;; Ensure that stack space is allocated.
184 ; CHECK: subq $280, %rsp
186 %some_allocation = alloca i64
187 ;; Call a un-inlineable function to ensure the allocation isn't put in the red zone.
188 call void @external_function(ptr %some_allocation)
192 declare void @external_function(ptr)
194 attributes #0 = { nounwind "frame-pointer"="all" }
195 attributes #1 = { nounwind "probe-stack"="inline-asm" }