1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -verify-machineinstrs < %s | FileCheck %s
3 ; This file contains a collection of basic tests to ensure we didn't
4 ; screw up normal call lowering when there are no deopt or gc arguments.
6 target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
7 target triple = "x86_64-pc-linux-gnu"
9 %struct = type { i64, i64 }
11 declare zeroext i1 @return_i1()
12 declare zeroext i32 @return_i32()
13 declare i32* @return_i32ptr()
14 declare float @return_float()
15 declare %struct @return_struct()
16 declare void @varargf(i32, ...)
18 define i1 @test_i1_return() gc "statepoint-example" {
19 ; CHECK-LABEL: test_i1_return:
20 ; CHECK: # %bb.0: # %entry
21 ; CHECK-NEXT: pushq %rax
22 ; CHECK-NEXT: .cfi_def_cfa_offset 16
23 ; CHECK-NEXT: callq return_i1
25 ; CHECK-NEXT: popq %rcx
26 ; CHECK-NEXT: .cfi_def_cfa_offset 8
28 ; This is just checking that a i1 gets lowered normally when there's no extra
29 ; state arguments to the statepoint
31 %safepoint_token = tail call token (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0)
32 %call1 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
36 define i32 @test_i32_return() gc "statepoint-example" {
37 ; CHECK-LABEL: test_i32_return:
38 ; CHECK: # %bb.0: # %entry
39 ; CHECK-NEXT: pushq %rax
40 ; CHECK-NEXT: .cfi_def_cfa_offset 16
41 ; CHECK-NEXT: callq return_i32
43 ; CHECK-NEXT: popq %rcx
44 ; CHECK-NEXT: .cfi_def_cfa_offset 8
47 %safepoint_token = tail call token (i64, i32, i32 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i32f(i64 0, i32 0, i32 ()* @return_i32, i32 0, i32 0, i32 0, i32 0)
48 %call1 = call zeroext i32 @llvm.experimental.gc.result.i32(token %safepoint_token)
52 define i32* @test_i32ptr_return() gc "statepoint-example" {
53 ; CHECK-LABEL: test_i32ptr_return:
54 ; CHECK: # %bb.0: # %entry
55 ; CHECK-NEXT: pushq %rax
56 ; CHECK-NEXT: .cfi_def_cfa_offset 16
57 ; CHECK-NEXT: callq return_i32ptr
59 ; CHECK-NEXT: popq %rcx
60 ; CHECK-NEXT: .cfi_def_cfa_offset 8
63 %safepoint_token = tail call token (i64, i32, i32* ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_p0i32f(i64 0, i32 0, i32* ()* @return_i32ptr, i32 0, i32 0, i32 0, i32 0)
64 %call1 = call i32* @llvm.experimental.gc.result.p0i32(token %safepoint_token)
68 define float @test_float_return() gc "statepoint-example" {
69 ; CHECK-LABEL: test_float_return:
70 ; CHECK: # %bb.0: # %entry
71 ; CHECK-NEXT: pushq %rax
72 ; CHECK-NEXT: .cfi_def_cfa_offset 16
73 ; CHECK-NEXT: callq return_float
75 ; CHECK-NEXT: popq %rax
76 ; CHECK-NEXT: .cfi_def_cfa_offset 8
79 %safepoint_token = tail call token (i64, i32, float ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_f32f(i64 0, i32 0, float ()* @return_float, i32 0, i32 0, i32 0, i32 0)
80 %call1 = call float @llvm.experimental.gc.result.f32(token %safepoint_token)
84 define %struct @test_struct_return() gc "statepoint-example" {
85 ; CHECK-LABEL: test_struct_return:
86 ; CHECK: # %bb.0: # %entry
87 ; CHECK-NEXT: pushq %rax
88 ; CHECK-NEXT: .cfi_def_cfa_offset 16
89 ; CHECK-NEXT: callq return_struct
91 ; CHECK-NEXT: popq %rcx
92 ; CHECK-NEXT: .cfi_def_cfa_offset 8
95 %safepoint_token = tail call token (i64, i32, %struct ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_structf(i64 0, i32 0, %struct ()* @return_struct, i32 0, i32 0, i32 0, i32 0)
96 %call1 = call %struct @llvm.experimental.gc.result.struct(token %safepoint_token)
100 define i1 @test_relocate(i32 addrspace(1)* %a) gc "statepoint-example" {
101 ; CHECK-LABEL: test_relocate:
102 ; CHECK: # %bb.0: # %entry
103 ; CHECK-NEXT: pushq %rax
104 ; CHECK-NEXT: .cfi_def_cfa_offset 16
105 ; CHECK-NEXT: movq %rdi, (%rsp)
106 ; CHECK-NEXT: callq return_i1
107 ; CHECK-NEXT: .Ltmp5:
108 ; CHECK-NEXT: popq %rcx
109 ; CHECK-NEXT: .cfi_def_cfa_offset 8
111 ; Check that an ununsed relocate has no code-generation impact
113 %safepoint_token = tail call token (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0, i32 addrspace(1)* %a)
114 %call1 = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 7, i32 7)
115 %call2 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
119 define void @test_void_vararg() gc "statepoint-example" {
120 ; CHECK-LABEL: test_void_vararg:
121 ; CHECK: # %bb.0: # %entry
122 ; CHECK-NEXT: pushq %rax
123 ; CHECK-NEXT: .cfi_def_cfa_offset 16
124 ; CHECK-NEXT: movl $42, %edi
125 ; CHECK-NEXT: movl $43, %esi
126 ; CHECK-NEXT: callq varargf
127 ; CHECK-NEXT: .Ltmp6:
128 ; CHECK-NEXT: popq %rax
129 ; CHECK-NEXT: .cfi_def_cfa_offset 8
131 ; Check a statepoint wrapping a *void* returning vararg function works
133 %safepoint_token = tail call token (i64, i32, void (i32, ...)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidi32varargf(i64 0, i32 0, void (i32, ...)* @varargf, i32 2, i32 0, i32 42, i32 43, i32 0, i32 0)
134 ;; if we try to use the result from a statepoint wrapping a
135 ;; non-void-returning varargf, we will experience a crash.
139 define i1 @test_i1_return_patchable() gc "statepoint-example" {
140 ; CHECK-LABEL: test_i1_return_patchable:
141 ; CHECK: # %bb.0: # %entry
142 ; CHECK-NEXT: pushq %rax
143 ; CHECK-NEXT: .cfi_def_cfa_offset 16
144 ; CHECK-NEXT: xorl %eax, %eax
145 ; CHECK-NEXT: nopl (%rax)
146 ; CHECK-NEXT: .Ltmp7:
147 ; CHECK-NEXT: popq %rcx
148 ; CHECK-NEXT: .cfi_def_cfa_offset 8
150 ; A patchable variant of test_i1_return
152 %safepoint_token = tail call token (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 3, i1 ()*null, i32 0, i32 0, i32 0, i32 0)
153 %call1 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
157 declare void @consume(i32 addrspace(1)* %obj)
159 define i1 @test_cross_bb(i32 addrspace(1)* %a, i1 %external_cond) gc "statepoint-example" {
160 ; CHECK-LABEL: test_cross_bb:
161 ; CHECK: # %bb.0: # %entry
162 ; CHECK-NEXT: pushq %rbp
163 ; CHECK-NEXT: .cfi_def_cfa_offset 16
164 ; CHECK-NEXT: pushq %rbx
165 ; CHECK-NEXT: .cfi_def_cfa_offset 24
166 ; CHECK-NEXT: pushq %rax
167 ; CHECK-NEXT: .cfi_def_cfa_offset 32
168 ; CHECK-NEXT: .cfi_offset %rbx, -24
169 ; CHECK-NEXT: .cfi_offset %rbp, -16
170 ; CHECK-NEXT: movl %esi, %ebp
171 ; CHECK-NEXT: movq %rdi, (%rsp)
172 ; CHECK-NEXT: callq return_i1
173 ; CHECK-NEXT: .Ltmp8:
174 ; CHECK-NEXT: testb $1, %bpl
175 ; CHECK-NEXT: je .LBB8_2
176 ; CHECK-NEXT: # %bb.1: # %left
177 ; CHECK-NEXT: movl %eax, %ebx
178 ; CHECK-NEXT: movq (%rsp), %rdi
179 ; CHECK-NEXT: callq consume
180 ; CHECK-NEXT: movl %ebx, %eax
181 ; CHECK-NEXT: jmp .LBB8_3
182 ; CHECK-NEXT: .LBB8_2: # %right
183 ; CHECK-NEXT: movb $1, %al
184 ; CHECK-NEXT: .LBB8_3: # %right
185 ; CHECK-NEXT: addq $8, %rsp
186 ; CHECK-NEXT: .cfi_def_cfa_offset 24
187 ; CHECK-NEXT: popq %rbx
188 ; CHECK-NEXT: .cfi_def_cfa_offset 16
189 ; CHECK-NEXT: popq %rbp
190 ; CHECK-NEXT: .cfi_def_cfa_offset 8
193 %safepoint_token = tail call token (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0, i32 addrspace(1)* %a)
194 br i1 %external_cond, label %left, label %right
197 %call1 = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 7, i32 7)
198 %call2 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
199 call void @consume(i32 addrspace(1)* %call1)
206 %struct2 = type { i64, i64, i64 }
208 declare void @consume_attributes(i32, i8* nest, i32, %struct2* byval)
210 define void @test_attributes(%struct2* byval %s) gc "statepoint-example" {
211 ; CHECK-LABEL: test_attributes:
212 ; CHECK: # %bb.0: # %entry
213 ; CHECK-NEXT: pushq %rax
214 ; CHECK-NEXT: .cfi_def_cfa_offset 16
215 ; CHECK-NEXT: subq $8, %rsp
216 ; CHECK-NEXT: .cfi_adjust_cfa_offset 8
217 ; CHECK-NEXT: movq {{[0-9]+}}(%rsp), %rax
218 ; CHECK-NEXT: movq {{[0-9]+}}(%rsp), %rcx
219 ; CHECK-NEXT: movq {{[0-9]+}}(%rsp), %rdx
220 ; CHECK-NEXT: movl $42, %edi
221 ; CHECK-NEXT: xorl %r10d, %r10d
222 ; CHECK-NEXT: movl $17, %esi
223 ; CHECK-NEXT: pushq %rax
224 ; CHECK-NEXT: .cfi_adjust_cfa_offset 8
225 ; CHECK-NEXT: pushq %rdx
226 ; CHECK-NEXT: .cfi_adjust_cfa_offset 8
227 ; CHECK-NEXT: pushq %rcx
228 ; CHECK-NEXT: .cfi_adjust_cfa_offset 8
229 ; CHECK-NEXT: callq consume_attributes
230 ; CHECK-NEXT: .Ltmp9:
231 ; CHECK-NEXT: addq $32, %rsp
232 ; CHECK-NEXT: .cfi_adjust_cfa_offset -32
233 ; CHECK-NEXT: popq %rax
234 ; CHECK-NEXT: .cfi_def_cfa_offset 8
237 ; Check that arguments with attributes are lowered correctly.
238 ; We call a function that has a nest argument and a byval argument.
239 %statepoint_token = call token (i64, i32, void (i32, i8*, i32, %struct2*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidi32p0i8i32p0s_struct2sf(i64 0, i32 0, void (i32, i8*, i32, %struct2*)* @consume_attributes, i32 4, i32 0, i32 42, i8* nest null, i32 17, %struct2* byval %s, i32 0, i32 0)
243 declare token @llvm.experimental.gc.statepoint.p0f_i1f(i64, i32, i1 ()*, i32, i32, ...)
244 declare i1 @llvm.experimental.gc.result.i1(token)
246 declare token @llvm.experimental.gc.statepoint.p0f_i32f(i64, i32, i32 ()*, i32, i32, ...)
247 declare i32 @llvm.experimental.gc.result.i32(token)
249 declare token @llvm.experimental.gc.statepoint.p0f_p0i32f(i64, i32, i32* ()*, i32, i32, ...)
250 declare i32* @llvm.experimental.gc.result.p0i32(token)
252 declare token @llvm.experimental.gc.statepoint.p0f_f32f(i64, i32, float ()*, i32, i32, ...)
253 declare float @llvm.experimental.gc.result.f32(token)
255 declare token @llvm.experimental.gc.statepoint.p0f_structf(i64, i32, %struct ()*, i32, i32, ...)
256 declare %struct @llvm.experimental.gc.result.struct(token)
258 declare token @llvm.experimental.gc.statepoint.p0f_isVoidi32varargf(i64, i32, void (i32, ...)*, i32, i32, ...)
260 declare token @llvm.experimental.gc.statepoint.p0f_isVoidi32p0i8i32p0s_struct2sf(i64, i32, void (i32, i8*, i32, %struct2*)*, i32, i32, ...)
262 declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token, i32, i32)