1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -verify-machineinstrs < %s | FileCheck %s
3 ; A collection of basic functionality tests for statepoint lowering - most
4 ; interesting cornercases are exercised through the x86 tests.
6 target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
7 target triple = "riscv64"
9 %struct = type { i64, i64 }
11 declare zeroext i1 @return_i1()
12 declare zeroext i32 @return_i32()
13 declare ptr @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: addi sp, sp, -16
22 ; CHECK-NEXT: .cfi_def_cfa_offset 16
23 ; CHECK-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
24 ; CHECK-NEXT: .cfi_offset ra, -8
25 ; CHECK-NEXT: call return_i1
27 ; CHECK-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
28 ; CHECK-NEXT: addi sp, sp, 16
30 ; This is just checking that a i1 gets lowered normally when there's no extra
31 ; state arguments to the statepoint
33 %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)
34 %call1 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
38 define i32 @test_i32_return() gc "statepoint-example" {
39 ; CHECK-LABEL: test_i32_return:
40 ; CHECK: # %bb.0: # %entry
41 ; CHECK-NEXT: addi sp, sp, -16
42 ; CHECK-NEXT: .cfi_def_cfa_offset 16
43 ; CHECK-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
44 ; CHECK-NEXT: .cfi_offset ra, -8
45 ; CHECK-NEXT: call return_i32
47 ; CHECK-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
48 ; CHECK-NEXT: addi sp, sp, 16
51 %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)
52 %call1 = call zeroext i32 @llvm.experimental.gc.result.i32(token %safepoint_token)
56 define ptr @test_i32ptr_return() gc "statepoint-example" {
57 ; CHECK-LABEL: test_i32ptr_return:
58 ; CHECK: # %bb.0: # %entry
59 ; CHECK-NEXT: addi sp, sp, -16
60 ; CHECK-NEXT: .cfi_def_cfa_offset 16
61 ; CHECK-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
62 ; CHECK-NEXT: .cfi_offset ra, -8
63 ; CHECK-NEXT: call return_i32ptr
65 ; CHECK-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
66 ; CHECK-NEXT: addi sp, sp, 16
69 %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)
70 %call1 = call ptr @llvm.experimental.gc.result.p0(token %safepoint_token)
74 define float @test_float_return() gc "statepoint-example" {
75 ; CHECK-LABEL: test_float_return:
76 ; CHECK: # %bb.0: # %entry
77 ; CHECK-NEXT: addi sp, sp, -16
78 ; CHECK-NEXT: .cfi_def_cfa_offset 16
79 ; CHECK-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
80 ; CHECK-NEXT: .cfi_offset ra, -8
81 ; CHECK-NEXT: call return_float
83 ; CHECK-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
84 ; CHECK-NEXT: addi sp, sp, 16
87 %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)
88 %call1 = call float @llvm.experimental.gc.result.f32(token %safepoint_token)
92 define %struct @test_struct_return() gc "statepoint-example" {
93 ; CHECK-LABEL: test_struct_return:
94 ; CHECK: # %bb.0: # %entry
95 ; CHECK-NEXT: addi sp, sp, -16
96 ; CHECK-NEXT: .cfi_def_cfa_offset 16
97 ; CHECK-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
98 ; CHECK-NEXT: .cfi_offset ra, -8
99 ; CHECK-NEXT: call return_struct
100 ; CHECK-NEXT: .Ltmp4:
101 ; CHECK-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
102 ; CHECK-NEXT: addi sp, sp, 16
105 %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)
106 %call1 = call %struct @llvm.experimental.gc.result.struct(token %safepoint_token)
110 define i1 @test_relocate(ptr addrspace(1) %a) gc "statepoint-example" {
111 ; CHECK-LABEL: test_relocate:
112 ; CHECK: # %bb.0: # %entry
113 ; CHECK-NEXT: addi sp, sp, -16
114 ; CHECK-NEXT: .cfi_def_cfa_offset 16
115 ; CHECK-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
116 ; CHECK-NEXT: .cfi_offset ra, -8
117 ; CHECK-NEXT: sd a0, 0(sp)
118 ; CHECK-NEXT: call return_i1
119 ; CHECK-NEXT: .Ltmp5:
120 ; CHECK-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
121 ; CHECK-NEXT: addi sp, sp, 16
123 ; Check that an ununsed relocate has no code-generation impact
125 %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)]
126 %call1 = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)
127 %call2 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
131 define void @test_void_vararg() gc "statepoint-example" {
132 ; CHECK-LABEL: test_void_vararg:
133 ; CHECK: # %bb.0: # %entry
134 ; CHECK-NEXT: addi sp, sp, -16
135 ; CHECK-NEXT: .cfi_def_cfa_offset 16
136 ; CHECK-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
137 ; CHECK-NEXT: .cfi_offset ra, -8
138 ; CHECK-NEXT: li a0, 42
139 ; CHECK-NEXT: li a1, 43
140 ; CHECK-NEXT: call varargf
141 ; CHECK-NEXT: .Ltmp6:
142 ; CHECK-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
143 ; CHECK-NEXT: addi sp, sp, 16
145 ; Check a statepoint wrapping a *ptr returning vararg function works
147 %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)
148 ;; if we try to use the result from a statepoint wrapping a
149 ;; non-void-returning varargf, we will experience a crash.
153 define i1 @test_i1_return_patchable() gc "statepoint-example" {
154 ; CHECK-LABEL: test_i1_return_patchable:
155 ; CHECK: # %bb.0: # %entry
156 ; CHECK-NEXT: addi sp, sp, -16
157 ; CHECK-NEXT: .cfi_def_cfa_offset 16
158 ; CHECK-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
159 ; CHECK-NEXT: .cfi_offset ra, -8
161 ; CHECK-NEXT: .Ltmp7:
162 ; CHECK-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
163 ; CHECK-NEXT: addi sp, sp, 16
165 ; A patchable variant of test_i1_return
167 %safepoint_token = tail call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 4, ptr elementtype(i1 ()) null, i32 0, i32 0, i32 0, i32 0)
168 %call1 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
172 declare void @consume(ptr addrspace(1) %obj)
174 define i1 @test_cross_bb(ptr addrspace(1) %a, i1 %external_cond) gc "statepoint-example" {
175 ; CHECK-LABEL: test_cross_bb:
176 ; CHECK: # %bb.0: # %entry
177 ; CHECK-NEXT: addi sp, sp, -32
178 ; CHECK-NEXT: .cfi_def_cfa_offset 32
179 ; CHECK-NEXT: sd ra, 24(sp) # 8-byte Folded Spill
180 ; CHECK-NEXT: sd s0, 16(sp) # 8-byte Folded Spill
181 ; CHECK-NEXT: .cfi_offset ra, -8
182 ; CHECK-NEXT: .cfi_offset s0, -16
183 ; CHECK-NEXT: andi s0, a1, 1
184 ; CHECK-NEXT: sd a0, 8(sp)
185 ; CHECK-NEXT: call return_i1
186 ; CHECK-NEXT: .Ltmp8:
187 ; CHECK-NEXT: beqz s0, .LBB8_2
188 ; CHECK-NEXT: # %bb.1: # %left
189 ; CHECK-NEXT: ld a1, 8(sp)
190 ; CHECK-NEXT: mv s0, a0
191 ; CHECK-NEXT: mv a0, a1
192 ; CHECK-NEXT: call consume
193 ; CHECK-NEXT: mv a0, s0
194 ; CHECK-NEXT: j .LBB8_3
195 ; CHECK-NEXT: .LBB8_2: # %right
196 ; CHECK-NEXT: li a0, 1
197 ; CHECK-NEXT: .LBB8_3: # %right
198 ; CHECK-NEXT: ld ra, 24(sp) # 8-byte Folded Reload
199 ; CHECK-NEXT: ld s0, 16(sp) # 8-byte Folded Reload
200 ; CHECK-NEXT: addi sp, sp, 32
203 %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)]
204 br i1 %external_cond, label %left, label %right
207 %call1 = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)
208 %call2 = call zeroext i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
209 call void @consume(ptr addrspace(1) %call1)
216 %struct2 = type { i64, i64, i64 }
218 declare void @consume_attributes(i32, ptr nest, i32, ptr byval(%struct2))
220 define void @test_attributes(ptr byval(%struct2) %s) gc "statepoint-example" {
221 ; CHECK-LABEL: test_attributes:
222 ; CHECK: # %bb.0: # %entry
223 ; CHECK-NEXT: addi sp, sp, -32
224 ; CHECK-NEXT: .cfi_def_cfa_offset 32
225 ; CHECK-NEXT: sd ra, 24(sp) # 8-byte Folded Spill
226 ; CHECK-NEXT: .cfi_offset ra, -8
227 ; CHECK-NEXT: ld a1, 16(a0)
228 ; CHECK-NEXT: sd a1, 16(sp)
229 ; CHECK-NEXT: ld a1, 8(a0)
230 ; CHECK-NEXT: sd a1, 8(sp)
231 ; CHECK-NEXT: ld a0, 0(a0)
232 ; CHECK-NEXT: sd a0, 0(sp)
233 ; CHECK-NEXT: li a0, 42
234 ; CHECK-NEXT: li a1, 17
235 ; CHECK-NEXT: mv a2, sp
236 ; CHECK-NEXT: li t2, 0
237 ; CHECK-NEXT: call consume_attributes
238 ; CHECK-NEXT: .Ltmp9:
239 ; CHECK-NEXT: ld ra, 24(sp) # 8-byte Folded Reload
240 ; CHECK-NEXT: addi sp, sp, 32
243 ; Check that arguments with attributes are lowered correctly.
244 ; We call a function that has a nest argument and a byval argument.
245 %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)
249 declare token @llvm.experimental.gc.statepoint.p0(i64, i32, ptr, i32, i32, ...)
250 declare i1 @llvm.experimental.gc.result.i1(token)
252 declare i32 @llvm.experimental.gc.result.i32(token)
254 declare ptr @llvm.experimental.gc.result.p0(token)
256 declare float @llvm.experimental.gc.result.f32(token)
258 declare %struct @llvm.experimental.gc.result.struct(token)
262 declare ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token, i32, i32)