1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
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(ptr addrspace(1)) "gc-leaf-function"
7 declare token @llvm.experimental.gc.statepoint.p0(i64, i32, ptr, i32, i32, ...)
8 declare ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token, i32, i32) #0
9 declare void @do_safepoint()
11 declare ptr addrspace(1) @new_instance() #1
14 ; Simple case: remove gc.relocate
15 define ptr addrspace(1) @test1(ptr addrspace(1) %arg) gc "statepoint-example" {
16 ; CHECK-LABEL: @test1(
18 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr nonnull elementtype(void ()) @g, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i32 100), "gc-live"() ]
19 ; CHECK-NEXT: ret ptr addrspace(1) [[ARG:%.*]]
22 %statepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @g, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %arg), "deopt" (i32 100)]
23 %arg.relocated = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token, i32 0, i32 0) ; (%arg, %arg)
24 ret ptr addrspace(1) %arg.relocated
27 ; Remove gc.relocates in presence of nested relocates.
28 define void @test2(ptr addrspace(1) %base) gc "statepoint-example" {
29 ; CHECK-LABEL: @test2(
31 ; CHECK-NEXT: [[PTR_GEP1:%.*]] = getelementptr i32, ptr addrspace(1) [[BASE:%.*]], i64 30
32 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr nonnull elementtype(void ()) @do_safepoint, i32 0, i32 0, i32 0, i32 0) [ "gc-live"() ]
33 ; CHECK-NEXT: call void @use_obj32(ptr addrspace(1) [[PTR_GEP1]])
34 ; CHECK-NEXT: [[STATEPOINT_TOKEN1:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr nonnull elementtype(void ()) @do_safepoint, i32 0, i32 0, i32 0, i32 0) [ "gc-live"() ]
35 ; CHECK-NEXT: call void @use_obj32(ptr addrspace(1) [[PTR_GEP1]])
36 ; CHECK-NEXT: ret void
39 %ptr.gep = getelementptr i32, ptr addrspace(1) %base, i32 15
40 %ptr.gep1 = getelementptr i32, ptr addrspace(1) %ptr.gep, i32 15
41 %statepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @do_safepoint, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %ptr.gep1, ptr addrspace(1) %base)]
42 %ptr.gep1.relocated = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token, i32 1, i32 0) ; (%base, %ptr.gep1)
43 %base.relocated = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token, i32 1, i32 1) ; (%base, %base)
44 call void @use_obj32(ptr addrspace(1) %ptr.gep1.relocated)
45 %statepoint_token1 = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @do_safepoint, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %ptr.gep1.relocated, ptr addrspace(1) %base.relocated)]
46 %ptr.gep1.relocated2 = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token1, i32 1, i32 0) ; (%base.relocated, %ptr.gep1.relocated)
47 %base.relocated3 = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token1, i32 1, i32 1) ; (%base.relocated, %base.relocated)
48 call void @use_obj32(ptr addrspace(1) %ptr.gep1.relocated2)
52 ; landing pad gc.relocates removed by instcombine since it has no uses.
53 define ptr addrspace(1) @test3(ptr addrspace(1) %arg) gc "statepoint-example" personality i32 8 {
54 ; CHECK-LABEL: @test3(
56 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = invoke token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr nonnull elementtype(void ()) @g, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i32 100), "gc-live"() ]
57 ; CHECK-NEXT: to label [[NORMAL_DEST:%.*]] unwind label [[UNWIND_DEST:%.*]]
59 ; CHECK-NEXT: ret ptr addrspace(1) [[ARG:%.*]]
61 ; CHECK-NEXT: [[LPAD:%.*]] = landingpad token
63 ; CHECK-NEXT: resume token undef
66 %statepoint_token = invoke token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @g, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %arg), "deopt" (i32 100)]
67 to label %normal_dest unwind label %unwind_dest
69 normal_dest: ; preds = %entry
70 %arg.relocated1 = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token, i32 0, i32 0) ; (%arg, %arg)
71 ret ptr addrspace(1) %arg.relocated1
73 unwind_dest: ; preds = %entry
74 %lpad = landingpad token
76 %arg.relocated = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %lpad, i32 0, i32 0) ; (%arg, %arg)
81 define void @test4(i1 %cond) gc "statepoint-example" {
82 ; CHECK-LABEL: @test4(
84 ; CHECK-NEXT: [[BASE1:%.*]] = call ptr addrspace(1) @new_instance()
85 ; CHECK-NEXT: [[BASE2:%.*]] = call ptr addrspace(1) @new_instance()
86 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[HERE:%.*]], label [[THERE:%.*]]
88 ; CHECK-NEXT: br label [[MERGE:%.*]]
90 ; CHECK-NEXT: br label [[MERGE]]
92 ; CHECK-NEXT: [[BASEPHI_BASE:%.*]] = phi ptr addrspace(1) [ [[BASE1]], [[HERE]] ], [ [[BASE2]], [[THERE]] ], !is_base_value !0
93 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr nonnull elementtype(void ()) @do_safepoint, i32 0, i32 0, i32 0, i32 0) [ "gc-live"() ]
94 ; CHECK-NEXT: [[PTR_GEP_REMAT:%.*]] = getelementptr i32, ptr addrspace(1) [[BASEPHI_BASE]], i64 15
95 ; CHECK-NEXT: call void @use_obj32(ptr addrspace(1) [[PTR_GEP_REMAT]])
96 ; CHECK-NEXT: ret void
99 %base1 = call ptr addrspace(1) @new_instance()
100 %base2 = call ptr addrspace(1) @new_instance()
101 br i1 %cond, label %here, label %there
103 here: ; preds = %entry
106 there: ; preds = %entry
109 merge: ; preds = %there, %here
110 %basephi.base = phi ptr addrspace(1) [ %base1, %here ], [ %base2, %there ], !is_base_value !0
111 %basephi = phi ptr addrspace(1) [ %base1, %here ], [ %base2, %there ]
112 %ptr.gep = getelementptr i32, ptr addrspace(1) %basephi, i32 15
113 %statepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @do_safepoint, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %basephi.base)]
114 %basephi.base.relocated = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token, i32 0, i32 0) ; (%basephi.base, %basephi.base)
115 %ptr.gep.remat = getelementptr i32, ptr addrspace(1) %basephi.base.relocated, i32 15
116 call void @use_obj32(ptr addrspace(1) %ptr.gep.remat)
120 ; The gc.relocate type is different from %arg, but removing the gc.relocate,
121 ; needs a bitcast to be added from ptr addrspace(1) to ptr addrspace(1)
122 define ptr addrspace(1) @test5(ptr addrspace(1) %arg) gc "statepoint-example" {
123 ; CHECK-LABEL: @test5(
125 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr nonnull elementtype(void ()) @g, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i32 100), "gc-live"() ]
126 ; CHECK-NEXT: ret ptr addrspace(1) [[ARG:%.*]]
129 %statepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @g, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %arg), "deopt" (i32 100)]
130 %arg.relocated = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %statepoint_token, i32 0, i32 0) ; (%arg, %arg)
131 ret ptr addrspace(1) %arg.relocated
134 attributes #0 = { nounwind readonly }
135 attributes #1 = { nounwind "gc-leaf-function" }