blob: 36ede468d49a4e14aef6ea0cf98063acd8026a5d [file] [log] [blame]
Philip Reamesa5aeaf42015-02-28 00:20:48 +00001; RUN: opt %s -rewrite-statepoints-for-gc -S 2>&1 | FileCheck %s
2
3declare i64 addrspace(1)* @generate_obj()
4declare void @use_obj(i64 addrspace(1)*)
5
6; The rewriting needs to make %obj loop variant by inserting a phi
7; of the original value and it's relocation.
8define void @def_use_safepoint() gc "statepoint-example" {
9; CHECK-LABEL: def_use_safepoint
10entry:
11 %obj = call i64 addrspace(1)* @generate_obj()
12 br label %loop
13
14loop:
15; CHECK: phi i64 addrspace(1)*
Sanjoy Das89c54912015-05-11 18:49:34 +000016; CHECK-DAG: [ %obj.relocated.casted, %loop ]
Philip Reamesa5aeaf42015-02-28 00:20:48 +000017; CHECK-DAG: [ %obj, %entry ]
18 call void @use_obj(i64 addrspace(1)* %obj)
Sanjoy Dasa1d39ba2015-05-12 23:52:24 +000019 %safepoint_token = call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
Philip Reamesa5aeaf42015-02-28 00:20:48 +000020 br label %loop
21}
22
23declare void @do_safepoint()
24
25declare void @parse_point(i64 addrspace(1)*)
26
27define i64 addrspace(1)* @test1(i32 %caller, i8 addrspace(1)* %a, i8 addrspace(1)* %b, i32 %unknown) gc "statepoint-example" {
28; CHECK-LABEL: test1
29 entry:
30 br i1 undef, label %left, label %right
31
32 left:
33 %a.cast = bitcast i8 addrspace(1)* %a to i64 addrspace(1)*
34; CHECK: left:
35; CHECK-NEXT: %a.cast = bitcast i8 addrspace(1)* %a to i64 addrspace(1)*
36; CHECK-NEXT: [[CAST_L:%.*]] = bitcast i8 addrspace(1)* %a to i64 addrspace(1)*
37
38; Our safepoint placement pass calls removeUnreachableBlocks, which does a bunch
39; of simplifications to branch instructions. This bug is visible only when
40; there are multiple branches into the same block from the same predecessor, and
41; the following ceremony is to make that artefact survive a call to
42; removeUnreachableBlocks. As an example, "br i1 undef, label %merge, label %merge"
43; will get simplified to "br label %merge" by removeUnreachableBlocks.
44 switch i32 %unknown, label %right [ i32 0, label %merge
45 i32 1, label %merge
46 i32 5, label %merge
47 i32 3, label %right ]
48
49 right:
50 %b.cast = bitcast i8 addrspace(1)* %b to i64 addrspace(1)*
51 br label %merge
52; CHECK: right:
53; CHECK-NEXT: %b.cast = bitcast i8 addrspace(1)* %b to i64 addrspace(1)*
54; CHECK-NEXT: [[CAST_R:%.*]] = bitcast i8 addrspace(1)* %b to i64 addrspace(1)*
55
56 merge:
57; CHECK: merge:
Philip Reamesfa2c6302015-07-24 19:01:39 +000058; CHECK-NEXT: %value.base = phi i64 addrspace(1)* [ [[CAST_L]], %left ], [ [[CAST_L]], %left ], [ [[CAST_L]], %left ], [ [[CAST_R]], %right ], !is_base_value !0
Philip Reamesa5aeaf42015-02-28 00:20:48 +000059 %value = phi i64 addrspace(1)* [ %a.cast, %left], [ %a.cast, %left], [ %a.cast, %left], [ %b.cast, %right]
Sanjoy Dasa1d39ba2015-05-12 23:52:24 +000060 %safepoint_token = call i32 (i64, i32, void (i64 addrspace(1)*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidp1i64f(i64 0, i32 0, void (i64 addrspace(1)*)* @parse_point, i32 1, i32 0, i64 addrspace(1)* %value, i32 0, i32 5, i32 0, i32 0, i32 0, i32 0, i32 0)
Philip Reamesa5aeaf42015-02-28 00:20:48 +000061
62 ret i64 addrspace(1)* %value
63}
64
65;; The purpose of this test is to ensure that when two live values share a
66;; base defining value with inherent conflicts, we end up with a *single*
67;; base phi/select per such node. This is testing an optimization, not a
68;; fundemental correctness criteria
69define void @test2(i1 %cnd, i64 addrspace(1)* %base_obj, i64 addrspace(1)* %base_arg2) gc "statepoint-example" {
70; CHECK-LABEL: @test2
71entry:
72 %obj = getelementptr i64, i64 addrspace(1)* %base_obj, i32 1
73 br label %loop
74
75loop: ; preds = %loop, %entry
76; CHECK-LABEL: loop
Philip Reamesfa2c6302015-07-24 19:01:39 +000077; CHECK: %current.base = phi i64 addrspace(1)*
Philip Reamesa5aeaf42015-02-28 00:20:48 +000078; CHECK-DAG: [ %base_obj, %entry ]
Philip Reamesdf1ef082015-04-10 22:53:14 +000079; Given the two selects are equivelent, so are their base phis - ideally,
80; we'd have commoned these, but that's a missed optimization, not correctness.
Philip Reamesfa2c6302015-07-24 19:01:39 +000081; CHECK-DAG: [ [[DISCARD:%.*.base.relocated.casted]], %loop ]
82; CHECK-NOT: extra.base
Philip Reamesa5aeaf42015-02-28 00:20:48 +000083; CHECK: next = select
Philip Reamesfa2c6302015-07-24 19:01:39 +000084; CHECK: extra2.base = select
Philip Reamesa5aeaf42015-02-28 00:20:48 +000085; CHECK: extra2 = select
Philip Reamesa5aeaf42015-02-28 00:20:48 +000086; CHECK: statepoint
87;; Both 'next' and 'extra2' are live across the backedge safepoint...
88 %current = phi i64 addrspace(1)* [ %obj, %entry ], [ %next, %loop ]
89 %extra = phi i64 addrspace(1)* [ %obj, %entry ], [ %extra2, %loop ]
90 %nexta = getelementptr i64, i64 addrspace(1)* %current, i32 1
91 %next = select i1 %cnd, i64 addrspace(1)* %nexta, i64 addrspace(1)* %base_arg2
92 %extra2 = select i1 %cnd, i64 addrspace(1)* %nexta, i64 addrspace(1)* %base_arg2
Sanjoy Dasa1d39ba2015-05-12 23:52:24 +000093 %safepoint_token = call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
Philip Reamesa5aeaf42015-02-28 00:20:48 +000094 br label %loop
95}
96
Philip Reamesabcdc5e2015-08-27 01:02:28 +000097define i64 addrspace(1)* @test3(i1 %cnd, i64 addrspace(1)* %obj,
98 i64 addrspace(1)* %obj2)
99 gc "statepoint-example" {
100; CHECK-LABEL: @test3
101entry:
102 br i1 %cnd, label %merge, label %taken
103taken:
104 br label %merge
105merge:
106; CHECK-LABEL: merge:
107; CHECK-NEXT: %bdv = phi
108; CHECK-NEXT: gc.statepoint
109 %bdv = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj2, %taken ]
110 %safepoint_token = call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
111 ret i64 addrspace(1)* %bdv
112}
113
Philip Reamesdab35f32015-09-02 21:11:44 +0000114define i64 addrspace(1)* @test4(i1 %cnd, i64 addrspace(1)* %obj,
115 i64 addrspace(1)* %obj2)
116 gc "statepoint-example" {
117; CHECK-LABEL: @test4
118entry:
119 br i1 %cnd, label %merge, label %taken
120taken:
121 br label %merge
122merge:
123; CHECK-LABEL: merge:
124; CHECK-NEXT: %bdv = phi
125; CHECK-NEXT: gc.statepoint
126 %bdv = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj, %taken ]
127 %safepoint_token = call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
128 ret i64 addrspace(1)* %bdv
129}
130
131define i64 addrspace(1)* @test5(i1 %cnd, i64 addrspace(1)* %obj,
132 i64 addrspace(1)* %obj2)
133 gc "statepoint-example" {
134; CHECK-LABEL: @test5
135entry:
136 br label %merge
137merge:
138; CHECK-LABEL: merge:
139; CHECK-NEXT: %bdv = phi
140; CHECK-NEXT: br i1
141 %bdv = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj2, %merge ]
142 br i1 %cnd, label %merge, label %next
143next:
144 %safepoint_token = call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
145 ret i64 addrspace(1)* %bdv
146}
147
Philip Reamesabcdc5e2015-08-27 01:02:28 +0000148
Philip Reamesa5aeaf42015-02-28 00:20:48 +0000149declare void @foo()
Sanjoy Dasa1d39ba2015-05-12 23:52:24 +0000150declare i32 @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
Philip Reamesfa2c6302015-07-24 19:01:39 +0000151declare i32 @llvm.experimental.gc.statepoint.p0f_isVoidp1i64f(i64, i32, void (i64 addrspace(1)*)*, i32, i32, ...)