blob: e65897e7a89991fcf6744e89d21cabf00578194c [file] [log] [blame]
Sanjoy Das04071082016-01-29 00:28:57 +00001; RUN: opt < %s -rewrite-statepoints-for-gc -S 2>&1 | FileCheck %s
Philip Reamesa5aeaf42015-02-28 00:20:48 +00002
3; The rewriting needs to make %obj loop variant by inserting a phi
4; of the original value and it's relocation.
Sanjoy Das04071082016-01-29 00:28:57 +00005
6declare i64 addrspace(1)* @generate_obj() "gc-leaf-function"
7
8declare void @use_obj(i64 addrspace(1)*) "gc-leaf-function"
9
Philip Reamesa5aeaf42015-02-28 00:20:48 +000010define void @def_use_safepoint() gc "statepoint-example" {
11; CHECK-LABEL: def_use_safepoint
Sanjoy Das04071082016-01-29 00:28:57 +000012; CHECK: phi i64 addrspace(1)*
13; CHECK-DAG: [ %obj.relocated.casted, %loop ]
14; CHECK-DAG: [ %obj, %entry ]
Philip Reamesa5aeaf42015-02-28 00:20:48 +000015entry:
16 %obj = call i64 addrspace(1)* @generate_obj()
17 br label %loop
18
Sanjoy Das04071082016-01-29 00:28:57 +000019loop: ; preds = %loop, %entry
Philip Reamesa5aeaf42015-02-28 00:20:48 +000020 call void @use_obj(i64 addrspace(1)* %obj)
Sanjoy Das04071082016-01-29 00:28:57 +000021 call void @do_safepoint() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
Philip Reamesa5aeaf42015-02-28 00:20:48 +000022 br label %loop
23}
24
25declare void @do_safepoint()
26
27declare void @parse_point(i64 addrspace(1)*)
28
29define i64 addrspace(1)* @test1(i32 %caller, i8 addrspace(1)* %a, i8 addrspace(1)* %b, i32 %unknown) gc "statepoint-example" {
30; CHECK-LABEL: test1
Sanjoy Das04071082016-01-29 00:28:57 +000031entry:
Philip Reamesa5aeaf42015-02-28 00:20:48 +000032 br i1 undef, label %left, label %right
33
Sanjoy Das04071082016-01-29 00:28:57 +000034left: ; preds = %entry
Philip Reamesa5aeaf42015-02-28 00:20:48 +000035; CHECK: left:
36; CHECK-NEXT: %a.cast = bitcast i8 addrspace(1)* %a to i64 addrspace(1)*
37; CHECK-NEXT: [[CAST_L:%.*]] = bitcast i8 addrspace(1)* %a to i64 addrspace(1)*
Philip Reamesa5aeaf42015-02-28 00:20:48 +000038; 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.
Sanjoy Das04071082016-01-29 00:28:57 +000044 %a.cast = bitcast i8 addrspace(1)* %a to i64 addrspace(1)*
45 switch i32 %unknown, label %right [
46 i32 0, label %merge
47 i32 1, label %merge
48 i32 5, label %merge
49 i32 3, label %right
50 ]
Philip Reamesa5aeaf42015-02-28 00:20:48 +000051
Sanjoy Das04071082016-01-29 00:28:57 +000052right: ; preds = %left, %left, %entry
Philip Reamesa5aeaf42015-02-28 00:20:48 +000053; CHECK: right:
54; CHECK-NEXT: %b.cast = bitcast i8 addrspace(1)* %b to i64 addrspace(1)*
55; CHECK-NEXT: [[CAST_R:%.*]] = bitcast i8 addrspace(1)* %b to i64 addrspace(1)*
Sanjoy Das04071082016-01-29 00:28:57 +000056 %b.cast = bitcast i8 addrspace(1)* %b to i64 addrspace(1)*
57 br label %merge
Philip Reamesa5aeaf42015-02-28 00:20:48 +000058
Sanjoy Das04071082016-01-29 00:28:57 +000059merge: ; preds = %right, %left, %left, %left
Philip Reamesa5aeaf42015-02-28 00:20:48 +000060; CHECK: merge:
Philip Reamesfa2c6302015-07-24 19:01:39 +000061; CHECK-NEXT: %value.base = phi i64 addrspace(1)* [ [[CAST_L]], %left ], [ [[CAST_L]], %left ], [ [[CAST_L]], %left ], [ [[CAST_R]], %right ], !is_base_value !0
Sanjoy Das04071082016-01-29 00:28:57 +000062 %value = phi i64 addrspace(1)* [ %a.cast, %left ], [ %a.cast, %left ], [ %a.cast, %left ], [ %b.cast, %right ]
63 call void @parse_point(i64 addrspace(1)* %value) [ "deopt"(i32 0, i32 0, i32 0, i32 0, i32 0) ]
Philip Reamesa5aeaf42015-02-28 00:20:48 +000064 ret i64 addrspace(1)* %value
65}
66
67;; The purpose of this test is to ensure that when two live values share a
68;; base defining value with inherent conflicts, we end up with a *single*
69;; base phi/select per such node. This is testing an optimization, not a
70;; fundemental correctness criteria
Sanjoy Das04071082016-01-29 00:28:57 +000071define void @test2(i1 %cnd, i64 addrspace(1)* %base_obj, i64 addrspace(1)* %base_arg2) gc "statepoint-example" {
Philip Reamesa5aeaf42015-02-28 00:20:48 +000072; CHECK-LABEL: @test2
73entry:
74 %obj = getelementptr i64, i64 addrspace(1)* %base_obj, i32 1
75 br label %loop
Philip Reamesa5aeaf42015-02-28 00:20:48 +000076; 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 ]
Sanjoy Das04071082016-01-29 00:28:57 +000079
Philip Reamesdf1ef082015-04-10 22:53:14 +000080; Given the two selects are equivelent, so are their base phis - ideally,
81; we'd have commoned these, but that's a missed optimization, not correctness.
Philip Reamesfa2c6302015-07-24 19:01:39 +000082; CHECK-DAG: [ [[DISCARD:%.*.base.relocated.casted]], %loop ]
83; CHECK-NOT: extra.base
Philip Reames79fa9b72016-02-22 20:45:56 +000084; CHECK: next.base = select
Philip Reamesa5aeaf42015-02-28 00:20:48 +000085; CHECK: next = select
Philip Reamesfa2c6302015-07-24 19:01:39 +000086; CHECK: extra2.base = select
Philip Reamesa5aeaf42015-02-28 00:20:48 +000087; CHECK: extra2 = select
Philip Reamesa5aeaf42015-02-28 00:20:48 +000088; CHECK: statepoint
89;; Both 'next' and 'extra2' are live across the backedge safepoint...
Sanjoy Das04071082016-01-29 00:28:57 +000090
91loop: ; preds = %loop, %entry
Philip Reamesa5aeaf42015-02-28 00:20:48 +000092 %current = phi i64 addrspace(1)* [ %obj, %entry ], [ %next, %loop ]
93 %extra = phi i64 addrspace(1)* [ %obj, %entry ], [ %extra2, %loop ]
94 %nexta = getelementptr i64, i64 addrspace(1)* %current, i32 1
95 %next = select i1 %cnd, i64 addrspace(1)* %nexta, i64 addrspace(1)* %base_arg2
96 %extra2 = select i1 %cnd, i64 addrspace(1)* %nexta, i64 addrspace(1)* %base_arg2
Sanjoy Das04071082016-01-29 00:28:57 +000097 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
Philip Reamesa5aeaf42015-02-28 00:20:48 +000098 br label %loop
99}
100
Sanjoy Das04071082016-01-29 00:28:57 +0000101define i64 addrspace(1)* @test3(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" {
Philip Reamesabcdc5e2015-08-27 01:02:28 +0000102; CHECK-LABEL: @test3
103entry:
104 br i1 %cnd, label %merge, label %taken
Sanjoy Das04071082016-01-29 00:28:57 +0000105
106taken: ; preds = %entry
Philip Reamesabcdc5e2015-08-27 01:02:28 +0000107 br label %merge
Sanjoy Das04071082016-01-29 00:28:57 +0000108
109merge: ; preds = %taken, %entry
Philip Reamesabcdc5e2015-08-27 01:02:28 +0000110; CHECK-LABEL: merge:
Philip Reames79fa9b72016-02-22 20:45:56 +0000111; CHECK-NEXT: phi
112; CHECK-NEXT: phi
Philip Reamesabcdc5e2015-08-27 01:02:28 +0000113; CHECK-NEXT: gc.statepoint
114 %bdv = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj2, %taken ]
Sanjoy Das04071082016-01-29 00:28:57 +0000115 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
Philip Reamesabcdc5e2015-08-27 01:02:28 +0000116 ret i64 addrspace(1)* %bdv
117}
118
Sanjoy Das04071082016-01-29 00:28:57 +0000119define i64 addrspace(1)* @test4(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" {
Philip Reamesdab35f32015-09-02 21:11:44 +0000120; CHECK-LABEL: @test4
121entry:
122 br i1 %cnd, label %merge, label %taken
Sanjoy Das04071082016-01-29 00:28:57 +0000123
124taken: ; preds = %entry
Philip Reamesdab35f32015-09-02 21:11:44 +0000125 br label %merge
Sanjoy Das04071082016-01-29 00:28:57 +0000126
127merge: ; preds = %taken, %entry
Philip Reamesdab35f32015-09-02 21:11:44 +0000128; CHECK-LABEL: merge:
Philip Reames79fa9b72016-02-22 20:45:56 +0000129; CHECK-NEXT: phi
Philip Reamesdab35f32015-09-02 21:11:44 +0000130; CHECK-NEXT: gc.statepoint
131 %bdv = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj, %taken ]
Sanjoy Das04071082016-01-29 00:28:57 +0000132 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
Philip Reamesdab35f32015-09-02 21:11:44 +0000133 ret i64 addrspace(1)* %bdv
134}
135
Sanjoy Das04071082016-01-29 00:28:57 +0000136define i64 addrspace(1)* @test5(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" {
Philip Reamesdab35f32015-09-02 21:11:44 +0000137; CHECK-LABEL: @test5
138entry:
139 br label %merge
Sanjoy Das04071082016-01-29 00:28:57 +0000140
141merge: ; preds = %merge, %entry
Philip Reamesdab35f32015-09-02 21:11:44 +0000142; CHECK-LABEL: merge:
Philip Reames79fa9b72016-02-22 20:45:56 +0000143; CHECK-NEXT: phi
144; CHECK-NEXT: phi
Philip Reamesdab35f32015-09-02 21:11:44 +0000145; CHECK-NEXT: br i1
146 %bdv = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj2, %merge ]
147 br i1 %cnd, label %merge, label %next
Sanjoy Das04071082016-01-29 00:28:57 +0000148
149next: ; preds = %merge
150 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
Philip Reamesdab35f32015-09-02 21:11:44 +0000151 ret i64 addrspace(1)* %bdv
152}
153
Philip Reamesa5aeaf42015-02-28 00:20:48 +0000154declare void @foo()