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 = global i64* null
7 @sink_i32 = 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(%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, %struct.interrupt_frame* %frame, i32 0, i32 2
24 %flags = load i64, i64* %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(%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), %rax
47 ; CHECK0: leaq 32(%rsp), %rcx
48 ; CHECK0: movq 16(%rcx), %rcx
51 ; CHECK0: addq $16, %rsp
53 %pflags = getelementptr inbounds %struct.interrupt_frame, %struct.interrupt_frame* %frame, i32 0, i32 2
54 %flags = load i64, i64* %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(%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 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(%struct.interrupt_frame* %frame) {
97 ; CHECK-LABEL: test_isr_x87
101 ; CHECK-NEXT: fstpt f80
104 %ld = load x86_fp80, x86_fp80* @f80, align 4
105 %add = fadd x86_fp80 %ld, 0xK3FFF8000000000000000
106 store x86_fp80 %add, x86_fp80* @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(%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 %arrayidx = getelementptr inbounds %struct.interrupt_frame, %struct.interrupt_frame* %p, i64 0, i32 0
126 %arrayidx2 = getelementptr inbounds %struct.interrupt_frame, %struct.interrupt_frame* %p, i64 0, i32 4
127 store volatile i64* %arrayidx, i64** @sink_address
128 store volatile i64* %arrayidx2, i64** @sink_address
132 ; The error code is between RBP and the interrupt_frame.
133 define dso_local x86_intrcc void @test_fp_2(%struct.interrupt_frame* %p, i64 %err) #0 {
134 ; CHECK-LABEL: test_fp_2:
135 ; CHECK: # %bb.0: # %entry
136 ; This RAX push is just to align the stack.
137 ; CHECK-NEXT: pushq %rax
138 ; CHECK-NEXT: pushq %rbp
139 ; CHECK-NEXT: movq %rsp, %rbp
141 ; CHECK-DAG: movq 16(%rbp), %[[R3:[^ ]*]]
142 ; CHECK-DAG: leaq 24(%rbp), %[[R1:[^ ]*]]
143 ; CHECK-DAG: leaq 56(%rbp), %[[R2:[^ ]*]]
144 ; CHECK: movq %[[R1]], sink_address(%rip)
145 ; CHECK: movq %[[R2]], sink_address(%rip)
146 ; CHECK: movq %[[R3]], sink_i32(%rip)
148 ; Pop off both the error code and the 8 byte alignment adjustment from the
150 ; CHECK: addq $16, %rsp
153 %arrayidx = getelementptr inbounds %struct.interrupt_frame, %struct.interrupt_frame* %p, i64 0, i32 0
154 %arrayidx2 = getelementptr inbounds %struct.interrupt_frame, %struct.interrupt_frame* %p, i64 0, i32 4
155 store volatile i64* %arrayidx, i64** @sink_address
156 store volatile i64* %arrayidx2, i64** @sink_address
157 store volatile i64 %err, i64* @sink_i32
161 ; Test argument copy elision when copied to a local alloca.
162 define x86_intrcc void @test_copy_elide(%struct.interrupt_frame* %frame, i64 %err) #0 {
163 ; CHECK-LABEL: test_copy_elide:
164 ; CHECK: # %bb.0: # %entry
165 ; This RAX push is just to align the stack.
166 ; CHECK-NEXT: pushq %rax
167 ; CHECK-NEXT: pushq %rbp
168 ; CHECK-NEXT: movq %rsp, %rbp
170 ; CHECK: leaq 16(%rbp), %[[R1:[^ ]*]]
171 ; CHECK: movq %[[R1]], sink_address(%rip)
173 %err.addr = alloca i64, align 4
174 store i64 %err, i64* %err.addr, align 4
175 store volatile i64* %err.addr, i64** @sink_address
180 attributes #0 = { nounwind "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" }