1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -verify-machineinstrs < %s | FileCheck %s
3 ; RUN: llc -verify-machineinstrs -opaque-pointers < %s | FileCheck %s
4 ; This file contains a collection of basic tests to ensure we didn't
5 ; screw up normal call lowering when there are no deopt or gc arguments.
7 target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
8 target triple = "x86_64-pc-linux-gnu"
10 %struct = type { i64, i64 }
12 declare zeroext i1 @return_i1()
13 declare zeroext i32 @return_i32()
14 declare ptr @return_i32ptr()
15 declare float @return_float()
16 declare %struct @return_struct()
17 declare void @varargf(i32, ...)
19 define i1 @test_i1_return() gc "statepoint-example" {
20 ; CHECK-LABEL: test_i1_return:
21 ; CHECK: # %bb.0: # %entry
22 ; CHECK-NEXT: pushq %rax
23 ; CHECK-NEXT: .cfi_def_cfa_offset 16
24 ; CHECK-NEXT: callq return_i1@PLT
26 ; CHECK-NEXT: popq %rcx
27 ; CHECK-NEXT: .cfi_def_cfa_offset 8
29 ; This is just checking that a i1 gets lowered normally when there's no extra
30 ; state arguments to the statepoint
32 %safepoint_token = tail call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(i1 ()) @return_i1, i32 0, i32 0, i32 0, i32 0)
33 %call1 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
37 define i32 @test_i32_return() gc "statepoint-example" {
38 ; CHECK-LABEL: test_i32_return:
39 ; CHECK: # %bb.0: # %entry
40 ; CHECK-NEXT: pushq %rax
41 ; CHECK-NEXT: .cfi_def_cfa_offset 16
42 ; CHECK-NEXT: callq return_i32@PLT
44 ; CHECK-NEXT: popq %rcx
45 ; CHECK-NEXT: .cfi_def_cfa_offset 8
48 %safepoint_token = tail call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(i32 ()) @return_i32, i32 0, i32 0, i32 0, i32 0)
49 %call1 = call zeroext i32 @llvm.experimental.gc.result.i32(token %safepoint_token)
53 define ptr @test_i32ptr_return() gc "statepoint-example" {
54 ; CHECK-LABEL: test_i32ptr_return:
55 ; CHECK: # %bb.0: # %entry
56 ; CHECK-NEXT: pushq %rax
57 ; CHECK-NEXT: .cfi_def_cfa_offset 16
58 ; CHECK-NEXT: callq return_i32ptr@PLT
60 ; CHECK-NEXT: popq %rcx
61 ; CHECK-NEXT: .cfi_def_cfa_offset 8
64 %safepoint_token = tail call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(ptr ()) @return_i32ptr, i32 0, i32 0, i32 0, i32 0)
65 %call1 = call ptr @llvm.experimental.gc.result.p0(token %safepoint_token)
69 define float @test_float_return() gc "statepoint-example" {
70 ; CHECK-LABEL: test_float_return:
71 ; CHECK: # %bb.0: # %entry
72 ; CHECK-NEXT: pushq %rax
73 ; CHECK-NEXT: .cfi_def_cfa_offset 16
74 ; CHECK-NEXT: callq return_float@PLT
76 ; CHECK-NEXT: popq %rax
77 ; CHECK-NEXT: .cfi_def_cfa_offset 8
80 %safepoint_token = tail call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(float ()) @return_float, i32 0, i32 0, i32 0, i32 0)
81 %call1 = call float @llvm.experimental.gc.result.f32(token %safepoint_token)
85 define %struct @test_struct_return() gc "statepoint-example" {
86 ; CHECK-LABEL: test_struct_return:
87 ; CHECK: # %bb.0: # %entry
88 ; CHECK-NEXT: pushq %rax
89 ; CHECK-NEXT: .cfi_def_cfa_offset 16
90 ; CHECK-NEXT: callq return_struct@PLT
92 ; CHECK-NEXT: popq %rcx
93 ; CHECK-NEXT: .cfi_def_cfa_offset 8
96 %safepoint_token = tail call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(%struct ()) @return_struct, i32 0, i32 0, i32 0, i32 0)
97 %call1 = call %struct @llvm.experimental.gc.result.struct(token %safepoint_token)
101 define i1 @test_relocate(ptr addrspace(1) %a) gc "statepoint-example" {
102 ; CHECK-LABEL: test_relocate:
103 ; CHECK: # %bb.0: # %entry
104 ; CHECK-NEXT: pushq %rax
105 ; CHECK-NEXT: .cfi_def_cfa_offset 16
106 ; CHECK-NEXT: movq %rdi, (%rsp)
107 ; CHECK-NEXT: callq return_i1@PLT
108 ; CHECK-NEXT: .Ltmp5:
109 ; CHECK-NEXT: popq %rcx
110 ; CHECK-NEXT: .cfi_def_cfa_offset 8
112 ; Check that an ununsed relocate has no code-generation impact
114 %safepoint_token = tail call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(i1 ()) @return_i1, i32 0, i32 0, i32 0, i32 0) ["gc-live" (ptr addrspace(1) %a)]
115 %call1 = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)
116 %call2 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
120 define void @test_void_vararg() gc "statepoint-example" {
121 ; CHECK-LABEL: test_void_vararg:
122 ; CHECK: # %bb.0: # %entry
123 ; CHECK-NEXT: pushq %rax
124 ; CHECK-NEXT: .cfi_def_cfa_offset 16
125 ; CHECK-NEXT: movl $42, %edi
126 ; CHECK-NEXT: movl $43, %esi
127 ; CHECK-NEXT: callq varargf@PLT
128 ; CHECK-NEXT: .Ltmp6:
129 ; CHECK-NEXT: popq %rax
130 ; CHECK-NEXT: .cfi_def_cfa_offset 8
132 ; Check a statepoint wrapping a *ptr returning vararg function works
134 %safepoint_token = tail call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void (i32, ...)) @varargf, i32 2, i32 0, i32 42, i32 43, i32 0, i32 0)
135 ;; if we try to use the result from a statepoint wrapping a
136 ;; non-void-returning varargf, we will experience a crash.
140 define i1 @test_i1_return_patchable() gc "statepoint-example" {
141 ; CHECK-LABEL: test_i1_return_patchable:
142 ; CHECK: # %bb.0: # %entry
143 ; CHECK-NEXT: pushq %rax
144 ; CHECK-NEXT: .cfi_def_cfa_offset 16
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, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 3, ptr elementtype(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(ptr addrspace(1) %obj)
159 define i1 @test_cross_bb(ptr 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@PLT
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@PLT
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, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(i1 ()) @return_i1, i32 0, i32 0, i32 0, i32 0) ["gc-live" (ptr addrspace(1) %a)]
194 br i1 %external_cond, label %left, label %right
197 %call1 = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)
198 %call2 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
199 call void @consume(ptr addrspace(1) %call1)
206 %struct2 = type { i64, i64, i64 }
208 declare void @consume_attributes(i32, ptr nest, i32, ptr byval(%struct2))
210 define void @test_attributes(ptr byval(%struct2) %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@PLT
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, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void (i32, ptr, i32, ptr)) @consume_attributes, i32 4, i32 0, i32 42, ptr nest null, i32 17, ptr byval(%struct2) %s, i32 0, i32 0)
243 declare token @llvm.experimental.gc.statepoint.p0(i64, i32, ptr, i32, i32, ...)
244 declare i1 @llvm.experimental.gc.result.i1(token)
246 declare i32 @llvm.experimental.gc.result.i32(token)
248 declare ptr @llvm.experimental.gc.result.p0(token)
250 declare float @llvm.experimental.gc.result.f32(token)
252 declare %struct @llvm.experimental.gc.result.struct(token)
256 declare ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token, i32, i32)