1 ; RUN: opt -S -rewrite-statepoints-for-gc < %s | FileCheck %s
2 ; RUN: opt -S -passes=rewrite-statepoints-for-gc < %s | FileCheck %s
4 ; constants don't get relocated.
5 @G = addrspace(1) global i8 5
9 define i8 @test() gc "statepoint-example" {
11 ; CHECK: gc.statepoint
12 ; CHECK-NEXT: load i8, i8 addrspace(1)* inttoptr (i64 15 to i8 addrspace(1)*)
13 ; Mostly just here to show reasonable code test can come from.
15 call void @foo() [ "deopt"() ]
16 %res = load i8, i8 addrspace(1)* inttoptr (i64 15 to i8 addrspace(1)*)
20 define i8 @test2(i8 addrspace(1)* %p) gc "statepoint-example" {
22 ; CHECK: gc.statepoint
23 ; CHECK-NEXT: gc.relocate
25 ; Globals don't move and thus don't get relocated
27 call void @foo() [ "deopt"() ]
28 %cmp = icmp eq i8 addrspace(1)* %p, null
29 br i1 %cmp, label %taken, label %not_taken
31 taken: ; preds = %not_taken, %entry
34 not_taken: ; preds = %entry
35 %cmp2 = icmp ne i8 addrspace(1)* %p, null
36 br i1 %cmp2, label %taken, label %dead
38 dead: ; preds = %not_taken
39 %addr = getelementptr i8, i8 addrspace(1)* %p, i32 15
40 %res = load i8, i8 addrspace(1)* %addr
44 define i8 @test3(i1 %always_true) gc "statepoint-example" {
46 ; CHECK: gc.statepoint
47 ; CHECK-NEXT: load i8, i8 addrspace(1)* @G
49 call void @foo() [ "deopt"() ]
50 %res = load i8, i8 addrspace(1)* @G, align 1
54 ; Even for source languages without constant references, we can
55 ; see constants can show up along paths where the value is dead.
56 ; This is particular relevant when computing bases of PHIs.
57 define i8 addrspace(1)* @test4(i8 addrspace(1)* %p) gc "statepoint-example" {
60 %is_null = icmp eq i8 addrspace(1)* %p, null
61 br i1 %is_null, label %split, label %join
65 %arg_value_addr.i = getelementptr inbounds i8, i8 addrspace(1)* %p, i64 8
66 %arg_value_addr_casted.i = bitcast i8 addrspace(1)* %arg_value_addr.i to i8 addrspace(1)* addrspace(1)*
71 ; CHECK: %addr2.base =
72 %addr2 = phi i8 addrspace(1)* addrspace(1)* [ %arg_value_addr_casted.i, %split ], [ inttoptr (i64 8 to i8 addrspace(1)* addrspace(1)*), %entry ]
73 ;; NOTE: This particular example can be jump-threaded, but in general,
74 ;; we can't, and have to deal with the resulting IR.
75 br i1 %is_null, label %early-exit, label %use
78 ret i8 addrspace(1)* null
82 ; CHECK: gc.statepoint
85 %res = load i8 addrspace(1)*, i8 addrspace(1)* addrspace(1)* %addr2, align 1
86 ret i8 addrspace(1)* %res
89 ; Globals don't move and thus don't get relocated
90 define i8 addrspace(1)* @test5(i1 %always_true) gc "statepoint-example" {
92 ; CHECK: gc.statepoint
93 ; CHECK-NEXT: %res = extractelement <2 x i8 addrspace(1)*> <i8 addrspace(1)* @G, i8 addrspace(1)* @G>, i32 0
96 %res = extractelement <2 x i8 addrspace(1)*> <i8 addrspace(1)* @G, i8 addrspace(1)* @G>, i32 0
97 ret i8 addrspace(1)* %res
100 define i8 addrspace(1)* @test6(i64 %arg) gc "statepoint-example" {
102 ; Don't fail any assertions and don't record null as a live value
104 ; CHECK: gc.statepoint
105 ; CHECK-NOT: call {{.*}}gc.relocate
106 %load_addr = getelementptr i8, i8 addrspace(1)* null, i64 %arg
107 call void @foo() [ "deopt"() ]
108 ret i8 addrspace(1)* %load_addr
111 define i8 addrspace(1)* @test7(i64 %arg) gc "statepoint-example" {
113 ; Same as test7 but use regular constant instead of a null
115 ; CHECK: gc.statepoint
116 ; CHECK-NOT: call {{.*}}gc.relocate
117 %load_addr = getelementptr i8, i8 addrspace(1)* inttoptr (i64 15 to i8 addrspace(1)*), i64 %arg
118 call void @foo() [ "deopt"() ]
119 ret i8 addrspace(1)* %load_addr
122 define i8 @test8(i8 addrspace(1)* %p) gc "statepoint-example" {
123 ; Checks that base( phi(gep null, oop) ) = phi(null, base(oop)) and that we
124 ; correctly relocate this value
125 ; CHECK-LABEL: @test8
127 %is_null = icmp eq i8 addrspace(1)* %p, null
128 br i1 %is_null, label %null.crit-edge, label %not-null
131 %load_addr = getelementptr inbounds i8, i8 addrspace(1)* %p, i64 8
135 %load_addr.const = getelementptr inbounds i8, i8 addrspace(1)* null, i64 8
139 %addr = phi i8 addrspace(1)* [ %load_addr, %not-null ], [%load_addr.const, %null.crit-edge]
140 ; CHECK: %addr.base = phi i8 addrspace(1)*
141 ; CHECK-DAG: [ %p, %not-null ]
142 ; CHECK-DAG: [ null, %null.crit-edge ]
143 ; CHECK: gc.statepoint
144 call void @foo() [ "deopt"() ]
145 ; CHECK-DAG: call {{.*}}gc.relocate{{.*}}(%addr.base, %addr.base)
146 ; CHECK-DAG: call {{.*}}gc.relocate{{.*}}(%addr.base, %addr)
147 br i1 %is_null, label %early-exit, label %use
153 %res = load i8, i8 addrspace(1)* %addr, align 1
157 define i8 @test9(i8 addrspace(1)* %p) gc "statepoint-example" {
158 ; Checks that base( phi(inttoptr, oop) ) = phi(null, base(oop)) and that we
159 ; correctly relocate this value
160 ; CHECK-LABEL: @test9
162 %is_null = icmp eq i8 addrspace(1)* %p, null
163 br i1 %is_null, label %null.crit-edge, label %not-null
166 %load_addr = getelementptr inbounds i8, i8 addrspace(1)* %p, i64 8
173 %addr = phi i8 addrspace(1)* [ %load_addr, %not-null ], [inttoptr (i64 8 to i8 addrspace(1)*), %null.crit-edge]
174 ; CHECK: %addr.base = phi i8 addrspace(1)*
175 ; CHECK-DAG: [ %p, %not-null ]
176 ; CHECK-DAG: [ null, %null.crit-edge ]
177 ; CHECK: gc.statepoint
178 call void @foo() [ "deopt"() ]
179 ; CHECK-DAG: call {{.*}}gc.relocate{{.*}}(%addr.base, %addr.base)
180 ; CHECK-DAG: call {{.*}}gc.relocate{{.*}}(%addr.base, %addr)
181 br i1 %is_null, label %early-exit, label %use
187 %res = load i8, i8 addrspace(1)* %addr, align 1
191 define i8 @test10(i8 addrspace(1)* %p) gc "statepoint-example" {
192 ; Checks that base( phi(const gep, oop) ) = phi(null, base(oop)) and that we
193 ; correctly relocate this value
194 ; CHECK-LABEL: @test10
196 %is_null = icmp eq i8 addrspace(1)* %p, null
197 br i1 %is_null, label %null.crit-edge, label %not-null
200 %load_addr = getelementptr inbounds i8, i8 addrspace(1)* %p, i64 8
207 %addr = phi i8 addrspace(1)* [ %load_addr, %not-null ], [getelementptr (i8, i8 addrspace(1)* null, i64 8), %null.crit-edge]
208 ; CHECK: %addr.base = phi i8 addrspace(1)*
209 ; CHECK-DAG: [ %p, %not-null ]
210 ; CHECK-DAG: [ null, %null.crit-edge ]
211 ; CHECK: gc.statepoint
212 call void @foo() [ "deopt"() ]
213 ; CHECK-DAG: call {{.*}}gc.relocate{{.*}}(%addr.base, %addr.base)
214 ; CHECK-DAG: call {{.*}}gc.relocate{{.*}}(%addr.base, %addr)
215 br i1 %is_null, label %early-exit, label %use
221 %res = load i8, i8 addrspace(1)* %addr, align 1
225 define i32 addrspace(1)* @test11(i1 %c) gc "statepoint-example" {
226 ; CHECK-LABEL: @test11
227 ; Checks that base( select(const1, const2) ) == null and that we don't record
228 ; such value in the oop map
230 %val = select i1 %c, i32 addrspace(1)* inttoptr (i64 8 to i32 addrspace(1)*), i32 addrspace(1)* inttoptr (i64 15 to i32 addrspace(1)*)
231 ; CHECK: gc.statepoint
232 ; CHECK-NOT: call {{.*}}gc.relocate
233 call void @foo() [ "deopt"() ]
234 ret i32 addrspace(1)* %val
238 define <2 x i32 addrspace(1)*> @test12(i1 %c) gc "statepoint-example" {
239 ; CHECK-LABEL: @test12
240 ; Same as test11 but with vectors
242 %val = select i1 %c, <2 x i32 addrspace(1)*> <i32 addrspace(1)* inttoptr (i64 5 to i32 addrspace(1)*),
243 i32 addrspace(1)* inttoptr (i64 15 to i32 addrspace(1)*)>,
244 <2 x i32 addrspace(1)*> <i32 addrspace(1)* inttoptr (i64 30 to i32 addrspace(1)*),
245 i32 addrspace(1)* inttoptr (i64 60 to i32 addrspace(1)*)>
246 ; CHECK: gc.statepoint
247 ; CHECK-NOT: call {{.*}}gc.relocate
248 call void @foo() [ "deopt"() ]
249 ret <2 x i32 addrspace(1)*> %val
252 define <2 x i32 addrspace(1)*> @test13(i1 %c, <2 x i32 addrspace(1)*> %ptr) gc "statepoint-example" {
253 ; CHECK-LABEL: @test13
254 ; Similar to test8, test9 and test10 but with vectors
256 %val = select i1 %c, <2 x i32 addrspace(1)*> %ptr,
257 <2 x i32 addrspace(1)*> <i32 addrspace(1)* inttoptr (i64 30 to i32 addrspace(1)*), i32 addrspace(1)* inttoptr (i64 60 to i32 addrspace(1)*)>
258 ; CHECK: %val.base = select i1 %c, <2 x i32 addrspace(1)*> %ptr, <2 x i32 addrspace(1)*> zeroinitializer, !is_base_value !0
259 ; CHECK: gc.statepoint
260 call void @foo() [ "deopt"() ]
261 ; CHECK-DAG: call {{.*}}gc.relocate{{.*}}(%val.base, %val.base)
262 ; CHECK-DAG: call {{.*}}gc.relocate{{.*}}(%val.base, %val)
263 ret <2 x i32 addrspace(1)*> %val