1 ; RUN: opt -S -rewrite-statepoints-for-gc %s | FileCheck %s
4 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
6 ; constants don't get relocated.
7 define i8 @test() gc "statepoint-example" {
10 ; CHECK-NEXT: load i8, i8 addrspace(1)* inttoptr (i64 15 to i8 addrspace(1)*)
12 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 0)
13 %res = load i8, i8 addrspace(1)* inttoptr (i64 15 to i8 addrspace(1)*)
18 ; Mostly just here to show reasonable code test can come from.
19 define i8 @test2(i8 addrspace(1)* %p) gc "statepoint-example" {
21 ; CHECK: gc.statepoint
22 ; CHECK-NEXT: gc.relocate
25 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 0)
26 %cmp = icmp eq i8 addrspace(1)* %p, null
27 br i1 %cmp, label %taken, label %not_taken
33 %cmp2 = icmp ne i8 addrspace(1)* %p, null
34 br i1 %cmp2, label %taken, label %dead
37 ; We see that dead can't be reached, but the optimizer might not. It's
38 ; completely legal for it to exploit the fact that if dead executed, %p
39 ; would have to equal null. This can produce intermediate states which
40 ; look like that of test above, even if arbitrary constant addresses aren't
41 ; legal in the source language
42 %addr = getelementptr i8, i8 addrspace(1)* %p, i32 15
43 %res = load i8, i8addrspace(1)* %addr
47 @G = addrspace(1) global i8 5
49 ; Globals don't move and thus don't get relocated
50 define i8 @test3(i1 %always_true) gc "statepoint-example" {
52 ; CHECK: gc.statepoint
53 ; CHECK-NEXT: load i8, i8 addrspace(1)* @G
55 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 0)
56 %res = load i8, i8 addrspace(1)* @G, align 1
60 ; Even for source languages without constant references, we can
61 ; see constants can show up along paths where the value is dead.
62 ; This is particular relevant when computing bases of PHIs.
63 define i8 addrspace(1)* @test4(i8 addrspace(1)* %p) gc "statepoint-example" {
66 %is_null = icmp eq i8 addrspace(1)* %p, null
67 br i1 %is_null, label %split, label %join
70 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 0)
71 %arg_value_addr.i = getelementptr inbounds i8, i8 addrspace(1)* %p, i64 8
72 %arg_value_addr_casted.i = bitcast i8 addrspace(1)* %arg_value_addr.i to i8 addrspace(1)* addrspace(1)*
77 ; CHECK: %addr2.base =
78 %addr2 = phi i8 addrspace(1)* addrspace(1)* [ %arg_value_addr_casted.i, %split ], [ inttoptr (i64 8 to i8 addrspace(1)* addrspace(1)*), %entry ]
79 ;; NOTE: This particular example can be jump-threaded, but in general,
80 ;; we can't, and have to deal with the resulting IR.
81 br i1 %is_null, label %early-exit, label %use
84 ret i8 addrspace(1)* null
88 ; CHECK: gc.statepoint
90 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 0)
91 %res = load i8 addrspace(1)*, i8 addrspace(1)* addrspace(1)* %addr2, align 1
92 ret i8 addrspace(1)* %res
95 ; Globals don't move and thus don't get relocated
96 define i8 addrspace(1)* @test5(i1 %always_true) gc "statepoint-example" {
98 ; CHECK: gc.statepoint
99 ; CHECK-NEXT: %res = extractelement <2 x i8 addrspace(1)*> <i8 addrspace(1)* @G, i8 addrspace(1)* @G>, i32 0
101 call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 0)
102 %res = extractelement <2 x i8 addrspace(1)*> <i8 addrspace(1)* @G, i8 addrspace(1)* @G>, i32 0
103 ret i8 addrspace(1)* %res