1 ; RUN: opt %s -rewrite-statepoints-for-gc -S 2>&1 | FileCheck %s
3 declare i64 addrspace(1)* @generate_obj()
4 declare void @use_obj(i64 addrspace(1)*)
6 ; The rewriting needs to make %obj loop variant by inserting a phi
7 ; of the original value and it's relocation.
8 define void @def_use_safepoint() gc "statepoint-example" {
9 ; CHECK-LABEL: def_use_safepoint
11 %obj = call i64 addrspace(1)* @generate_obj()
15 ; CHECK: phi i64 addrspace(1)*
16 ; CHECK-DAG: [ %obj.relocated, %loop ]
17 ; CHECK-DAG: [ %obj, %entry ]
18 call void @use_obj(i64 addrspace(1)* %obj)
19 %safepoint_token = call i32 (void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
23 declare void @do_safepoint()
25 declare void @parse_point(i64 addrspace(1)*)
27 define i64 addrspace(1)* @test1(i32 %caller, i8 addrspace(1)* %a, i8 addrspace(1)* %b, i32 %unknown) gc "statepoint-example" {
30 br i1 undef, label %left, label %right
33 %a.cast = bitcast i8 addrspace(1)* %a to i64 addrspace(1)*
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)*
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
50 %b.cast = bitcast i8 addrspace(1)* %b to i64 addrspace(1)*
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)*
58 ; CHECK-NEXT: %base_phi = phi i64 addrspace(1)* [ [[CAST_L]], %left ], [ [[CAST_L]], %left ], [ [[CAST_L]], %left ], [ [[CAST_R]], %right ], !is_base_value !0
59 %value = phi i64 addrspace(1)* [ %a.cast, %left], [ %a.cast, %left], [ %a.cast, %left], [ %b.cast, %right]
60 %safepoint_token = call i32 (void (i64 addrspace(1)*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidp1i64f(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)
62 ret i64 addrspace(1)* %value
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
69 define void @test2(i1 %cnd, i64 addrspace(1)* %base_obj, i64 addrspace(1)* %base_arg2) gc "statepoint-example" {
72 %obj = getelementptr i64, i64 addrspace(1)* %base_obj, i32 1
75 loop: ; preds = %loop, %entry
77 ; CHECK: %base_phi = phi i64 addrspace(1)*
78 ; CHECK-DAG: [ %base_obj, %entry ]
79 ; 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.
81 ; CHECK-DAG: [ [[DISCARD:%base_select.*.relocated]], %loop ]
82 ; CHECK-NOT: base_phi2
83 ; CHECK: next = select
85 ; CHECK: extra2 = select
88 ;; Both 'next' and 'extra2' are live across the backedge safepoint...
89 %current = phi i64 addrspace(1)* [ %obj, %entry ], [ %next, %loop ]
90 %extra = phi i64 addrspace(1)* [ %obj, %entry ], [ %extra2, %loop ]
91 %nexta = getelementptr i64, i64 addrspace(1)* %current, i32 1
92 %next = select i1 %cnd, i64 addrspace(1)* %nexta, i64 addrspace(1)* %base_arg2
93 %extra2 = select i1 %cnd, i64 addrspace(1)* %nexta, i64 addrspace(1)* %base_arg2
94 %safepoint_token = call i32 (void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()* @foo, i32 0, i32 0, i32 0, i32 5, i32 0, i32 -1, i32 0, i32 0, i32 0)
99 declare i32 @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()*, i32, i32, ...)
100 declare i32 @llvm.experimental.gc.statepoint.p0f_isVoidp1i64f(void (i64 addrspace(1)*)*, i32, i32, ...)