1*9880d681SAndroid Build Coastguard Worker; RUN: opt -O3 -S < %s | FileCheck --check-prefix=CHECK-OPT %s 2*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s | FileCheck --check-prefix=CHECK-LLC %s 3*9880d681SAndroid Build Coastguard Worker; These tests are targetted at making sure we don't retain information 4*9880d681SAndroid Build Coastguard Worker; about memory which contains potential gc references across a statepoint. 5*9880d681SAndroid Build Coastguard Worker; They're carefully written to only outlaw forwarding of references. 6*9880d681SAndroid Build Coastguard Worker; Depending on the collector, forwarding non-reference fields or 7*9880d681SAndroid Build Coastguard Worker; constant null references may be perfectly legal. (If unimplemented.) 8*9880d681SAndroid Build Coastguard Worker; The general structure of these tests is: 9*9880d681SAndroid Build Coastguard Worker; - learn a fact about memory (via an assume) 10*9880d681SAndroid Build Coastguard Worker; - cross a statepoint 11*9880d681SAndroid Build Coastguard Worker; - check the same fact about memory (which we no longer know) 12*9880d681SAndroid Build Coastguard Worker 13*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-i64:64-f80:128-n8:16:32:64-S128" 14*9880d681SAndroid Build Coastguard Workertarget triple = "x86_64-pc-linux-gnu" 15*9880d681SAndroid Build Coastguard Worker 16*9880d681SAndroid Build Coastguard Worker; If not at a statepoint, we could forward known memory values 17*9880d681SAndroid Build Coastguard Worker; across this call. 18*9880d681SAndroid Build Coastguard Workerdeclare void @func() readonly 19*9880d681SAndroid Build Coastguard Worker 20*9880d681SAndroid Build Coastguard Worker;; Forwarding the value of a pointer load is invalid since it may have 21*9880d681SAndroid Build Coastguard Worker;; changed at the safepoint. Forwarding a non-gc pointer value would 22*9880d681SAndroid Build Coastguard Worker;; be valid, but is not currently implemented. 23*9880d681SAndroid Build Coastguard Workerdefine i1 @test_load_forward(i32 addrspace(1)* addrspace(1)* %p) gc "statepoint-example" { 24*9880d681SAndroid Build Coastguard Workerentry: 25*9880d681SAndroid Build Coastguard Worker %before = load i32 addrspace(1)*, i32 addrspace(1)* addrspace(1)* %p 26*9880d681SAndroid Build Coastguard Worker %cmp1 = call i1 @f(i32 addrspace(1)* %before) 27*9880d681SAndroid Build Coastguard Worker call void @llvm.assume(i1 %cmp1) 28*9880d681SAndroid Build Coastguard Worker %safepoint_token = tail call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @func, i32 0, i32 0, i32 0, i32 0, i32 addrspace(1)* addrspace(1)* %p) 29*9880d681SAndroid Build Coastguard Worker %pnew = call i32 addrspace(1)* addrspace(1)* @llvm.experimental.gc.relocate.p1p1i32(token %safepoint_token, i32 7, i32 7) 30*9880d681SAndroid Build Coastguard Worker %after = load i32 addrspace(1)*, i32 addrspace(1)* addrspace(1)* %pnew 31*9880d681SAndroid Build Coastguard Worker %cmp2 = call i1 @f(i32 addrspace(1)* %after) 32*9880d681SAndroid Build Coastguard Worker ret i1 %cmp2 33*9880d681SAndroid Build Coastguard Worker 34*9880d681SAndroid Build Coastguard Worker; CHECK-OPT-LABEL: test_load_forward 35*9880d681SAndroid Build Coastguard Worker; CHECK-OPT: ret i1 %cmp2 36*9880d681SAndroid Build Coastguard Worker; CHECK-LLC-LABEL: test_load_forward 37*9880d681SAndroid Build Coastguard Worker; CHECK-LLC: callq f 38*9880d681SAndroid Build Coastguard Worker} 39*9880d681SAndroid Build Coastguard Worker 40*9880d681SAndroid Build Coastguard Worker;; Same as above, but forwarding from a store 41*9880d681SAndroid Build Coastguard Workerdefine i1 @test_store_forward(i32 addrspace(1)* addrspace(1)* %p, 42*9880d681SAndroid Build Coastguard Worker i32 addrspace(1)* %v) gc "statepoint-example" { 43*9880d681SAndroid Build Coastguard Workerentry: 44*9880d681SAndroid Build Coastguard Worker %cmp1 = call i1 @f(i32 addrspace(1)* %v) 45*9880d681SAndroid Build Coastguard Worker call void @llvm.assume(i1 %cmp1) 46*9880d681SAndroid Build Coastguard Worker store i32 addrspace(1)* %v, i32 addrspace(1)* addrspace(1)* %p 47*9880d681SAndroid Build Coastguard Worker %safepoint_token = tail call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @func, i32 0, i32 0, i32 0, i32 0, i32 addrspace(1)* addrspace(1)* %p) 48*9880d681SAndroid Build Coastguard Worker %pnew = call i32 addrspace(1)* addrspace(1)* @llvm.experimental.gc.relocate.p1p1i32(token %safepoint_token, i32 7, i32 7) 49*9880d681SAndroid Build Coastguard Worker %after = load i32 addrspace(1)*, i32 addrspace(1)* addrspace(1)* %pnew 50*9880d681SAndroid Build Coastguard Worker %cmp2 = call i1 @f(i32 addrspace(1)* %after) 51*9880d681SAndroid Build Coastguard Worker ret i1 %cmp2 52*9880d681SAndroid Build Coastguard Worker 53*9880d681SAndroid Build Coastguard Worker; CHECK-OPT-LABEL: test_store_forward 54*9880d681SAndroid Build Coastguard Worker; CHECK-OPT: ret i1 %cmp2 55*9880d681SAndroid Build Coastguard Worker; CHECK-LLC-LABEL: test_store_forward 56*9880d681SAndroid Build Coastguard Worker; CHECK-LLC: callq f 57*9880d681SAndroid Build Coastguard Worker} 58*9880d681SAndroid Build Coastguard Worker 59*9880d681SAndroid Build Coastguard Worker; A predicate on the pointer which is not simply null, but whose value 60*9880d681SAndroid Build Coastguard Worker; would be known unchanged if the pointer value could be forwarded. 61*9880d681SAndroid Build Coastguard Worker; The implementation of such a function could inspect the integral value 62*9880d681SAndroid Build Coastguard Worker; of the pointer and is thus not safe to reuse after a statepoint. 63*9880d681SAndroid Build Coastguard Workerdeclare i1 @f(i32 addrspace(1)* %v) readnone 64*9880d681SAndroid Build Coastguard Worker 65*9880d681SAndroid Build Coastguard Worker; This is a variant of the test_load_forward test which is intended to 66*9880d681SAndroid Build Coastguard Worker; highlight the fact that a gc pointer can be stored in part of the heap 67*9880d681SAndroid Build Coastguard Worker; that is not itself GC managed. The GC may have an external mechanism 68*9880d681SAndroid Build Coastguard Worker; to know about and update that value at a safepoint. Note that the 69*9880d681SAndroid Build Coastguard Worker; statepoint does not provide the collector with this root. 70*9880d681SAndroid Build Coastguard Workerdefine i1 @test_load_forward_nongc_heap(i32 addrspace(1)** %p) gc "statepoint-example" { 71*9880d681SAndroid Build Coastguard Workerentry: 72*9880d681SAndroid Build Coastguard Worker %before = load i32 addrspace(1)*, i32 addrspace(1)** %p 73*9880d681SAndroid Build Coastguard Worker %cmp1 = call i1 @f(i32 addrspace(1)* %before) 74*9880d681SAndroid Build Coastguard Worker call void @llvm.assume(i1 %cmp1) 75*9880d681SAndroid Build Coastguard Worker call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @func, i32 0, i32 0, i32 0, i32 0) 76*9880d681SAndroid Build Coastguard Worker %after = load i32 addrspace(1)*, i32 addrspace(1)** %p 77*9880d681SAndroid Build Coastguard Worker %cmp2 = call i1 @f(i32 addrspace(1)* %after) 78*9880d681SAndroid Build Coastguard Worker ret i1 %cmp2 79*9880d681SAndroid Build Coastguard Worker 80*9880d681SAndroid Build Coastguard Worker; CHECK-OPT-LABEL: test_load_forward_nongc_heap 81*9880d681SAndroid Build Coastguard Worker; CHECK-OPT: ret i1 %cmp2 82*9880d681SAndroid Build Coastguard Worker; CHECK-LLC-LABEL: test_load_forward_nongc_heap 83*9880d681SAndroid Build Coastguard Worker; CHECK-LLC: callq f 84*9880d681SAndroid Build Coastguard Worker} 85*9880d681SAndroid Build Coastguard Worker 86*9880d681SAndroid Build Coastguard Worker;; Same as above, but forwarding from a store 87*9880d681SAndroid Build Coastguard Workerdefine i1 @test_store_forward_nongc_heap(i32 addrspace(1)** %p, 88*9880d681SAndroid Build Coastguard Worker i32 addrspace(1)* %v) gc "statepoint-example" { 89*9880d681SAndroid Build Coastguard Workerentry: 90*9880d681SAndroid Build Coastguard Worker %cmp1 = call i1 @f(i32 addrspace(1)* %v) 91*9880d681SAndroid Build Coastguard Worker call void @llvm.assume(i1 %cmp1) 92*9880d681SAndroid Build Coastguard Worker store i32 addrspace(1)* %v, i32 addrspace(1)** %p 93*9880d681SAndroid Build Coastguard Worker call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @func, i32 0, i32 0, i32 0, i32 0) 94*9880d681SAndroid Build Coastguard Worker %after = load i32 addrspace(1)*, i32 addrspace(1)** %p 95*9880d681SAndroid Build Coastguard Worker %cmp2 = call i1 @f(i32 addrspace(1)* %after) 96*9880d681SAndroid Build Coastguard Worker ret i1 %cmp2 97*9880d681SAndroid Build Coastguard Worker 98*9880d681SAndroid Build Coastguard Worker; CHECK-OPT-LABEL: test_store_forward_nongc_heap 99*9880d681SAndroid Build Coastguard Worker; CHECK-OPT: ret i1 %cmp2 100*9880d681SAndroid Build Coastguard Worker; CHECK-LLC-LABEL: test_store_forward_nongc_heap 101*9880d681SAndroid Build Coastguard Worker; CHECK-LLC: callq f 102*9880d681SAndroid Build Coastguard Worker} 103*9880d681SAndroid Build Coastguard Worker 104*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.assume(i1) 105*9880d681SAndroid Build Coastguard Workerdeclare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...) 106*9880d681SAndroid Build Coastguard Workerdeclare i32 addrspace(1)* addrspace(1)* @llvm.experimental.gc.relocate.p1p1i32(token, i32, i32) #3 107