Home | History | Annotate | Download | only in RewriteStatepointsForGC
      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 
      4 declare void @foo()
      5 
      6 ; Trivial relocation over a single call
      7 define i8 addrspace(1)* @test1(i8 addrspace(1)* %obj) gc "statepoint-example" {
      8 ; CHECK-LABEL: @test1
      9 ; CHECK-LABEL: entry:
     10 ; CHECK-NEXT: gc.statepoint
     11 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
     12 entry:
     13   call i32 (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)
     14   ret i8 addrspace(1)* %obj
     15 }
     16 
     17 ; Two safepoints in a row (i.e. consistent liveness)
     18 define i8 addrspace(1)* @test2(i8 addrspace(1)* %obj) gc "statepoint-example" {
     19 ; CHECK-LABEL: @test2
     20 ; CHECK-LABEL: entry:
     21 ; CHECK-NEXT: gc.statepoint
     22 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
     23 ; CHECK-NEXT: gc.statepoint
     24 ; CHECK-NEXT: %obj.relocated1 = call coldcc i8 addrspace(1)*
     25 entry:
     26   call i32 (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)
     27   call i32 (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)
     28   ret i8 addrspace(1)* %obj
     29 }
     30 
     31 ; A simple derived pointer
     32 define i8 @test3(i8 addrspace(1)* %obj) gc "statepoint-example" {
     33 ; CHECK-LABEL: entry:
     34 ; CHECK-NEXT: getelementptr
     35 ; CHECK-NEXT: gc.statepoint
     36 ; CHECK-NEXT: %derived.relocated = call coldcc i8 addrspace(1)*
     37 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
     38 ; CHECK-NEXT: load i8, i8 addrspace(1)* %derived.relocated
     39 ; CHECK-NEXT: load i8, i8 addrspace(1)* %obj.relocated
     40 entry:
     41   %derived = getelementptr i8, i8 addrspace(1)* %obj, i64 10
     42   call i32 (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)
     43 
     44   %a = load i8, i8 addrspace(1)* %derived
     45   %b = load i8, i8 addrspace(1)* %obj
     46   %c = sub i8 %a, %b
     47   ret i8 %c
     48 }
     49 
     50 ; Tests to make sure we visit both the taken and untaken predeccessor 
     51 ; of merge.  This was a bug in the dataflow liveness at one point.
     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:
     57 ; CHECK-LABEL: taken:
     58 ; CHECK-NEXT: gc.statepoint
     59 ; CHECK-NEXT: %obj.relocated = call coldcc i8 addrspace(1)*
     60   call i32 (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)
     61   br label %merge
     62 
     63 untaken:
     64 ; CHECK-LABEL: untaken:
     65 ; CHECK-NEXT: gc.statepoint
     66 ; CHECK-NEXT: %obj.relocated1 = call coldcc i8 addrspace(1)*
     67   call i32 (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)
     68   br label %merge
     69 
     70 merge:
     71 ; CHECK-LABEL: merge:
     72 ; CHECK-NEXT: %.0 = phi i8 addrspace(1)* [ %obj.relocated, %taken ], [ %obj.relocated1, %untaken ]
     73 ; CHECK-NEXT: ret i8 addrspace(1)* %.0
     74   ret i8 addrspace(1)* %obj
     75 }
     76 
     77 ; When run over a function which doesn't opt in, should do nothing!
     78 define i8 addrspace(1)* @test5(i8 addrspace(1)* %obj) gc "ocaml" {
     79 ; CHECK-LABEL: @test5
     80 ; CHECK-LABEL: entry:
     81 ; CHECK-NEXT: gc.statepoint
     82 ; CHECK-NOT: %obj.relocated = call coldcc i8 addrspace(1)*
     83 entry:
     84   call i32 (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 i32 @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)