1 ; RUN: opt -S -strip-gc-relocates -instcombine < %s | FileCheck %s
2 ; RUN: opt -S -passes=strip-gc-relocates,instcombine < %s | FileCheck %s
3 ; test utility/debugging pass which removes gc.relocates, inserted by -rewrite-statepoints-for-gc
4 declare void @use_obj32(i32 addrspace(1)*) "gc-leaf-function"
7 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
8 declare i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token, i32, i32) #0
9 declare void @do_safepoint()
11 declare i32 addrspace(1)* @new_instance() #1
14 ; Simple case: remove gc.relocate
15 define i32 addrspace(1)* @test1(i32 addrspace(1)* %arg) gc "statepoint-example" {
18 ; CHECK: gc.statepoint
19 ; CHECK-NOT: gc.relocate
20 ; CHECK: ret i32 addrspace(1)* %arg
21 %statepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @g, i32 0, i32 0, i32 0, i32 0) ["gc-live"(i32 addrspace(1)* %arg), "deopt" (i32 100)]
22 %arg.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %statepoint_token, i32 0, i32 0) ; (%arg, %arg)
23 %arg.relocated.casted = bitcast i8 addrspace(1)* %arg.relocated to i32 addrspace(1)*
24 ret i32 addrspace(1)* %arg.relocated.casted
27 ; Remove gc.relocates in presence of nested relocates.
28 define void @test2(i32 addrspace(1)* %base) gc "statepoint-example" {
32 ; CHECK-NOT: gc.relocate
33 ; CHECK: call void @use_obj32(i32 addrspace(1)* %ptr.gep1)
34 ; CHECK: call void @use_obj32(i32 addrspace(1)* %ptr.gep1)
35 %ptr.gep = getelementptr i32, i32 addrspace(1)* %base, i32 15
36 %ptr.gep1 = getelementptr i32, i32 addrspace(1)* %ptr.gep, i32 15
37 %statepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 0) ["gc-live"(i32 addrspace(1)* %ptr.gep1, i32 addrspace(1)* %base)]
38 %ptr.gep1.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %statepoint_token, i32 1, i32 0) ; (%base, %ptr.gep1)
39 %ptr.gep1.relocated.casted = bitcast i8 addrspace(1)* %ptr.gep1.relocated to i32 addrspace(1)*
40 %base.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %statepoint_token, i32 1, i32 1) ; (%base, %base)
41 %base.relocated.casted = bitcast i8 addrspace(1)* %base.relocated to i32 addrspace(1)*
42 call void @use_obj32(i32 addrspace(1)* %ptr.gep1.relocated.casted)
43 %statepoint_token1 = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 0) ["gc-live"(i32 addrspace(1)* %ptr.gep1.relocated.casted, i32 addrspace(1)* %base.relocated.casted)]
44 %ptr.gep1.relocated2 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %statepoint_token1, i32 1, i32 0) ; (%base.relocated.casted, %ptr.gep1.relocated.casted)
45 %ptr.gep1.relocated2.casted = bitcast i8 addrspace(1)* %ptr.gep1.relocated2 to i32 addrspace(1)*
46 %base.relocated3 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %statepoint_token1, i32 1, i32 1) ; (%base.relocated.casted, %base.relocated.casted)
47 %base.relocated3.casted = bitcast i8 addrspace(1)* %base.relocated3 to i32 addrspace(1)*
48 call void @use_obj32(i32 addrspace(1)* %ptr.gep1.relocated2.casted)
52 ; landing pad gc.relocates removed by instcombine since it has no uses.
53 define i32 addrspace(1)* @test3(i32 addrspace(1)* %arg) gc "statepoint-example" personality i32 8 {
55 ; CHECK: gc.statepoint
56 ; CHECK-LABEL: normal_dest:
57 ; CHECK-NOT: gc.relocate
58 ; CHECK: ret i32 addrspace(1)* %arg
59 ; CHECK-LABEL: unwind_dest:
60 ; CHECK-NOT: gc.relocate
62 %statepoint_token = invoke token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @g, i32 0, i32 0, i32 0, i32 0) ["gc-live"(i32 addrspace(1)* %arg), "deopt" (i32 100)]
63 to label %normal_dest unwind label %unwind_dest
65 normal_dest: ; preds = %entry
66 %arg.relocated1 = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %statepoint_token, i32 0, i32 0) ; (%arg, %arg)
67 %arg.relocated1.casted = bitcast i8 addrspace(1)* %arg.relocated1 to i32 addrspace(1)*
68 ret i32 addrspace(1)* %arg.relocated1.casted
70 unwind_dest: ; preds = %entry
71 %lpad = landingpad token
73 %arg.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %lpad, i32 0, i32 0) ; (%arg, %arg)
74 %arg.relocated.casted = bitcast i8 addrspace(1)* %arg.relocated to i32 addrspace(1)*
79 define void @test4(i1 %cond) gc "statepoint-example" {
82 %base1 = call i32 addrspace(1)* @new_instance()
83 %base2 = call i32 addrspace(1)* @new_instance()
84 br i1 %cond, label %here, label %there
86 here: ; preds = %entry
89 there: ; preds = %entry
92 merge: ; preds = %there, %here
94 ; CHECK-NOT: gc.relocate
95 ; CHECK: %ptr.gep.remat = getelementptr i32, i32 addrspace(1)* %basephi.base
96 %basephi.base = phi i32 addrspace(1)* [ %base1, %here ], [ %base2, %there ], !is_base_value !0
97 %basephi = phi i32 addrspace(1)* [ %base1, %here ], [ %base2, %there ]
98 %ptr.gep = getelementptr i32, i32 addrspace(1)* %basephi, i32 15
99 %statepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 0) ["gc-live"(i32 addrspace(1)* %basephi.base)]
100 %basephi.base.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %statepoint_token, i32 0, i32 0) ; (%basephi.base, %basephi.base)
101 %basephi.base.relocated.casted = bitcast i8 addrspace(1)* %basephi.base.relocated to i32 addrspace(1)*
102 %ptr.gep.remat = getelementptr i32, i32 addrspace(1)* %basephi.base.relocated.casted, i32 15
103 call void @use_obj32(i32 addrspace(1)* %ptr.gep.remat)
107 ; The gc.relocate type is different from %arg, but removing the gc.relocate,
108 ; needs a bitcast to be added from i32 addrspace(1)* to i8 addrspace(1)*
109 define i8 addrspace(1)* @test5(i32 addrspace(1)* %arg) gc "statepoint-example" {
112 ; CHECK: gc.statepoint
113 ; CHECK-NOT: gc.relocate
114 %statepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @g, i32 0, i32 0, i32 0, i32 0) ["gc-live"(i32 addrspace(1)* %arg), "deopt" (i32 100)]
115 %arg.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %statepoint_token, i32 0, i32 0) ; (%arg, %arg)
116 ret i8 addrspace(1)* %arg.relocated
119 attributes #0 = { nounwind readonly }
120 attributes #1 = { nounwind "gc-leaf-function" }