1 ; RUN: opt < %s -rewrite-statepoints-for-gc -spp-rematerialization-threshold=0 -S | FileCheck %s
2 ; RUN: opt < %s -passes=rewrite-statepoints-for-gc -spp-rematerialization-threshold=0 -S | FileCheck %s
7 declare void @use(...) "gc-leaf-function"
9 define i64 addrspace(1)* @test1(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2, i1 %condition) gc "statepoint-example" {
11 ; CHECK-DAG: %obj.relocated
12 ; CHECK-DAG: %obj2.relocated
14 call void @foo() [ "deopt"() ]
17 joint: ; preds = %joint2, %entry
19 ; CHECK: %phi1 = phi i64 addrspace(1)* [ %obj.relocated.casted, %entry ], [ %obj3, %joint2 ]
20 %phi1 = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj3, %joint2 ]
21 br i1 %condition, label %use, label %joint2
26 joint2: ; preds = %use, %joint
27 ; CHECK-LABEL: joint2:
28 ; CHECK: %phi2 = phi i64 addrspace(1)* [ %obj.relocated.casted, %use ], [ %obj2.relocated.casted, %joint ]
29 ; CHECK: %obj3 = getelementptr i64, i64 addrspace(1)* %obj2.relocated.casted, i32 1
30 %phi2 = phi i64 addrspace(1)* [ %obj, %use ], [ %obj2, %joint ]
31 %obj3 = getelementptr i64, i64 addrspace(1)* %obj2, i32 1
35 declare i64 addrspace(1)* @generate_obj() "gc-leaf-function"
37 declare void @consume_obj(i64 addrspace(1)*) "gc-leaf-function"
39 declare i1 @rt() "gc-leaf-function"
41 define void @test2() gc "statepoint-example" {
44 %obj_init = call i64 addrspace(1)* @generate_obj()
45 %obj = getelementptr i64, i64 addrspace(1)* %obj_init, i32 42
48 loop: ; preds = %loop.backedge, %entry
50 ; CHECK-DAG: [ %obj_init.relocated.casted, %loop.backedge ]
51 ; CHECK-DAG: [ %obj_init, %entry ]
52 ; CHECK-DAG: [ %obj.relocated.casted, %loop.backedge ]
53 ; CHECK-DAG: [ %obj, %entry ]
54 ; CHECK-NOT: %location = getelementptr i64, i64 addrspace(1)* %obj, i32 %index
55 %index = phi i32 [ 0, %entry ], [ %index.inc, %loop.backedge ]
56 %location = getelementptr i64, i64 addrspace(1)* %obj, i32 %index
57 call void @consume_obj(i64 addrspace(1)* %location)
58 %index.inc = add i32 %index, 1
59 %condition = call i1 @rt()
60 br i1 %condition, label %loop_x, label %loop_y
62 loop_x: ; preds = %loop
63 br label %loop.backedge
65 loop.backedge: ; preds = %loop_y, %loop_x
66 call void @do_safepoint() [ "deopt"() ]
69 loop_y: ; preds = %loop
70 br label %loop.backedge
73 declare void @some_call(i8 addrspace(1)*) "gc-leaf-function"
75 define void @relocate_merge(i1 %cnd, i8 addrspace(1)* %arg) gc "statepoint-example" {
76 ; CHECK-LABEL: @relocate_merge
79 br i1 %cnd, label %if_branch, label %else_branch
81 if_branch: ; preds = %bci_0
82 ; CHECK-LABEL: if_branch:
83 ; CHECK: gc.statepoint
85 call void @foo() [ "deopt"() ]
88 else_branch: ; preds = %bci_0
89 ; CHECK-LABEL: else_branch:
90 ; CHECK: gc.statepoint
92 ; We need to end up with a single relocation phi updated from both paths
93 call void @foo() [ "deopt"() ]
96 join: ; preds = %else_branch, %if_branch
98 ; CHECK: phi i8 addrspace(1)*
99 ; CHECK-DAG: [ %arg.relocated, %if_branch ]
100 ; CHECK-DAG: [ %arg.relocated2, %else_branch ]
102 call void @some_call(i8 addrspace(1)* %arg)
106 declare void @goo(i64)
108 declare i32 @moo(i64 addrspace(1)*)
110 ; Make sure a use in a statepoint gets properly relocated at a previous one.
111 ; This is basically just making sure that statepoints aren't accidentally
113 define void @test3(i64 addrspace(1)* %obj) gc "statepoint-example" {
114 ; CHECK-LABEL: @test3
115 ; CHECK: gc.statepoint
116 ; CHECK-NEXT: gc.relocate
117 ; CHECK-NEXT: bitcast
118 ; CHECK-NEXT: gc.statepoint
120 call void @goo(i64 undef) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
121 %0 = call i32 @moo(i64 addrspace(1)* %obj) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
125 declare i8 addrspace(1)* @boo()
127 ; Check specifically for the case where the result of a statepoint needs to
128 ; be relocated itself
129 define void @test4() gc "statepoint-example" {
130 ; CHECK-LABEL: @test4
131 ; CHECK: gc.statepoint
133 ; CHECK: gc.statepoint
134 ; CHECK: [[RELOCATED:%[^ ]+]] = call {{.*}}gc.relocate
135 ; CHECK: @use(i8 addrspace(1)* [[RELOCATED]])
136 %1 = call i8 addrspace(1)* @boo() [ "deopt"() ]
137 %2 = call i8 addrspace(1)* @boo() [ "deopt"() ]
138 call void (...) @use(i8 addrspace(1)* %1)
142 ; Test updating a phi where not all inputs are live to begin with
143 define void @test5(i8 addrspace(1)* %arg) gc "statepoint-example" {
146 %0 = call i8 addrspace(1)* @boo() [ "deopt"() ]
147 switch i32 undef, label %kill [
152 kill: ; preds = %entry
155 merge: ; preds = %kill, %entry, %entry
157 ; CHECK: %test = phi i8 addrspace(1)
158 ; CHECK-DAG: [ null, %kill ]
159 ; CHECK-DAG: [ %arg.relocated, %entry ]
160 ; CHECK-DAG: [ %arg.relocated, %entry ]
161 %test = phi i8 addrspace(1)* [ null, %kill ], [ %arg, %entry ], [ %arg, %entry ]
162 call void (...) @use(i8 addrspace(1)* %test)
166 ; Check to make sure we handle values live over an entry statepoint
167 define void @test6(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2, i8 addrspace(1)* %arg3) gc "statepoint-example" {
168 ; CHECK-LABEL: @test6
170 br i1 undef, label %gc.safepoint_poll.exit2, label %do_safepoint
172 do_safepoint: ; preds = %entry
173 ; CHECK-LABEL: do_safepoint:
174 ; CHECK: gc.statepoint
175 ; CHECK: arg1.relocated =
176 ; CHECK: arg2.relocated =
177 ; CHECK: arg3.relocated =
178 call void @foo() [ "deopt"(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2, i8 addrspace(1)* %arg3) ]
179 br label %gc.safepoint_poll.exit2
181 gc.safepoint_poll.exit2: ; preds = %do_safepoint, %entry
182 ; CHECK-LABEL: gc.safepoint_poll.exit2:
183 ; CHECK: phi i8 addrspace(1)*
184 ; CHECK-DAG: [ %arg3, %entry ]
185 ; CHECK-DAG: [ %arg3.relocated, %do_safepoint ]
186 ; CHECK: phi i8 addrspace(1)*
187 ; CHECK-DAG: [ %arg2, %entry ]
188 ; CHECK-DAG: [ %arg2.relocated, %do_safepoint ]
189 ; CHECK: phi i8 addrspace(1)*
190 ; CHECK-DAG: [ %arg1, %entry ]
191 ; CHECK-DAG: [ %arg1.relocated, %do_safepoint ]
192 call void (...) @use(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2, i8 addrspace(1)* %arg3)
196 ; Check relocation in a loop nest where a relocation happens in the outer
197 ; but not the inner loop
198 define void @test_outer_loop(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2, i1 %cmp) gc "statepoint-example" {
199 ; CHECK-LABEL: @test_outer_loop
204 outer-loop: ; preds = %outer-inc, %bci_0
205 ; CHECK-LABEL: outer-loop:
206 ; CHECK: phi i8 addrspace(1)* [ %arg2, %bci_0 ], [ %arg2.relocated, %outer-inc ]
207 ; CHECK: phi i8 addrspace(1)* [ %arg1, %bci_0 ], [ %arg1.relocated, %outer-inc ]
210 inner-loop: ; preds = %inner-loop, %outer-loop
211 br i1 %cmp, label %inner-loop, label %outer-inc
213 outer-inc: ; preds = %inner-loop
214 ; CHECK-LABEL: outer-inc:
215 ; CHECK: %arg1.relocated
216 ; CHECK: %arg2.relocated
217 call void @foo() [ "deopt"(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2) ]
221 ; Check that both inner and outer loops get phis when relocation is in
223 define void @test_inner_loop(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2, i1 %cmp) gc "statepoint-example" {
224 ; CHECK-LABEL: @test_inner_loop
229 outer-loop: ; preds = %outer-inc, %bci_0
230 ; CHECK-LABEL: outer-loop:
231 ; CHECK: phi i8 addrspace(1)* [ %arg2, %bci_0 ], [ %arg2.relocated, %outer-inc ]
232 ; CHECK: phi i8 addrspace(1)* [ %arg1, %bci_0 ], [ %arg1.relocated, %outer-inc ]
234 ; CHECK-LABEL: inner-loop
235 ; CHECK: phi i8 addrspace(1)*
236 ; CHECK-DAG: %outer-loop ]
237 ; CHECK-DAG: [ %arg2.relocated, %inner-loop ]
238 ; CHECK: phi i8 addrspace(1)*
239 ; CHECK-DAG: %outer-loop ]
240 ; CHECK-DAG: [ %arg1.relocated, %inner-loop ]
241 ; CHECK: gc.statepoint
242 ; CHECK: %arg1.relocated
243 ; CHECK: %arg2.relocated
245 inner-loop: ; preds = %inner-loop, %outer-loop
246 call void @foo() [ "deopt"(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2) ]
247 br i1 %cmp, label %inner-loop, label %outer-inc
249 outer-inc: ; preds = %inner-loop
250 ; CHECK-LABEL: outer-inc:
251 ; This test shows why updating just those uses of the original value being
252 ; relocated dominated by the inserted relocation is not always sufficient.
256 define i64 addrspace(1)* @test7(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2, i1 %condition) gc "statepoint-example" {
257 ; CHECK-LABEL: @test7
259 br i1 %condition, label %branch2, label %join
261 branch2: ; preds = %entry
262 br i1 %condition, label %callbb, label %join2
264 callbb: ; preds = %branch2
265 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
268 join: ; preds = %callbb, %entry
270 ; CHECK: phi i64 addrspace(1)* [ %obj.relocated.casted, %callbb ], [ %obj, %entry ]
271 ; CHECK: phi i64 addrspace(1)*
272 ; CHECK-DAG: [ %obj, %entry ]
273 ; CHECK-DAG: [ %obj2.relocated.casted, %callbb ]
274 %phi1 = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj2, %callbb ]
277 join2: ; preds = %join, %branch2
278 ; CHECK-LABEL: join2:
279 ; CHECK: phi2 = phi i64 addrspace(1)*
281 ; CHECK-DAG: [ %obj2, %branch2 ]
282 %phi2 = phi i64 addrspace(1)* [ %obj, %join ], [ %obj2, %branch2 ]
283 ret i64 addrspace(1)* %phi2
286 declare void @do_safepoint()