193 lines · plain
1; RUN: llc -mtriple=x86_64-unknown-unknown < %s | FileCheck %s2; RUN: llc -mtriple=x86_64-unknown-unknown -O0 < %s | FileCheck %s -check-prefix=CHECK03 4%struct.interrupt_frame = type { i64, i64, i64, i64, i64 }5 6@sink_address = dso_local global ptr null7@sink_i32 = dso_local global i64 08 9; Spills rax, putting original esp at +8.10; No stack adjustment if declared with no error code11define x86_intrcc void @test_isr_no_ecode(ptr byval(%struct.interrupt_frame) %frame) {12 ; CHECK-LABEL: test_isr_no_ecode:13 ; CHECK: pushq %rax14 ; CHECK: movq 24(%rsp), %rax15 ; CHECK: popq %rax16 ; CHECK: iretq17 ; CHECK0-LABEL: test_isr_no_ecode:18 ; CHECK0: pushq %rax19 ; CHECK0: leaq 8(%rsp), %rax20 ; CHECK0: movq 16(%rax), %rax21 ; CHECK0: popq %rax22 ; CHECK0: iretq23 %pflags = getelementptr inbounds %struct.interrupt_frame, ptr %frame, i32 0, i32 224 %flags = load i64, ptr %pflags, align 425 call void asm sideeffect "", "r"(i64 %flags)26 ret void27}28 29; Spills rax and rcx, putting original rsp at +16. Stack is adjusted up another 8 bytes30; before return, popping the error code.31define x86_intrcc void @test_isr_ecode(ptr byval(%struct.interrupt_frame) %frame, i64 %ecode) {32 ; CHECK-LABEL: test_isr_ecode33 ; CHECK: pushq %rax34 ; CHECK: pushq %rax35 ; CHECK: pushq %rcx36 ; CHECK: movq 24(%rsp), %rax37 ; CHECK: movq 48(%rsp), %rcx38 ; CHECK: popq %rcx39 ; CHECK: popq %rax40 ; CHECK: addq $16, %rsp41 ; CHECK: iretq42 ; CHECK0-LABEL: test_isr_ecode43 ; CHECK0: pushq %rax44 ; CHECK0: pushq %rax45 ; CHECK0: pushq %rcx46 ; CHECK0: movq 24(%rsp), %rcx47 ; CHECK0: leaq 32(%rsp), %rax48 ; CHECK0: movq 16(%rax), %rax49 ; CHECK0: popq %rcx50 ; CHECK0: popq %rax51 ; CHECK0: addq $16, %rsp52 ; CHECK0: iretq53 %pflags = getelementptr inbounds %struct.interrupt_frame, ptr %frame, i32 0, i32 254 %flags = load i64, ptr %pflags, align 455 call void asm sideeffect "", "r,r"(i64 %flags, i64 %ecode)56 ret void57}58 59; All clobbered registers must be saved60define 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_clobbers63 64 ; CHECK: pushq %rax65 ; CHECK: pushq %rbp66 ; CHECK: pushq %r1167 ; CHECK: pushq %rbx68 ; CHECK: movaps %xmm069 ; CHECK: movaps {{.*}}, %xmm070 ; CHECK: popq %rbx71 ; CHECK: popq %r1172 ; CHECK: popq %rbp73 ; CHECK: popq %rax74 ; CHECK: addq $16, %rsp75 ; CHECK: iretq76 ; CHECK0-LABEL: test_isr_clobbers77 78 ; CHECK0: pushq %rax79 ; CHECK0: pushq %rbp80 ; CHECK0: pushq %r1181 ; CHECK0: pushq %rbx82 ; CHECK0: movaps %xmm083 ; CHECK0: movaps {{.*}}, %xmm084 ; CHECK0: popq %rbx85 ; CHECK0: popq %r1186 ; CHECK0: popq %rbp87 ; CHECK0: popq %rax88 ; CHECK0: addq $16, %rsp89 ; CHECK0: iretq90 ret void91}92 93@f80 = common dso_local global x86_fp80 0xK00000000000000000000, align 494 95; Test that the presence of x87 does not crash the FP stackifier96define x86_intrcc void @test_isr_x87(ptr byval(%struct.interrupt_frame) %frame) {97 ; CHECK-LABEL: test_isr_x8798 ; CHECK-DAG: fldt f8099 ; CHECK-DAG: fld1100 ; CHECK: faddp101 ; CHECK-NEXT: fstpt f80102 ; CHECK-NEXT: iretq103entry:104 %ld = load x86_fp80, ptr @f80, align 4105 %add = fadd x86_fp80 %ld, 0xK3FFF8000000000000000106 store x86_fp80 %add, ptr @f80, align 4107 ret void108}109 110; Use a frame pointer to check the offsets. No return address, arguments start111; at RBP+4.112define 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: # %entry115 ; CHECK-NEXT: pushq %rbp116 ; CHECK-NEXT: movq %rsp, %rbp117 ; CHECK-DAG: leaq 8(%rbp), %[[R1:[^ ]*]]118 ; CHECK-DAG: leaq 40(%rbp), %[[R2:[^ ]*]]119 ; CHECK: movq %[[R1]], sink_address120 ; CHECK: movq %[[R2]], sink_address121 ; CHECK: popq %rbp122 ; CHECK: iretq123entry:124 %arrayidx2 = getelementptr inbounds %struct.interrupt_frame, ptr %p, i64 0, i32 4125 store volatile ptr %p, ptr @sink_address126 store volatile ptr %arrayidx2, ptr @sink_address127 ret void128}129 130; The error code is between RBP and the interrupt_frame.131define dso_local x86_intrcc void @test_fp_2(ptr byval(%struct.interrupt_frame) %p, i64 %err) #0 {132 ; CHECK-LABEL: test_fp_2:133 ; CHECK: # %bb.0: # %entry134 ; This RAX push is just to align the stack.135 ; CHECK-NEXT: pushq %rax136 ; CHECK-NEXT: pushq %rbp137 ; CHECK-NEXT: movq %rsp, %rbp138 ; CHECK-DAG: movq 16(%rbp), %[[R3:[^ ]*]]139 ; CHECK-DAG: leaq 24(%rbp), %[[R1:[^ ]*]]140 ; CHECK-DAG: leaq 56(%rbp), %[[R2:[^ ]*]]141 ; CHECK: movq %[[R1]], sink_address(%rip)142 ; CHECK: movq %[[R2]], sink_address(%rip)143 ; CHECK: movq %[[R3]], sink_i32(%rip)144 ; CHECK: popq %rbp145 ; Pop off both the error code and the 8 byte alignment adjustment from the146 ; prologue.147 ; CHECK: addq $16, %rsp148 ; CHECK: iretq149entry:150 %arrayidx2 = getelementptr inbounds %struct.interrupt_frame, ptr %p, i64 0, i32 4151 store volatile ptr %p, ptr @sink_address152 store volatile ptr %arrayidx2, ptr @sink_address153 store volatile i64 %err, ptr @sink_i32154 ret void155}156 157; Test argument copy elision when copied to a local alloca.158define x86_intrcc void @test_copy_elide(ptr byval(%struct.interrupt_frame) %frame, i64 %err) #0 {159 ; CHECK-LABEL: test_copy_elide:160 ; CHECK: # %bb.0: # %entry161 ; This RAX push is just to align the stack.162 ; CHECK-NEXT: pushq %rax163 ; CHECK-NEXT: pushq %rbp164 ; CHECK-NEXT: movq %rsp, %rbp165 ; CHECK: leaq 16(%rbp), %[[R1:[^ ]*]]166 ; CHECK: movq %[[R1]], sink_address(%rip)167entry:168 %err.addr = alloca i64, align 4169 store i64 %err, ptr %err.addr, align 4170 store volatile ptr %err.addr, ptr @sink_address171 ret void172}173 174define x86_intrcc void @test_stack_allocation(ptr byval(%struct.interrupt_frame) %frame, i64 %err) #1 {175 ; CHECK-LABEL: test_stack_allocation:176 ; CHECK: # %bb.0: # %entry177 178 ;; Ensure that STACKALLOC_W_PROBING isn't emitted.179 ; CHECK-NOT: # fixed size alloca with probing180 ;; Ensure that stack space is allocated.181 ; CHECK: subq $280, %rsp182entry:183 %some_allocation = alloca i64184 ;; Call a un-inlineable function to ensure the allocation isn't put in the red zone.185 call void @external_function(ptr %some_allocation)186 ret void187}188 189declare void @external_function(ptr)190 191attributes #0 = { nounwind "frame-pointer"="all" }192attributes #1 = { nounwind "probe-stack"="inline-asm" }193