[gc.statepoint] Change gc.statepoint intrinsic's return type to token type instead...
[oota-llvm.git] / test / Transforms / RewriteStatepointsForGC / deopt-bundles / basics.ll
1 ; This is a collection of really basic tests for gc.statepoint rewriting.
2 ; RUN:  opt %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -spp-rematerialization-threshold=0 -S | FileCheck %s
3
4 ; Trivial relocation over a single call
5
6 declare void @foo()
7
8 define i8 addrspace(1)* @test1(i8 addrspace(1)* %obj) gc "statepoint-example" {
9 ; CHECK-LABEL: @test1
10 entry:
11 ; CHECK-LABEL: entry:
12 ; CHECK-NEXT: gc.statepoint
13 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
14 ; Two safepoints in a row (i.e. consistent liveness)
15   call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
16   ret i8 addrspace(1)* %obj
17 }
18
19 define i8 addrspace(1)* @test2(i8 addrspace(1)* %obj) gc "statepoint-example" {
20 ; CHECK-LABEL: @test2
21 entry:
22 ; CHECK-LABEL: entry:
23 ; CHECK-NEXT: gc.statepoint
24 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
25 ; CHECK-NEXT: gc.statepoint
26 ; CHECK-NEXT: %obj.relocated2 = call coldcc i8 addrspace(1)*
27 ; A simple derived pointer
28   call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
29   call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
30   ret i8 addrspace(1)* %obj
31 }
32
33 define i8 @test3(i8 addrspace(1)* %obj) gc "statepoint-example" {
34 entry:
35 ; CHECK-LABEL: entry:
36 ; CHECK-NEXT: getelementptr
37 ; CHECK-NEXT: gc.statepoint
38 ; CHECK-NEXT: %derived.relocated = call coldcc i8 addrspace(1)*
39 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
40 ; CHECK-NEXT: load i8, i8 addrspace(1)* %derived.relocated
41 ; CHECK-NEXT: load i8, i8 addrspace(1)* %obj.relocated
42 ; Tests to make sure we visit both the taken and untaken predeccessor 
43 ; of merge.  This was a bug in the dataflow liveness at one point.
44   %derived = getelementptr i8, i8 addrspace(1)* %obj, i64 10
45   call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
46   %a = load i8, i8 addrspace(1)* %derived
47   %b = load i8, i8 addrspace(1)* %obj
48   %c = sub i8 %a, %b
49   ret i8 %c
50 }
51
52 define i8 addrspace(1)* @test4(i1 %cmp, i8 addrspace(1)* %obj) gc "statepoint-example" {
53 entry:
54   br i1 %cmp, label %taken, label %untaken
55
56 taken:                                            ; preds = %entry
57 ; CHECK-LABEL: taken:
58 ; CHECK-NEXT: gc.statepoint
59 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
60   call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
61   br label %merge
62
63 untaken:                                          ; preds = %entry
64 ; CHECK-LABEL: untaken:
65 ; CHECK-NEXT: gc.statepoint
66 ; CHECK-NEXT: %obj.relocated2 = call coldcc i8 addrspace(1)*
67   call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
68   br label %merge
69
70 merge:                                            ; preds = %untaken, %taken
71 ; CHECK-LABEL: merge:
72 ; CHECK-NEXT: %.0 = phi i8 addrspace(1)* [ %obj.relocated, %taken ], [ %obj.relocated2, %untaken ]
73 ; CHECK-NEXT: ret i8 addrspace(1)* %.0
74 ; When run over a function which doesn't opt in, should do nothing!
75   ret i8 addrspace(1)* %obj
76 }
77
78 define i8 addrspace(1)* @test5(i8 addrspace(1)* %obj) gc "ocaml" {
79 ; CHECK-LABEL: @test5
80 entry:
81 ; CHECK-LABEL: entry:
82 ; CHECK-NEXT: gc.statepoint
83 ; CHECK-NOT: %obj.relocated = call coldcc i8 addrspace(1)*
84   %0 = call token (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)
85   ret i8 addrspace(1)* %obj
86 }
87
88 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)