1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=rewrite-statepoints-for-gc -S 2>&1 | FileCheck %s
4 declare ptr addrspace(1) @generate_obj() "gc-leaf-function"
6 declare void @use_obj(ptr addrspace(1)) "gc-leaf-function"
8 ; The rewriting needs to make %obj loop variant by inserting a phi
9 ; of the original value and it's relocation.
10 define void @test() gc "statepoint-example" {
13 ; CHECK-NEXT: [[OBJ:%.*]] = call ptr addrspace(1) @generate_obj()
14 ; CHECK-NEXT: br label [[LOOP:%.*]]
16 ; CHECK-NEXT: [[DOT0:%.*]] = phi ptr addrspace(1) [ [[OBJ]], [[ENTRY:%.*]] ], [ [[OBJ_RELOCATED:%.*]], [[LOOP]] ]
17 ; CHECK-NEXT: call void @use_obj(ptr addrspace(1) [[DOT0]])
18 ; CHECK-NEXT: [[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) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0), "gc-live"(ptr addrspace(1) [[DOT0]]) ]
19 ; CHECK-NEXT: [[OBJ_RELOCATED]] = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 0, i32 0)
20 ; CHECK-NEXT: br label [[LOOP]]
23 %obj = call ptr addrspace(1) @generate_obj()
27 call void @use_obj(ptr addrspace(1) %obj)
28 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
32 declare void @do_safepoint()
34 declare void @parse_point(ptr addrspace(1))
36 define ptr addrspace(1) @test1(i32 %caller, ptr addrspace(1) %a, ptr addrspace(1) %b, i32 %unknown, i1 %c) gc "statepoint-example" {
37 ; CHECK-LABEL: @test1(
39 ; CHECK-NEXT: br i1 [[C:%.*]], label [[LEFT:%.*]], label [[RIGHT:%.*]]
41 ; CHECK-NEXT: switch i32 [[UNKNOWN:%.*]], label [[RIGHT]] [
42 ; CHECK-NEXT: i32 0, label [[MERGE:%.*]]
43 ; CHECK-NEXT: i32 1, label [[MERGE]]
44 ; CHECK-NEXT: i32 5, label [[MERGE]]
47 ; CHECK-NEXT: br label [[MERGE]]
49 ; CHECK-NEXT: [[VALUE:%.*]] = phi ptr addrspace(1) [ [[A:%.*]], [[LEFT]] ], [ [[A]], [[LEFT]] ], [ [[A]], [[LEFT]] ], [ [[B:%.*]], [[RIGHT]] ]
50 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void (ptr addrspace(1))) @parse_point, i32 1, i32 0, ptr addrspace(1) [[VALUE]], i32 0, i32 0) [ "deopt"(i32 0, i32 0, i32 0, i32 0, i32 0), "gc-live"(ptr addrspace(1) [[VALUE]]) ]
51 ; CHECK-NEXT: [[VALUE_RELOCATED:%.*]] = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 0, i32 0)
52 ; CHECK-NEXT: ret ptr addrspace(1) [[VALUE_RELOCATED]]
55 br i1 %c, label %left, label %right
58 ; Our safepoint placement pass calls removeUnreachableBlocks, which does a bunch
59 ; of simplifications to branch instructions. This bug is visible only when
60 ; there are multiple branches into the same block from the same predecessor, and
61 ; the following ceremony is to make that artefact survive a call to
62 ; removeUnreachableBlocks. As an example, "br i1 undef, label %merge, label %merge"
63 ; will get simplified to "br label %merge" by removeUnreachableBlocks.
64 switch i32 %unknown, label %right [
75 %value = phi ptr addrspace(1) [ %a, %left ], [ %a, %left ], [ %a, %left ], [ %b, %right ]
76 call void @parse_point(ptr addrspace(1) %value) [ "deopt"(i32 0, i32 0, i32 0, i32 0, i32 0) ]
77 ret ptr addrspace(1) %value
80 ;; The purpose of this test is to ensure that when two live values share a
81 ;; base defining value with inherent conflicts, we end up with a *single*
82 ;; base phi/select per such node. This is testing an optimization, not a
83 ;; fundemental correctness criteria
84 define void @test2(i1 %cnd, ptr addrspace(1) %base_obj, ptr addrspace(1) %base_arg2) gc "statepoint-example" {
85 ; CHECK-LABEL: @test2(
87 ; CHECK-NEXT: [[OBJ:%.*]] = getelementptr i64, ptr addrspace(1) [[BASE_OBJ:%.*]], i32 1
88 ; CHECK-NEXT: br label [[LOOP:%.*]]
90 ; CHECK-NEXT: [[DOT0:%.*]] = phi ptr addrspace(1) [ [[BASE_ARG2:%.*]], [[ENTRY:%.*]] ], [ [[BASE_ARG2_RELOCATED:%.*]], [[LOOP]] ]
91 ; CHECK-NEXT: [[CURRENT_BASE:%.*]] = phi ptr addrspace(1) [ [[BASE_OBJ]], [[ENTRY]] ], [ [[NEXT_BASE_RELOCATED:%.*]], [[LOOP]] ], !is_base_value !0
92 ; CHECK-NEXT: [[CURRENT:%.*]] = phi ptr addrspace(1) [ [[OBJ]], [[ENTRY]] ], [ [[NEXT_RELOCATED:%.*]], [[LOOP]] ]
93 ; CHECK-NEXT: [[EXTRA:%.*]] = phi ptr addrspace(1) [ [[OBJ]], [[ENTRY]] ], [ [[EXTRA2_RELOCATED:%.*]], [[LOOP]] ]
94 ; CHECK-NEXT: [[NEXTA:%.*]] = getelementptr i64, ptr addrspace(1) [[CURRENT]], i32 1
95 ; CHECK-NEXT: [[NEXT_BASE:%.*]] = select i1 [[CND:%.*]], ptr addrspace(1) [[CURRENT_BASE]], ptr addrspace(1) [[DOT0]], !is_base_value !0
96 ; CHECK-NEXT: [[NEXT:%.*]] = select i1 [[CND]], ptr addrspace(1) [[NEXTA]], ptr addrspace(1) [[DOT0]]
97 ; CHECK-NEXT: [[EXTRA2_BASE:%.*]] = select i1 [[CND]], ptr addrspace(1) [[CURRENT_BASE]], ptr addrspace(1) [[DOT0]], !is_base_value !0
98 ; CHECK-NEXT: [[EXTRA2:%.*]] = select i1 [[CND]], ptr addrspace(1) [[NEXTA]], ptr addrspace(1) [[DOT0]]
99 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @foo, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0), "gc-live"(ptr addrspace(1) [[NEXT_BASE]], ptr addrspace(1) [[NEXT]], ptr addrspace(1) [[EXTRA2]], ptr addrspace(1) [[DOT0]], ptr addrspace(1) [[EXTRA2_BASE]]) ]
100 ; CHECK-NEXT: [[NEXT_BASE_RELOCATED]] = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 0, i32 0)
101 ; CHECK-NEXT: [[NEXT_RELOCATED]] = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 0, i32 1)
102 ; CHECK-NEXT: [[EXTRA2_RELOCATED]] = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 4, i32 2)
103 ; CHECK-NEXT: [[BASE_ARG2_RELOCATED]] = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 3, i32 3)
104 ; CHECK-NEXT: [[EXTRA2_BASE_RELOCATED:%.*]] = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 4, i32 4)
105 ; CHECK-NEXT: br label [[LOOP]]
108 %obj = getelementptr i64, ptr addrspace(1) %base_obj, i32 1
111 ; Given the two selects are equivelent, so are their base phis - ideally,
112 ; we'd have commoned these, but that's a missed optimization, not correctness.
113 ;; Both 'next' and 'extra2' are live across the backedge safepoint...
116 %current = phi ptr addrspace(1) [ %obj, %entry ], [ %next, %loop ]
117 %extra = phi ptr addrspace(1) [ %obj, %entry ], [ %extra2, %loop ]
118 %nexta = getelementptr i64, ptr addrspace(1) %current, i32 1
119 %next = select i1 %cnd, ptr addrspace(1) %nexta, ptr addrspace(1) %base_arg2
120 %extra2 = select i1 %cnd, ptr addrspace(1) %nexta, ptr addrspace(1) %base_arg2
121 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
125 define ptr addrspace(1) @test3(i1 %cnd, ptr addrspace(1) %obj, ptr addrspace(1) %obj2) gc "statepoint-example" {
126 ; CHECK-LABEL: @test3(
128 ; CHECK-NEXT: br i1 [[CND:%.*]], label [[MERGE:%.*]], label [[TAKEN:%.*]]
130 ; CHECK-NEXT: br label [[MERGE]]
132 ; CHECK-NEXT: [[BDV:%.*]] = phi ptr addrspace(1) [ [[OBJ:%.*]], [[ENTRY:%.*]] ], [ [[OBJ2:%.*]], [[TAKEN]] ]
133 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @foo, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0), "gc-live"(ptr addrspace(1) [[BDV]]) ]
134 ; CHECK-NEXT: [[BDV_RELOCATED:%.*]] = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 0, i32 0)
135 ; CHECK-NEXT: ret ptr addrspace(1) [[BDV_RELOCATED]]
138 br i1 %cnd, label %merge, label %taken
144 %bdv = phi ptr addrspace(1) [ %obj, %entry ], [ %obj2, %taken ]
145 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
146 ret ptr addrspace(1) %bdv
149 define ptr addrspace(1) @test4(i1 %cnd, ptr addrspace(1) %obj, ptr addrspace(1) %obj2) gc "statepoint-example" {
150 ; CHECK-LABEL: @test4(
152 ; CHECK-NEXT: br i1 [[CND:%.*]], label [[MERGE:%.*]], label [[TAKEN:%.*]]
154 ; CHECK-NEXT: br label [[MERGE]]
156 ; CHECK-NEXT: [[BDV:%.*]] = phi ptr addrspace(1) [ [[OBJ:%.*]], [[ENTRY:%.*]] ], [ [[OBJ]], [[TAKEN]] ]
157 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @foo, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0), "gc-live"(ptr addrspace(1) [[BDV]]) ]
158 ; CHECK-NEXT: [[BDV_RELOCATED:%.*]] = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 0, i32 0)
159 ; CHECK-NEXT: ret ptr addrspace(1) [[BDV_RELOCATED]]
162 br i1 %cnd, label %merge, label %taken
168 %bdv = phi ptr addrspace(1) [ %obj, %entry ], [ %obj, %taken ]
169 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
170 ret ptr addrspace(1) %bdv
173 define ptr addrspace(1) @test5(i1 %cnd, ptr addrspace(1) %obj, ptr addrspace(1) %obj2) gc "statepoint-example" {
174 ; CHECK-LABEL: @test5(
176 ; CHECK-NEXT: br label [[MERGE:%.*]]
178 ; CHECK-NEXT: [[BDV:%.*]] = phi ptr addrspace(1) [ [[OBJ:%.*]], [[ENTRY:%.*]] ], [ [[OBJ2:%.*]], [[MERGE]] ]
179 ; CHECK-NEXT: br i1 [[CND:%.*]], label [[MERGE]], label [[NEXT:%.*]]
181 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @foo, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0), "gc-live"(ptr addrspace(1) [[BDV]]) ]
182 ; CHECK-NEXT: [[BDV_RELOCATED:%.*]] = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 0, i32 0)
183 ; CHECK-NEXT: ret ptr addrspace(1) [[BDV_RELOCATED]]
189 %bdv = phi ptr addrspace(1) [ %obj, %entry ], [ %obj2, %merge ]
190 br i1 %cnd, label %merge, label %next
193 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
194 ret ptr addrspace(1) %bdv
197 ; We know from the deopt use that %bdv must be a base value, and as
198 ; result can avoid materializing the extra copy of the BDV phi node.
199 ; (Even without a general forward analysis)
200 define ptr addrspace(1) @test6(i1 %cnd, ptr addrspace(1) %obj, ptr addrspace(1) %obj2) gc "statepoint-example" {
201 ; CHECK-LABEL: @test6(
203 ; CHECK-NEXT: br label [[MERGE:%.*]]
205 ; CHECK-NEXT: [[BDV:%.*]] = phi ptr addrspace(1) [ [[OBJ:%.*]], [[ENTRY:%.*]] ], [ [[OBJ2:%.*]], [[MERGE]] ]
206 ; CHECK-NEXT: br i1 [[CND:%.*]], label [[MERGE]], label [[NEXT:%.*]]
208 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(void ()) @foo, i32 0, i32 0, i32 0, i32 0) [ "deopt"(ptr addrspace(1) [[BDV]]), "gc-live"(ptr addrspace(1) [[BDV]]) ]
209 ; CHECK-NEXT: [[BDV_RELOCATED:%.*]] = call coldcc ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[STATEPOINT_TOKEN]], i32 0, i32 0)
210 ; CHECK-NEXT: ret ptr addrspace(1) [[BDV_RELOCATED]]
216 %bdv = phi ptr addrspace(1) [ %obj, %entry ], [ %obj2, %merge ]
217 br i1 %cnd, label %merge, label %next
220 call void @foo() [ "deopt"(ptr addrspace(1) %bdv) ]
221 ret ptr addrspace(1) %bdv
226 define void @test7() gc "statepoint-example" {
227 ; CHECK-LABEL: @test7(
229 ; CHECK-NEXT: [[GETELEMENTPTR:%.*]] = getelementptr i8, <2 x ptr addrspace(1)> zeroinitializer, <2 x i64> <i64 888, i64 908>
230 ; CHECK-NEXT: [[SHUFFLEVECTOR_BASE:%.*]] = shufflevector <2 x ptr addrspace(1)> zeroinitializer, <2 x ptr addrspace(1)> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3>, !is_base_value !0
231 ; CHECK-NEXT: [[SHUFFLEVECTOR:%.*]] = shufflevector <2 x ptr addrspace(1)> [[GETELEMENTPTR]], <2 x ptr addrspace(1)> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
232 ; CHECK-NEXT: [[SHUFFLEVECTOR1_BASE:%.*]] = shufflevector <2 x ptr addrspace(1)> zeroinitializer, <2 x ptr addrspace(1)> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3>, !is_base_value !0
233 ; CHECK-NEXT: [[SHUFFLEVECTOR1:%.*]] = shufflevector <2 x ptr addrspace(1)> [[GETELEMENTPTR]], <2 x ptr addrspace(1)> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
234 ; CHECK-NEXT: [[SELECT_BASE:%.*]] = select i1 false, <4 x ptr addrspace(1)> [[SHUFFLEVECTOR1_BASE]], <4 x ptr addrspace(1)> [[SHUFFLEVECTOR_BASE]], !is_base_value !0
235 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 false, <4 x ptr addrspace(1)> [[SHUFFLEVECTOR1]], <4 x ptr addrspace(1)> [[SHUFFLEVECTOR]]
236 ; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(i32 ()) @snork, i32 0, i32 0, i32 0, i32 0) [ "gc-live"(<4 x ptr addrspace(1)> [[SELECT]], <4 x ptr addrspace(1)> [[SELECT_BASE]]) ]
237 ; CHECK-NEXT: [[SELECT_RELOCATED:%.*]] = call coldcc <4 x ptr addrspace(1)> @llvm.experimental.gc.relocate.v4p1(token [[STATEPOINT_TOKEN]], i32 1, i32 0)
238 ; CHECK-NEXT: [[SELECT_BASE_RELOCATED:%.*]] = call coldcc <4 x ptr addrspace(1)> @llvm.experimental.gc.relocate.v4p1(token [[STATEPOINT_TOKEN]], i32 1, i32 1)
239 ; CHECK-NEXT: [[EXTRACTELEMENT:%.*]] = extractelement <4 x ptr addrspace(1)> [[SELECT_RELOCATED]], i32 0
240 ; CHECK-NEXT: ret void
243 %getelementptr = getelementptr i8, <2 x ptr addrspace(1)> zeroinitializer, <2 x i64> <i64 888, i64 908>
244 %shufflevector = shufflevector <2 x ptr addrspace(1)> %getelementptr, <2 x ptr addrspace(1)> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
245 %shufflevector1 = shufflevector <2 x ptr addrspace(1)> %getelementptr, <2 x ptr addrspace(1)> zeroinitializer, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
246 %select = select i1 false, <4 x ptr addrspace(1)> %shufflevector1, <4 x ptr addrspace(1)> %shufflevector
247 %call = call i32 @snork()
248 %extractelement = extractelement <4 x ptr addrspace(1)> %select, i32 0