1 ; RUN: opt < %s -passes=rewrite-statepoints-for-gc -spp-rematerialization-threshold=0 -S | FileCheck %s
6 declare void @use(...) "gc-leaf-function"
8 define ptr addrspace(1) @test1(ptr addrspace(1) %obj, ptr addrspace(1) %obj2, i1 %condition) gc "statepoint-example" {
10 ; CHECK-DAG: %obj.relocated
11 ; CHECK-DAG: %obj2.relocated
13 call void @foo() [ "deopt"() ]
16 joint: ; preds = %joint2, %entry
18 ; CHECK: %phi1 = phi ptr addrspace(1) [ %obj.relocated, %entry ], [ %obj3, %joint2 ]
19 %phi1 = phi ptr addrspace(1) [ %obj, %entry ], [ %obj3, %joint2 ]
20 br i1 %condition, label %use, label %joint2
25 joint2: ; preds = %use, %joint
26 ; CHECK-LABEL: joint2:
27 ; CHECK: %phi2 = phi ptr addrspace(1) [ %obj.relocated, %use ], [ %obj2.relocated, %joint ]
28 ; CHECK: %obj3 = getelementptr i64, ptr addrspace(1) %obj2.relocated, i32 1
29 %phi2 = phi ptr addrspace(1) [ %obj, %use ], [ %obj2, %joint ]
30 %obj3 = getelementptr i64, ptr addrspace(1) %obj2, i32 1
34 declare ptr addrspace(1) @generate_obj() "gc-leaf-function"
36 declare void @consume_obj(ptr addrspace(1)) "gc-leaf-function"
38 declare i1 @rt() "gc-leaf-function"
40 define void @test2() gc "statepoint-example" {
43 %obj_init = call ptr addrspace(1) @generate_obj()
44 %obj = getelementptr i64, ptr addrspace(1) %obj_init, i32 42
47 loop: ; preds = %loop.backedge, %entry
49 ; CHECK-DAG: [ %obj_init.relocated, %loop.backedge ]
50 ; CHECK-DAG: [ %obj_init, %entry ]
51 ; CHECK-DAG: [ %obj.relocated, %loop.backedge ]
52 ; CHECK-DAG: [ %obj, %entry ]
53 ; CHECK-NOT: %location = getelementptr i64, ptr addrspace(1) %obj, i32 %index
54 %index = phi i32 [ 0, %entry ], [ %index.inc, %loop.backedge ]
55 %location = getelementptr i64, ptr addrspace(1) %obj, i32 %index
56 call void @consume_obj(ptr addrspace(1) %location)
57 %index.inc = add i32 %index, 1
58 %condition = call i1 @rt()
59 br i1 %condition, label %loop_x, label %loop_y
61 loop_x: ; preds = %loop
62 br label %loop.backedge
64 loop.backedge: ; preds = %loop_y, %loop_x
65 call void @do_safepoint() [ "deopt"() ]
68 loop_y: ; preds = %loop
69 br label %loop.backedge
72 declare void @some_call(ptr addrspace(1)) "gc-leaf-function"
74 define void @relocate_merge(i1 %cnd, ptr addrspace(1) %arg) gc "statepoint-example" {
75 ; CHECK-LABEL: @relocate_merge
78 br i1 %cnd, label %if_branch, label %else_branch
80 if_branch: ; preds = %bci_0
81 ; CHECK-LABEL: if_branch:
82 ; CHECK: gc.statepoint
84 call void @foo() [ "deopt"() ]
87 else_branch: ; preds = %bci_0
88 ; CHECK-LABEL: else_branch:
89 ; CHECK: gc.statepoint
91 ; We need to end up with a single relocation phi updated from both paths
92 call void @foo() [ "deopt"() ]
95 join: ; preds = %else_branch, %if_branch
97 ; CHECK: phi ptr addrspace(1)
98 ; CHECK-DAG: [ %arg.relocated, %if_branch ]
99 ; CHECK-DAG: [ %arg.relocated2, %else_branch ]
101 call void @some_call(ptr addrspace(1) %arg)
105 declare void @goo(i64)
107 declare i32 @moo(ptr addrspace(1))
109 ; Make sure a use in a statepoint gets properly relocated at a previous one.
110 ; This is basically just making sure that statepoints aren't accidentally
112 define void @test3(ptr addrspace(1) %obj) gc "statepoint-example" {
113 ; CHECK-LABEL: @test3
114 ; CHECK: gc.statepoint
115 ; CHECK-NEXT: gc.relocate
116 ; CHECK-NEXT: gc.statepoint
118 call void @goo(i64 undef) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
119 %0 = call i32 @moo(ptr addrspace(1) %obj) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
123 declare ptr addrspace(1) @boo()
125 ; Check specifically for the case where the result of a statepoint needs to
126 ; be relocated itself
127 define void @test4() gc "statepoint-example" {
128 ; CHECK-LABEL: @test4
129 ; CHECK: gc.statepoint
131 ; CHECK: gc.statepoint
132 ; CHECK: [[RELOCATED:%[^ ]+]] = call {{.*}}gc.relocate
133 ; CHECK: @use(ptr addrspace(1) [[RELOCATED]])
134 %1 = call ptr addrspace(1) @boo() [ "deopt"() ]
135 %2 = call ptr addrspace(1) @boo() [ "deopt"() ]
136 call void (...) @use(ptr addrspace(1) %1)
140 ; Test updating a phi where not all inputs are live to begin with
141 define void @test5(ptr addrspace(1) %arg) gc "statepoint-example" {
144 %0 = call ptr addrspace(1) @boo() [ "deopt"() ]
145 switch i32 undef, label %kill [
150 kill: ; preds = %entry
153 merge: ; preds = %kill, %entry, %entry
155 ; CHECK: %test = phi ptr addrspace(1)
156 ; CHECK-DAG: [ null, %kill ]
157 ; CHECK-DAG: [ %arg.relocated, %entry ]
158 ; CHECK-DAG: [ %arg.relocated, %entry ]
159 %test = phi ptr addrspace(1) [ null, %kill ], [ %arg, %entry ], [ %arg, %entry ]
160 call void (...) @use(ptr addrspace(1) %test)
164 ; Check to make sure we handle values live over an entry statepoint
165 define void @test6(ptr addrspace(1) %arg1, ptr addrspace(1) %arg2, ptr addrspace(1) %arg3, i1 %c) gc "statepoint-example" {
166 ; CHECK-LABEL: @test6
168 br i1 %c, label %gc.safepoint_poll.exit2, label %do_safepoint
170 do_safepoint: ; preds = %entry
171 ; CHECK-LABEL: do_safepoint:
172 ; CHECK: gc.statepoint
173 ; CHECK: arg1.relocated =
174 ; CHECK: arg2.relocated =
175 ; CHECK: arg3.relocated =
176 call void @foo() [ "deopt"(ptr addrspace(1) %arg1, ptr addrspace(1) %arg2, ptr addrspace(1) %arg3) ]
177 br label %gc.safepoint_poll.exit2
179 gc.safepoint_poll.exit2: ; preds = %do_safepoint, %entry
180 ; CHECK-LABEL: gc.safepoint_poll.exit2:
181 ; CHECK: phi ptr addrspace(1)
182 ; CHECK-DAG: [ %arg3, %entry ]
183 ; CHECK-DAG: [ %arg3.relocated, %do_safepoint ]
184 ; CHECK: phi ptr addrspace(1)
185 ; CHECK-DAG: [ %arg2, %entry ]
186 ; CHECK-DAG: [ %arg2.relocated, %do_safepoint ]
187 ; CHECK: phi ptr addrspace(1)
188 ; CHECK-DAG: [ %arg1, %entry ]
189 ; CHECK-DAG: [ %arg1.relocated, %do_safepoint ]
190 call void (...) @use(ptr addrspace(1) %arg1, ptr addrspace(1) %arg2, ptr addrspace(1) %arg3)
194 ; Check relocation in a loop nest where a relocation happens in the outer
195 ; but not the inner loop
196 define void @test_outer_loop(ptr addrspace(1) %arg1, ptr addrspace(1) %arg2, i1 %cmp) gc "statepoint-example" {
197 ; CHECK-LABEL: @test_outer_loop
202 outer-loop: ; preds = %outer-inc, %bci_0
203 ; CHECK-LABEL: outer-loop:
204 ; CHECK: phi ptr addrspace(1) [ %arg2, %bci_0 ], [ %arg2.relocated, %outer-inc ]
205 ; CHECK: phi ptr addrspace(1) [ %arg1, %bci_0 ], [ %arg1.relocated, %outer-inc ]
208 inner-loop: ; preds = %inner-loop, %outer-loop
209 br i1 %cmp, label %inner-loop, label %outer-inc
211 outer-inc: ; preds = %inner-loop
212 ; CHECK-LABEL: outer-inc:
213 ; CHECK: %arg1.relocated
214 ; CHECK: %arg2.relocated
215 call void @foo() [ "deopt"(ptr addrspace(1) %arg1, ptr addrspace(1) %arg2) ]
219 ; Check that both inner and outer loops get phis when relocation is in
221 define void @test_inner_loop(ptr addrspace(1) %arg1, ptr addrspace(1) %arg2, i1 %cmp) gc "statepoint-example" {
222 ; CHECK-LABEL: @test_inner_loop
227 outer-loop: ; preds = %outer-inc, %bci_0
228 ; CHECK-LABEL: outer-loop:
229 ; CHECK: phi ptr addrspace(1) [ %arg2, %bci_0 ], [ %arg2.relocated, %outer-inc ]
230 ; CHECK: phi ptr addrspace(1) [ %arg1, %bci_0 ], [ %arg1.relocated, %outer-inc ]
232 ; CHECK-LABEL: inner-loop
233 ; CHECK: phi ptr addrspace(1)
234 ; CHECK-DAG: %outer-loop ]
235 ; CHECK-DAG: [ %arg2.relocated, %inner-loop ]
236 ; CHECK: phi ptr addrspace(1)
237 ; CHECK-DAG: %outer-loop ]
238 ; CHECK-DAG: [ %arg1.relocated, %inner-loop ]
239 ; CHECK: gc.statepoint
240 ; CHECK: %arg1.relocated
241 ; CHECK: %arg2.relocated
243 inner-loop: ; preds = %inner-loop, %outer-loop
244 call void @foo() [ "deopt"(ptr addrspace(1) %arg1, ptr addrspace(1) %arg2) ]
245 br i1 %cmp, label %inner-loop, label %outer-inc
247 outer-inc: ; preds = %inner-loop
248 ; 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.
254 define ptr addrspace(1) @test7(ptr addrspace(1) %obj, ptr addrspace(1) %obj2, i1 %condition) gc "statepoint-example" {
255 ; CHECK-LABEL: @test7
257 br i1 %condition, label %branch2, label %join
259 branch2: ; preds = %entry
260 br i1 %condition, label %callbb, label %join2
262 callbb: ; preds = %branch2
263 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
266 join: ; preds = %callbb, %entry
268 ; CHECK: phi ptr addrspace(1) [ %obj.relocated, %callbb ], [ %obj, %entry ]
269 ; CHECK: phi ptr addrspace(1)
270 ; CHECK-DAG: [ %obj, %entry ]
271 ; CHECK-DAG: [ %obj2.relocated, %callbb ]
272 %phi1 = phi ptr addrspace(1) [ %obj, %entry ], [ %obj2, %callbb ]
275 join2: ; preds = %join, %branch2
276 ; CHECK-LABEL: join2:
277 ; CHECK: phi2 = phi ptr addrspace(1)
279 ; CHECK-DAG: [ %obj2, %branch2 ]
280 %phi2 = phi ptr addrspace(1) [ %obj, %join ], [ %obj2, %branch2 ]
281 ret ptr addrspace(1) %phi2
284 declare void @do_safepoint()