• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -rewrite-statepoints-for-gc -spp-rematerialization-threshold=0 -S | FileCheck %s
2
3
4declare void @foo()
5
6declare void @use(...) "gc-leaf-function"
7
8define i64 addrspace(1)* @test1(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2, i1 %condition) gc "statepoint-example" {
9; CHECK-LABEL: @test1
10; CHECK-DAG: %obj.relocated
11; CHECK-DAG: %obj2.relocated
12entry:
13  call void @foo() [ "deopt"() ]
14  br label %joint
15
16joint:                                            ; preds = %joint2, %entry
17; CHECK-LABEL: joint:
18; CHECK: %phi1 = phi i64 addrspace(1)* [ %obj.relocated.casted, %entry ], [ %obj3, %joint2 ]
19  %phi1 = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj3, %joint2 ]
20  br i1 %condition, label %use, label %joint2
21
22use:                                              ; preds = %joint
23  br label %joint2
24
25joint2:                                           ; preds = %use, %joint
26; CHECK-LABEL: joint2:
27; CHECK: %phi2 = phi i64 addrspace(1)* [ %obj.relocated.casted, %use ], [ %obj2.relocated.casted, %joint ]
28; CHECK: %obj3 = getelementptr i64, i64 addrspace(1)* %obj2.relocated.casted, i32 1
29  %phi2 = phi i64 addrspace(1)* [ %obj, %use ], [ %obj2, %joint ]
30  %obj3 = getelementptr i64, i64 addrspace(1)* %obj2, i32 1
31  br label %joint
32}
33
34declare i64 addrspace(1)* @generate_obj() "gc-leaf-function"
35
36declare void @consume_obj(i64 addrspace(1)*) "gc-leaf-function"
37
38declare i1 @rt() "gc-leaf-function"
39
40define void @test2() gc "statepoint-example" {
41; CHECK-LABEL: @test2
42entry:
43  %obj_init = call i64 addrspace(1)* @generate_obj()
44  %obj = getelementptr i64, i64 addrspace(1)* %obj_init, i32 42
45  br label %loop
46
47loop:                                             ; preds = %loop.backedge, %entry
48; CHECK: loop:
49; CHECK-DAG: [ %obj_init.relocated.casted, %loop.backedge ]
50; CHECK-DAG: [ %obj_init, %entry ]
51; CHECK-DAG: [ %obj.relocated.casted, %loop.backedge ]
52; CHECK-DAG: [ %obj, %entry ]
53; CHECK-NOT: %location = getelementptr i64, i64 addrspace(1)* %obj, i32 %index
54  %index = phi i32 [ 0, %entry ], [ %index.inc, %loop.backedge ]
55  %location = getelementptr i64, i64 addrspace(1)* %obj, i32 %index
56  call void @consume_obj(i64 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
60
61loop_x:                                           ; preds = %loop
62  br label %loop.backedge
63
64loop.backedge:                                    ; preds = %loop_y, %loop_x
65  call void @do_safepoint() [ "deopt"() ]
66  br label %loop
67
68loop_y:                                           ; preds = %loop
69  br label %loop.backedge
70}
71
72declare void @some_call(i8 addrspace(1)*) "gc-leaf-function"
73
74define void @relocate_merge(i1 %cnd, i8 addrspace(1)* %arg) gc "statepoint-example" {
75; CHECK-LABEL: @relocate_merge
76
77bci_0:
78  br i1 %cnd, label %if_branch, label %else_branch
79
80if_branch:                                        ; preds = %bci_0
81; CHECK-LABEL: if_branch:
82; CHECK: gc.statepoint
83; CHECK: gc.relocate
84  call void @foo() [ "deopt"() ]
85  br label %join
86
87else_branch:                                      ; preds = %bci_0
88; CHECK-LABEL: else_branch:
89; CHECK: gc.statepoint
90; CHECK: gc.relocate
91; We need to end up with a single relocation phi updated from both paths
92  call void @foo() [ "deopt"() ]
93  br label %join
94
95join:                                             ; preds = %else_branch, %if_branch
96; CHECK-LABEL: join:
97; CHECK: phi i8 addrspace(1)*
98; CHECK-DAG: [ %arg.relocated, %if_branch ]
99; CHECK-DAG: [ %arg.relocated2, %else_branch ]
100; CHECK-NOT: phi
101  call void @some_call(i8 addrspace(1)* %arg)
102  ret void
103}
104
105; Make sure a use in a statepoint gets properly relocated at a previous one.
106; This is basically just making sure that statepoints aren't accidentally
107; treated specially.
108define void @test3(i64 addrspace(1)* %obj) gc "statepoint-example" {
109; CHECK-LABEL: @test3
110; CHECK: gc.statepoint
111; CHECK-NEXT: gc.relocate
112; CHECK-NEXT: bitcast
113; CHECK-NEXT: gc.statepoint
114entry:
115  call void undef(i64 undef) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
116  %0 = call i32 undef(i64 addrspace(1)* %obj) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
117  ret void
118}
119
120; Check specifically for the case where the result of a statepoint needs to
121; be relocated itself
122define void @test4() gc "statepoint-example" {
123; CHECK-LABEL: @test4
124; CHECK: gc.statepoint
125; CHECK: gc.result
126; CHECK: gc.statepoint
127; CHECK: [[RELOCATED:%[^ ]+]] = call {{.*}}gc.relocate
128; CHECK: @use(i8 addrspace(1)* [[RELOCATED]])
129  %1 = call i8 addrspace(1)* undef() [ "deopt"() ]
130  %2 = call i8 addrspace(1)* undef() [ "deopt"() ]
131  call void (...) @use(i8 addrspace(1)* %1)
132  unreachable
133}
134
135; Test updating a phi where not all inputs are live to begin with
136define void @test5(i8 addrspace(1)* %arg) gc "statepoint-example" {
137; CHECK-LABEL: test5
138entry:
139  %0 = call i8 addrspace(1)* undef() [ "deopt"() ]
140  switch i32 undef, label %kill [
141    i32 10, label %merge
142    i32 13, label %merge
143  ]
144
145kill:                                             ; preds = %entry
146  br label %merge
147
148merge:                                            ; preds = %kill, %entry, %entry
149; CHECK: merge:
150; CHECK: %test = phi i8 addrspace(1)
151; CHECK-DAG: [ null, %kill ]
152; CHECK-DAG: [ %arg.relocated, %entry ]
153; CHECK-DAG: [ %arg.relocated, %entry ]
154  %test = phi i8 addrspace(1)* [ null, %kill ], [ %arg, %entry ], [ %arg, %entry ]
155  call void (...) @use(i8 addrspace(1)* %test)
156  unreachable
157}
158
159; Check to make sure we handle values live over an entry statepoint
160define void @test6(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2, i8 addrspace(1)* %arg3) gc "statepoint-example" {
161; CHECK-LABEL: @test6
162entry:
163  br i1 undef, label %gc.safepoint_poll.exit2, label %do_safepoint
164
165do_safepoint:                                     ; preds = %entry
166; CHECK-LABEL: do_safepoint:
167; CHECK: gc.statepoint
168; CHECK: arg1.relocated =
169; CHECK: arg2.relocated =
170; CHECK: arg3.relocated =
171  call void @foo() [ "deopt"(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2, i8 addrspace(1)* %arg3) ]
172  br label %gc.safepoint_poll.exit2
173
174gc.safepoint_poll.exit2:                          ; preds = %do_safepoint, %entry
175; CHECK-LABEL: gc.safepoint_poll.exit2:
176; CHECK: phi i8 addrspace(1)*
177; CHECK-DAG: [ %arg3, %entry ]
178; CHECK-DAG: [ %arg3.relocated, %do_safepoint ]
179; CHECK: phi i8 addrspace(1)*
180; CHECK-DAG: [ %arg2, %entry ]
181; CHECK-DAG: [ %arg2.relocated, %do_safepoint ]
182; CHECK: phi i8 addrspace(1)*
183; CHECK-DAG: [ %arg1, %entry ]
184; CHECK-DAG:  [ %arg1.relocated, %do_safepoint ]
185  call void (...) @use(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2, i8 addrspace(1)* %arg3)
186  ret void
187}
188
189; Check relocation in a loop nest where a relocation happens in the outer
190; but not the inner loop
191define void @test_outer_loop(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2, i1 %cmp) gc "statepoint-example" {
192; CHECK-LABEL: @test_outer_loop
193
194bci_0:
195  br label %outer-loop
196
197outer-loop:                                       ; preds = %outer-inc, %bci_0
198; CHECK-LABEL: outer-loop:
199; CHECK: phi i8 addrspace(1)* [ %arg2, %bci_0 ], [ %arg2.relocated, %outer-inc ]
200; CHECK: phi i8 addrspace(1)* [ %arg1, %bci_0 ], [ %arg1.relocated, %outer-inc ]
201  br label %inner-loop
202
203inner-loop:                                       ; preds = %inner-loop, %outer-loop
204  br i1 %cmp, label %inner-loop, label %outer-inc
205
206outer-inc:                                        ; preds = %inner-loop
207; CHECK-LABEL: outer-inc:
208; CHECK: %arg1.relocated
209; CHECK: %arg2.relocated
210  call void @foo() [ "deopt"(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2) ]
211  br label %outer-loop
212}
213
214; Check that both inner and outer loops get phis when relocation is in
215;  inner loop
216define void @test_inner_loop(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2, i1 %cmp) gc "statepoint-example" {
217; CHECK-LABEL: @test_inner_loop
218
219bci_0:
220  br label %outer-loop
221
222outer-loop:                                       ; preds = %outer-inc, %bci_0
223; CHECK-LABEL: outer-loop:
224; CHECK: phi i8 addrspace(1)* [ %arg2, %bci_0 ], [ %arg2.relocated, %outer-inc ]
225; CHECK: phi i8 addrspace(1)* [ %arg1, %bci_0 ], [ %arg1.relocated, %outer-inc ]
226  br label %inner-loop
227; CHECK-LABEL: inner-loop
228; CHECK: phi i8 addrspace(1)*
229; CHECK-DAG: %outer-loop ]
230; CHECK-DAG: [ %arg2.relocated, %inner-loop ]
231; CHECK: phi i8 addrspace(1)*
232; CHECK-DAG: %outer-loop ]
233; CHECK-DAG: [ %arg1.relocated, %inner-loop ]
234; CHECK: gc.statepoint
235; CHECK: %arg1.relocated
236; CHECK: %arg2.relocated
237
238inner-loop:                                       ; preds = %inner-loop, %outer-loop
239  call void @foo() [ "deopt"(i8 addrspace(1)* %arg1, i8 addrspace(1)* %arg2) ]
240  br i1 %cmp, label %inner-loop, label %outer-inc
241
242outer-inc:                                        ; preds = %inner-loop
243; CHECK-LABEL: outer-inc:
244; This test shows why updating just those uses of the original value being
245; relocated dominated by the inserted relocation is not always sufficient.
246  br label %outer-loop
247}
248
249define i64 addrspace(1)* @test7(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2, i1 %condition) gc "statepoint-example" {
250; CHECK-LABEL: @test7
251entry:
252  br i1 %condition, label %branch2, label %join
253
254branch2:                                          ; preds = %entry
255  br i1 %condition, label %callbb, label %join2
256
257callbb:                                           ; preds = %branch2
258  call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
259  br label %join
260
261join:                                             ; preds = %callbb, %entry
262; CHECK-LABEL: join:
263; CHECK: phi i64 addrspace(1)* [ %obj.relocated.casted, %callbb ], [ %obj, %entry ]
264; CHECK: phi i64 addrspace(1)*
265; CHECK-DAG: [ %obj, %entry ]
266; CHECK-DAG: [ %obj2.relocated.casted, %callbb ]
267  %phi1 = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj2, %callbb ]
268  br label %join2
269
270join2:                                            ; preds = %join, %branch2
271; CHECK-LABEL: join2:
272; CHECK: phi2 = phi i64 addrspace(1)*
273; CHECK-DAG: %join ]
274; CHECK-DAG:  [ %obj2, %branch2 ]
275  %phi2 = phi i64 addrspace(1)* [ %obj, %join ], [ %obj2, %branch2 ]
276  ret i64 addrspace(1)* %phi2
277}
278
279declare void @do_safepoint()
280