1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -rewrite-statepoints-for-gc -S 2>&1 | FileCheck %s
3 ; RUN: opt < %s -passes=rewrite-statepoints-for-gc -S 2>&1 | FileCheck %s
5 declare i64 addrspace(1)* @generate_obj() "gc-leaf-function"
7 declare void @use_obj(i64 addrspace(1)*) "gc-leaf-function"
9 ; The rewriting needs to make %obj loop variant by inserting a phi
10 ; of the original value and it's relocation.
11 define void @test() gc "statepoint-example" {
14 ; CHECK-NEXT: [[OBJ:%.*]] = call i64 addrspace(1)* @generate_obj()
15 ; CHECK-NEXT: br label [[LOOP:%.*]]
17 ; CHECK-NEXT: [[DOT0:%.*]] = phi i64 addrspace(1)* [ [[OBJ]], [[ENTRY:%.*]] ], [ [[OBJ_RELOCATED_CASTED:%.*]], [[LOOP]] ]
18 ; CHECK-NEXT: call void @use_obj(i64 addrspace(1)* [[DOT0]])
19 ; CHECK-NEXT: [[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) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0), "gc-live"(i64 addrspace(1)* [[DOT0]]) ]
20 ; CHECK-NEXT: [[OBJ_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 0, i32 0)
21 ; CHECK-NEXT: [[OBJ_RELOCATED_CASTED]] = bitcast i8 addrspace(1)* [[OBJ_RELOCATED]] to i64 addrspace(1)*
22 ; CHECK-NEXT: br label [[LOOP]]
25 %obj = call i64 addrspace(1)* @generate_obj()
29 call void @use_obj(i64 addrspace(1)* %obj)
30 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
34 declare void @do_safepoint()
36 declare void @parse_point(i64 addrspace(1)*)
38 define i64 addrspace(1)* @test1(i32 %caller, i8 addrspace(1)* %a, i8 addrspace(1)* %b, i32 %unknown) gc "statepoint-example" {
39 ; CHECK-LABEL: @test1(
41 ; CHECK-NEXT: br i1 undef, label [[LEFT:%.*]], label [[RIGHT:%.*]]
43 ; CHECK-NEXT: [[A_CAST:%.*]] = bitcast i8 addrspace(1)* [[A:%.*]] to i64 addrspace(1)*
44 ; CHECK-NEXT: switch i32 [[UNKNOWN:%.*]], label [[RIGHT]] [
45 ; CHECK-NEXT: i32 0, label [[MERGE:%.*]]
46 ; CHECK-NEXT: i32 1, label [[MERGE]]
47 ; CHECK-NEXT: i32 5, label [[MERGE]]
50 ; CHECK-NEXT: [[B_CAST:%.*]] = bitcast i8 addrspace(1)* [[B:%.*]] to i64 addrspace(1)*
51 ; CHECK-NEXT: br label [[MERGE]]
53 ; CHECK-NEXT: [[VALUE:%.*]] = phi i64 addrspace(1)* [ [[A_CAST]], [[LEFT]] ], [ [[A_CAST]], [[LEFT]] ], [ [[A_CAST]], [[LEFT]] ], [ [[B_CAST]], [[RIGHT]] ]
54 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, void (i64 addrspace(1)*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidp1i64f(i64 2882400000, i32 0, void (i64 addrspace(1)*)* @parse_point, i32 1, i32 0, i64 addrspace(1)* [[VALUE]], i32 0, i32 0) [ "deopt"(i32 0, i32 0, i32 0, i32 0, i32 0), "gc-live"(i64 addrspace(1)* [[VALUE]]) ]
55 ; CHECK-NEXT: [[VALUE_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 0, i32 0)
56 ; CHECK-NEXT: [[VALUE_RELOCATED_CASTED:%.*]] = bitcast i8 addrspace(1)* [[VALUE_RELOCATED]] to i64 addrspace(1)*
57 ; CHECK-NEXT: ret i64 addrspace(1)* [[VALUE_RELOCATED_CASTED]]
60 br i1 undef, label %left, label %right
63 ; Our safepoint placement pass calls removeUnreachableBlocks, which does a bunch
64 ; of simplifications to branch instructions. This bug is visible only when
65 ; there are multiple branches into the same block from the same predecessor, and
66 ; the following ceremony is to make that artefact survive a call to
67 ; removeUnreachableBlocks. As an example, "br i1 undef, label %merge, label %merge"
68 ; will get simplified to "br label %merge" by removeUnreachableBlocks.
69 %a.cast = bitcast i8 addrspace(1)* %a to i64 addrspace(1)*
70 switch i32 %unknown, label %right [
78 %b.cast = bitcast i8 addrspace(1)* %b to i64 addrspace(1)*
82 %value = phi i64 addrspace(1)* [ %a.cast, %left ], [ %a.cast, %left ], [ %a.cast, %left ], [ %b.cast, %right ]
83 call void @parse_point(i64 addrspace(1)* %value) [ "deopt"(i32 0, i32 0, i32 0, i32 0, i32 0) ]
84 ret i64 addrspace(1)* %value
87 ;; The purpose of this test is to ensure that when two live values share a
88 ;; base defining value with inherent conflicts, we end up with a *single*
89 ;; base phi/select per such node. This is testing an optimization, not a
90 ;; fundemental correctness criteria
91 define void @test2(i1 %cnd, i64 addrspace(1)* %base_obj, i64 addrspace(1)* %base_arg2) gc "statepoint-example" {
92 ; CHECK-LABEL: @test2(
94 ; CHECK-NEXT: [[OBJ:%.*]] = getelementptr i64, i64 addrspace(1)* [[BASE_OBJ:%.*]], i32 1
95 ; CHECK-NEXT: br label [[LOOP:%.*]]
97 ; CHECK-NEXT: [[DOT0:%.*]] = phi i64 addrspace(1)* [ [[BASE_ARG2:%.*]], [[ENTRY:%.*]] ], [ [[BASE_ARG2_RELOCATED_CASTED:%.*]], [[LOOP]] ]
98 ; CHECK-NEXT: [[CURRENT_BASE:%.*]] = phi i64 addrspace(1)* [ [[BASE_OBJ]], [[ENTRY]] ], [ [[NEXT_BASE_RELOCATED_CASTED:%.*]], [[LOOP]] ], !is_base_value !0
99 ; CHECK-NEXT: [[CURRENT:%.*]] = phi i64 addrspace(1)* [ [[OBJ]], [[ENTRY]] ], [ [[NEXT_RELOCATED_CASTED:%.*]], [[LOOP]] ]
100 ; CHECK-NEXT: [[EXTRA:%.*]] = phi i64 addrspace(1)* [ [[OBJ]], [[ENTRY]] ], [ [[EXTRA2_RELOCATED_CASTED:%.*]], [[LOOP]] ]
101 ; CHECK-NEXT: [[NEXTA:%.*]] = getelementptr i64, i64 addrspace(1)* [[CURRENT]], i32 1
102 ; CHECK-NEXT: [[NEXT_BASE:%.*]] = select i1 [[CND:%.*]], i64 addrspace(1)* [[CURRENT_BASE]], i64 addrspace(1)* [[DOT0]], !is_base_value !0
103 ; CHECK-NEXT: [[NEXT:%.*]] = select i1 [[CND]], i64 addrspace(1)* [[NEXTA]], i64 addrspace(1)* [[DOT0]]
104 ; CHECK-NEXT: [[EXTRA2_BASE:%.*]] = select i1 [[CND]], i64 addrspace(1)* [[CURRENT_BASE]], i64 addrspace(1)* [[DOT0]], !is_base_value !0
105 ; CHECK-NEXT: [[EXTRA2:%.*]] = select i1 [[CND]], i64 addrspace(1)* [[NEXTA]], i64 addrspace(1)* [[DOT0]]
106 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0), "gc-live"(i64 addrspace(1)* [[NEXT_BASE]], i64 addrspace(1)* [[NEXT]], i64 addrspace(1)* [[EXTRA2]], i64 addrspace(1)* [[DOT0]], i64 addrspace(1)* [[EXTRA2_BASE]]) ]
107 ; CHECK-NEXT: [[NEXT_BASE_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 0, i32 0)
108 ; CHECK-NEXT: [[NEXT_BASE_RELOCATED_CASTED]] = bitcast i8 addrspace(1)* [[NEXT_BASE_RELOCATED]] to i64 addrspace(1)*
109 ; CHECK-NEXT: [[NEXT_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 0, i32 1)
110 ; CHECK-NEXT: [[NEXT_RELOCATED_CASTED]] = bitcast i8 addrspace(1)* [[NEXT_RELOCATED]] to i64 addrspace(1)*
111 ; CHECK-NEXT: [[EXTRA2_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 4, i32 2)
112 ; CHECK-NEXT: [[EXTRA2_RELOCATED_CASTED]] = bitcast i8 addrspace(1)* [[EXTRA2_RELOCATED]] to i64 addrspace(1)*
113 ; CHECK-NEXT: [[BASE_ARG2_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 3, i32 3)
114 ; CHECK-NEXT: [[BASE_ARG2_RELOCATED_CASTED]] = bitcast i8 addrspace(1)* [[BASE_ARG2_RELOCATED]] to i64 addrspace(1)*
115 ; CHECK-NEXT: [[EXTRA2_BASE_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 4, i32 4)
116 ; CHECK-NEXT: [[EXTRA2_BASE_RELOCATED_CASTED:%.*]] = bitcast i8 addrspace(1)* [[EXTRA2_BASE_RELOCATED]] to i64 addrspace(1)*
117 ; CHECK-NEXT: br label [[LOOP]]
120 %obj = getelementptr i64, i64 addrspace(1)* %base_obj, i32 1
123 ; Given the two selects are equivelent, so are their base phis - ideally,
124 ; we'd have commoned these, but that's a missed optimization, not correctness.
125 ;; Both 'next' and 'extra2' are live across the backedge safepoint...
128 %current = phi i64 addrspace(1)* [ %obj, %entry ], [ %next, %loop ]
129 %extra = phi i64 addrspace(1)* [ %obj, %entry ], [ %extra2, %loop ]
130 %nexta = getelementptr i64, i64 addrspace(1)* %current, i32 1
131 %next = select i1 %cnd, i64 addrspace(1)* %nexta, i64 addrspace(1)* %base_arg2
132 %extra2 = select i1 %cnd, i64 addrspace(1)* %nexta, i64 addrspace(1)* %base_arg2
133 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
137 define i64 addrspace(1)* @test3(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" {
138 ; CHECK-LABEL: @test3(
140 ; CHECK-NEXT: br i1 [[CND:%.*]], label [[MERGE:%.*]], label [[TAKEN:%.*]]
142 ; CHECK-NEXT: br label [[MERGE]]
144 ; CHECK-NEXT: [[BDV:%.*]] = phi i64 addrspace(1)* [ [[OBJ:%.*]], [[ENTRY:%.*]] ], [ [[OBJ2:%.*]], [[TAKEN]] ]
145 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0), "gc-live"(i64 addrspace(1)* [[BDV]]) ]
146 ; CHECK-NEXT: [[BDV_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 0, i32 0)
147 ; CHECK-NEXT: [[BDV_RELOCATED_CASTED:%.*]] = bitcast i8 addrspace(1)* [[BDV_RELOCATED]] to i64 addrspace(1)*
148 ; CHECK-NEXT: ret i64 addrspace(1)* [[BDV_RELOCATED_CASTED]]
151 br i1 %cnd, label %merge, label %taken
157 %bdv = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj2, %taken ]
158 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
159 ret i64 addrspace(1)* %bdv
162 define i64 addrspace(1)* @test4(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" {
163 ; CHECK-LABEL: @test4(
165 ; CHECK-NEXT: br i1 [[CND:%.*]], label [[MERGE:%.*]], label [[TAKEN:%.*]]
167 ; CHECK-NEXT: br label [[MERGE]]
169 ; CHECK-NEXT: [[BDV:%.*]] = phi i64 addrspace(1)* [ [[OBJ:%.*]], [[ENTRY:%.*]] ], [ [[OBJ]], [[TAKEN]] ]
170 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0), "gc-live"(i64 addrspace(1)* [[BDV]]) ]
171 ; CHECK-NEXT: [[BDV_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 0, i32 0)
172 ; CHECK-NEXT: [[BDV_RELOCATED_CASTED:%.*]] = bitcast i8 addrspace(1)* [[BDV_RELOCATED]] to i64 addrspace(1)*
173 ; CHECK-NEXT: ret i64 addrspace(1)* [[BDV_RELOCATED_CASTED]]
176 br i1 %cnd, label %merge, label %taken
182 %bdv = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj, %taken ]
183 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
184 ret i64 addrspace(1)* %bdv
187 define i64 addrspace(1)* @test5(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" {
188 ; CHECK-LABEL: @test5(
190 ; CHECK-NEXT: br label [[MERGE:%.*]]
192 ; CHECK-NEXT: [[BDV:%.*]] = phi i64 addrspace(1)* [ [[OBJ:%.*]], [[ENTRY:%.*]] ], [ [[OBJ2:%.*]], [[MERGE]] ]
193 ; CHECK-NEXT: br i1 [[CND:%.*]], label [[MERGE]], label [[NEXT:%.*]]
195 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0), "gc-live"(i64 addrspace(1)* [[BDV]]) ]
196 ; CHECK-NEXT: [[BDV_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 0, i32 0)
197 ; CHECK-NEXT: [[BDV_RELOCATED_CASTED:%.*]] = bitcast i8 addrspace(1)* [[BDV_RELOCATED]] to i64 addrspace(1)*
198 ; CHECK-NEXT: ret i64 addrspace(1)* [[BDV_RELOCATED_CASTED]]
204 %bdv = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj2, %merge ]
205 br i1 %cnd, label %merge, label %next
208 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
209 ret i64 addrspace(1)* %bdv
212 ; We know from the deopt use that %bdv must be a base value, and as
213 ; result can avoid materializing the extra copy of the BDV phi node.
214 ; (Even without a general forward analysis)
215 define i64 addrspace(1)* @test6(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" {
216 ; CHECK-LABEL: @test6(
218 ; CHECK-NEXT: br label [[MERGE:%.*]]
220 ; CHECK-NEXT: [[BDV:%.*]] = phi i64 addrspace(1)* [ [[OBJ:%.*]], [[ENTRY:%.*]] ], [ [[OBJ2:%.*]], [[MERGE]] ]
221 ; CHECK-NEXT: br i1 [[CND:%.*]], label [[MERGE]], label [[NEXT:%.*]]
223 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i64 addrspace(1)* [[BDV]]), "gc-live"(i64 addrspace(1)* [[BDV]]) ]
224 ; CHECK-NEXT: [[BDV_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 0, i32 0)
225 ; CHECK-NEXT: [[BDV_RELOCATED_CASTED:%.*]] = bitcast i8 addrspace(1)* [[BDV_RELOCATED]] to i64 addrspace(1)*
226 ; CHECK-NEXT: ret i64 addrspace(1)* [[BDV_RELOCATED_CASTED]]
232 %bdv = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj2, %merge ]
233 br i1 %cnd, label %merge, label %next
236 call void @foo() [ "deopt"(i64 addrspace(1)* %bdv) ]
237 ret i64 addrspace(1)* %bdv