1 ; This is a collection of really basic tests for gc.statepoint rewriting.
2 ; RUN: opt < %s -passes=rewrite-statepoints-for-gc -spp-rematerialization-threshold=0 -S | FileCheck %s
4 ; Trivial relocation over a single call
8 define ptr addrspace(1) @test1(ptr addrspace(1) %obj) gc "statepoint-example" {
12 ; CHECK-NEXT: gc.statepoint
13 ; CHECK-NEXT: %obj.relocated = call coldcc ptr 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 ptr addrspace(1) %obj
19 define ptr addrspace(1) @test2(ptr addrspace(1) %obj) gc "statepoint-example" {
23 ; CHECK-NEXT: gc.statepoint
24 ; CHECK-NEXT: %obj.relocated = call coldcc ptr addrspace(1)
25 ; CHECK-NEXT: gc.statepoint
26 ; CHECK-NEXT: %obj.relocated2 = call coldcc ptr 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 ptr addrspace(1) %obj
33 define i8 @test3(ptr addrspace(1) %obj) gc "statepoint-example" {
36 ; CHECK-NEXT: getelementptr
37 ; CHECK-NEXT: gc.statepoint
38 ; CHECK-NEXT: %obj.relocated = call coldcc ptr addrspace(1)
39 ; CHECK-NEXT: %derived.relocated = call coldcc ptr addrspace(1)
40 ; CHECK-NEXT: load i8, ptr addrspace(1) %derived.relocated
41 ; CHECK-NEXT: load i8, ptr 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, ptr addrspace(1) %obj, i64 10
45 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
46 %a = load i8, ptr addrspace(1) %derived
47 %b = load i8, ptr addrspace(1) %obj
52 define ptr addrspace(1) @test4(i1 %cmp, ptr addrspace(1) %obj) gc "statepoint-example" {
54 br i1 %cmp, label %taken, label %untaken
56 taken: ; preds = %entry
58 ; CHECK-NEXT: gc.statepoint
59 ; CHECK-NEXT: %obj.relocated = call coldcc ptr addrspace(1)
60 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
63 untaken: ; preds = %entry
64 ; CHECK-LABEL: untaken:
65 ; CHECK-NEXT: gc.statepoint
66 ; CHECK-NEXT: %obj.relocated2 = call coldcc ptr addrspace(1)
67 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
70 merge: ; preds = %untaken, %taken
72 ; CHECK-NEXT: %.0 = phi ptr addrspace(1) [ %obj.relocated, %taken ], [ %obj.relocated2, %untaken ]
73 ; CHECK-NEXT: ret ptr addrspace(1) %.0
74 ; When run over a function which doesn't opt in, should do nothing!
75 ret ptr addrspace(1) %obj
78 define ptr addrspace(1) @test5(ptr addrspace(1) %obj) gc "ocaml" {
82 ; CHECK-NEXT: gc.statepoint
83 ; CHECK-NOT: %obj.relocated = call coldcc ptr addrspace(1)
84 %0 = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, 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)]
85 ret ptr addrspace(1) %obj
88 declare token @llvm.experimental.gc.statepoint.p0(i64, i32, ptr, i32, i32, ...)