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