1 ; RUN: opt %s -rewrite-statepoints-for-gc -S 2>&1 | FileCheck %s
7 define i64 addrspace(1)* @test1(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2, i1 %condition) gc "statepoint-example" {
10 ; CHECK-DAG: %obj.relocated
11 ; CHECK-DAG: %obj2.relocated
12 %safepoint_token = call i32 (void ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()* @foo, i32 0, i32 0, i32 0)
17 ; CHECK: %phi1 = phi i64 addrspace(1)* [ %obj.relocated, %entry ], [ %obj3, %joint2 ]
18 %phi1 = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj3, %joint2 ]
19 br i1 %condition, label %use, label %joint2
25 ; CHECK-LABEL: joint2:
26 ; CHECK: %phi2 = phi i64 addrspace(1)* [ %obj.relocated, %use ], [ %obj2.relocated, %joint ]
27 ; CHECK: %obj3 = getelementptr i64, i64 addrspace(1)* %obj2.relocated, i32 1
28 %phi2 = phi i64 addrspace(1)* [ %obj, %use ], [ %obj2, %joint ]
29 %obj3 = getelementptr i64, i64 addrspace(1)* %obj2, i32 1
33 declare i64 addrspace(1)* @generate_obj()
35 declare void @consume_obj(i64 addrspace(1)*)
39 define void @test2() gc "statepoint-example" {
42 %obj_init = call i64 addrspace(1)* @generate_obj()
43 %obj = getelementptr i64, i64 addrspace(1)* %obj_init, i32 42
48 ; CHECK-DAG: [ %obj_init.relocated, %loop.backedge ]
49 ; CHECK-DAG: [ %obj_init, %entry ]
50 ; CHECK-DAG: [ %obj.relocated, %loop.backedge ]
51 ; CHECK-DAG: [ %obj, %entry ]
52 %index = phi i32 [ 0, %entry ], [ %index.inc, %loop.backedge ]
53 ; CHECK-NOT: %location = getelementptr i64, i64 addrspace(1)* %obj, i32 %index
54 %location = getelementptr i64, i64 addrspace(1)* %obj, i32 %index
55 call void @consume_obj(i64 addrspace(1)* %location)
56 %index.inc = add i32 %index, 1
57 %condition = call i1 @rt()
58 br i1 %condition, label %loop_x, label %loop_y
61 br label %loop.backedge
64 %safepoint_token = call i32 (void ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()* @do_safepoint, i32 0, i32 0, i32 0)
68 br label %loop.backedge
71 declare void @some_call(i8 addrspace(1)*)
73 define void @relocate_merge(i1 %cnd, i8 addrspace(1)* %arg) gc "statepoint-example" {
74 ; CHECK-LABEL: @relocate_merge
76 br i1 %cnd, label %if_branch, label %else_branch
79 ; CHECK-LABEL: if_branch:
80 ; CHECK: gc.statepoint
82 %safepoint_token = call i32 (void ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()* @foo, i32 0, i32 0, i32 0)
86 ; CHECK-LABEL: else_branch:
87 ; CHECK: gc.statepoint
89 %safepoint_token1 = call i32 (void ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()* @foo, i32 0, i32 0, i32 0)
93 ; We need to end up with a single relocation phi updated from both paths
95 ; CHECK: phi i8 addrspace(1)*
96 ; CHECK-DAG: [ %arg.relocated, %if_branch ]
97 ; CHECK-DAG: [ %arg.relocated4, %else_branch ]
99 call void (i8 addrspace(1)*)* @some_call(i8 addrspace(1)* %arg)
103 ; Make sure a use in a statepoint gets properly relocated at a previous one.
104 ; This is basically just making sure that statepoints aren't accidentally
106 define void @test3(i64 addrspace(1)* %obj) gc "statepoint-example" {
108 ; CHECK-LABEL: @test3
109 ; CHECK: gc.statepoint
110 ; CHECK-NEXT: gc.relocate
111 ; CHECK-NEXT: gc.statepoint
112 %safepoint_token = call i32 (void (i64)*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_isVoidi64f(void (i64)* undef, i32 1, i32 0, i64 undef, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
113 %safepoint_token1 = call i32 (i32 (i64 addrspace(1)*)*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_i32p1i64f(i32 (i64 addrspace(1)*)* undef, i32 1, i32 0, i64 addrspace(1)* %obj, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
117 ; Check specifically for the case where the result of a statepoint needs to
118 ; be relocated itself
119 define void @test4() gc "statepoint-example" {
120 ; CHECK-LABEL: @test4
121 ; CHECK: gc.statepoint
123 ; CHECK: gc.statepoint
125 ; CHECK: @use(i8 addrspace(1)* %res.relocated)
126 %safepoint_token2 = tail call i32 (i8 addrspace(1)* ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_p1i8f(i8 addrspace(1)* ()* undef, i32 0, i32 0, i32 0)
127 %res = call i8 addrspace(1)* @llvm.experimental.gc.result.ptr.p1i8(i32 %safepoint_token2)
128 call i32 (i8 addrspace(1)* ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_p1i8f(i8 addrspace(1)* ()* undef, i32 0, i32 0, i32 0)
129 call void (...)* @use(i8 addrspace(1)* %res)
134 ; Test updating a phi where not all inputs are live to begin with
135 define void @test5(i8 addrspace(1)* %arg) gc "statepoint-example" {
138 call i32 (i8 addrspace(1)* ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_p1i8f(i8 addrspace(1)* ()* undef, i32 0, i32 0, i32 0)
139 switch i32 undef, label %kill [
149 ; CHECK: %test = phi i8 addrspace(1)
150 ; CHECK-DAG: [ null, %kill ]
151 ; CHECK-DAG: [ %arg.relocated, %entry ]
152 ; CHECK-DAG: [ %arg.relocated, %entry ]
153 %test = phi i8 addrspace(1)* [ null, %kill ], [ %arg, %entry ], [ %arg, %entry ]
154 call void (...)* @use(i8 addrspace(1)* %test)
159 ; Check to make sure we handle values live over an entry statepoint
160 define void @test6(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2,
161 i8 addrspace(1)* %arg3) gc "statepoint-example" {
162 ; CHECK-LABEL: @test6
164 br i1 undef, label %gc.safepoint_poll.exit2, label %do_safepoint
167 ; CHECK-LABEL: do_safepoint:
168 ; CHECK: gc.statepoint
169 ; CHECK: arg1.relocated =
170 ; CHECK: arg2.relocated =
171 ; CHECK: arg3.relocated =
172 call i32 (void ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()* @foo, i32 0, i32 0, i32 3, i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2, i8 addrspace(1)* %arg3)
173 br label %gc.safepoint_poll.exit2
175 gc.safepoint_poll.exit2:
176 ; CHECK-LABEL: gc.safepoint_poll.exit2:
177 ; CHECK: phi i8 addrspace(1)*
178 ; CHECK-DAG: [ %arg3, %entry ]
179 ; CHECK-DAG: [ %arg3.relocated, %do_safepoint ]
180 ; CHECK: phi i8 addrspace(1)*
181 ; CHECK-DAG: [ %arg2, %entry ]
182 ; CHECK-DAG: [ %arg2.relocated, %do_safepoint ]
183 ; CHECK: phi i8 addrspace(1)*
184 ; CHECK-DAG: [ %arg1, %entry ]
185 ; CHECK-DAG: [ %arg1.relocated, %do_safepoint ]
186 call void (...)* @use(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2, i8 addrspace(1)* %arg3)
190 ; Check relocation in a loop nest where a relocation happens in the outer
191 ; but not the inner loop
192 define void @test_outer_loop(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2,
193 i1 %cmp) gc "statepoint-example" {
194 ; CHECK-LABEL: @test_outer_loop
199 ; CHECK-LABEL: outer-loop:
200 ; CHECK: phi i8 addrspace(1)* [ %arg2, %bci_0 ], [ %arg2.relocated, %outer-inc ]
201 ; CHECK: phi i8 addrspace(1)* [ %arg1, %bci_0 ], [ %arg1.relocated, %outer-inc ]
205 br i1 %cmp, label %inner-loop, label %outer-inc
208 ; CHECK-LABEL: outer-inc:
209 ; CHECK: %arg1.relocated
210 ; CHECK: %arg2.relocated
211 %safepoint_token = call i32 (void ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()* @foo, i32 0, i32 0, i32 2, i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2)
215 ; Check that both inner and outer loops get phis when relocation is in
217 define void @test_inner_loop(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2,
218 i1 %cmp) gc "statepoint-example" {
219 ; CHECK-LABEL: @test_inner_loop
224 ; CHECK-LABEL: outer-loop:
225 ; CHECK: phi i8 addrspace(1)* [ %arg2, %bci_0 ], [ %arg2.relocated, %outer-inc ]
226 ; CHECK: phi i8 addrspace(1)* [ %arg1, %bci_0 ], [ %arg1.relocated, %outer-inc ]
230 ; CHECK-LABEL: inner-loop
231 ; CHECK: phi i8 addrspace(1)*
232 ; CHECK-DAG: %outer-loop ]
233 ; CHECK-DAG: [ %arg2.relocated, %inner-loop ]
234 ; CHECKL phi i8 addrspace(1)*
235 ; CHECK-DAG: %outer-loop ]
236 ; CHECK-DAG: [ %arg1.relocated, %inner-loop ]
237 ; CHECK: gc.statepoint
238 ; CHECK: %arg1.relocated
239 ; CHECK: %arg2.relocated
240 %safepoint_token = call i32 (void ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()* @foo, i32 0, i32 0, i32 2, i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2)
241 br i1 %cmp, label %inner-loop, label %outer-inc
244 ; CHECK-LABEL: outer-inc:
249 ; This test shows why updating just those uses of the original value being
250 ; relocated dominated by the inserted relocation is not always sufficient.
251 define i64 addrspace(1)* @test7(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2, i1 %condition) gc "statepoint-example" {
252 ; CHECK-LABEL: @test7
254 br i1 %condition, label %branch2, label %join
257 br i1 %condition, label %callbb, label %join2
260 %safepoint_token = call i32 (void ()*, i32, i32, ...)* @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()* @foo, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
265 ; CHECK: phi i64 addrspace(1)* [ %obj.relocated, %callbb ], [ %obj, %entry ]
266 ; CHECK: phi i64 addrspace(1)*
267 ; CHECK-DAG: [ %obj, %entry ]
268 ; CHECK-DAG: [ %obj2.relocated, %callbb ]
269 ; This is a phi outside the dominator region of the new defs inserted by
270 ; the safepoint, BUT we can't stop the search here or we miss the second
272 %phi1 = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj2, %callbb ]
276 ; CHECK-LABEL: join2:
277 ; CHECK: phi2 = phi i64 addrspace(1)*
279 ; CHECK-DAG: [ %obj2, %branch2 ]
280 %phi2 = phi i64 addrspace(1)* [ %obj, %join ], [ %obj2, %branch2 ]
281 ret i64 addrspace(1)* %phi2
285 declare void @do_safepoint()
287 declare i32 @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()*, i32, i32, ...)
288 declare i32 @llvm.experimental.gc.statepoint.p0f_p1i8f(i8 addrspace(1)* ()*, i32, i32, ...)
289 declare i32 @llvm.experimental.gc.statepoint.p0f_isVoidi64f(void (i64)*, i32, i32, ...)
290 declare i32 @llvm.experimental.gc.statepoint.p0f_i32p1i64f(i32 (i64 addrspace(1)*)*, i32, i32, ...)
291 declare i8 addrspace(1)* @llvm.experimental.gc.result.ptr.p1i8(i32) #3