107 lines · plain
1; RUN: opt -O3 -S < %s | FileCheck --check-prefix=CHECK-OPT %s2; RUN: llc -verify-machineinstrs < %s | FileCheck --check-prefix=CHECK-LLC %s3; These tests are targetted at making sure we don't retain information4; about memory which contains potential gc references across a statepoint.5; They're carefully written to only outlaw forwarding of references. 6; Depending on the collector, forwarding non-reference fields or7; constant null references may be perfectly legal. (If unimplemented.)8; The general structure of these tests is:9; - learn a fact about memory (via an assume)10; - cross a statepoint11; - check the same fact about memory (which we no longer know)12 13target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"14target triple = "x86_64-pc-linux-gnu"15 16; If not at a statepoint, we could forward known memory values17; across this call.18declare void @func() readonly19 20;; Forwarding the value of a pointer load is invalid since it may have21;; changed at the safepoint. Forwarding a non-gc pointer value would 22;; be valid, but is not currently implemented.23define i1 @test_load_forward(ptr addrspace(1) %p) gc "statepoint-example" {24entry:25 %before = load ptr addrspace(1), ptr addrspace(1) %p26 %cmp1 = call i1 @f(ptr addrspace(1) %before)27 call void @llvm.assume(i1 %cmp1)28 %safepoint_token = tail call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0) ["gc-live" (ptr addrspace(1) %p)]29 %pnew = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)30 %after = load ptr addrspace(1), ptr addrspace(1) %pnew31 %cmp2 = call i1 @f(ptr addrspace(1) %after)32 ret i1 %cmp233 34; CHECK-OPT-LABEL: test_load_forward35; CHECK-OPT: ret i1 %cmp236; CHECK-LLC-LABEL: test_load_forward37; CHECK-LLC: callq f38}39 40;; Same as above, but forwarding from a store41define i1 @test_store_forward(ptr addrspace(1) %p,42 ptr addrspace(1) %v) gc "statepoint-example" {43entry:44 %cmp1 = call i1 @f(ptr addrspace(1) %v)45 call void @llvm.assume(i1 %cmp1)46 store ptr addrspace(1) %v, ptr addrspace(1) %p47 %safepoint_token = tail call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0) ["gc-live" (ptr addrspace(1) %p)]48 %pnew = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)49 %after = load ptr addrspace(1), ptr addrspace(1) %pnew50 %cmp2 = call i1 @f(ptr addrspace(1) %after)51 ret i1 %cmp252 53; CHECK-OPT-LABEL: test_store_forward54; CHECK-OPT: ret i1 %cmp255; CHECK-LLC-LABEL: test_store_forward56; CHECK-LLC: callq f57}58 59; A predicate on the pointer which is not simply null, but whose value60; would be known unchanged if the pointer value could be forwarded.61; The implementation of such a function could inspect the integral value62; of the pointer and is thus not safe to reuse after a statepoint.63declare i1 @f(ptr addrspace(1) %v) readnone64 65; This is a variant of the test_load_forward test which is intended to 66; highlight the fact that a gc pointer can be stored in part of the heap67; that is not itself GC managed. The GC may have an external mechanism68; to know about and update that value at a safepoint. Note that the 69; statepoint does not provide the collector with this root.70define i1 @test_load_forward_nongc_heap(ptr %p) gc "statepoint-example" {71entry:72 %before = load ptr addrspace(1), ptr %p73 %cmp1 = call i1 @f(ptr addrspace(1) %before)74 call void @llvm.assume(i1 %cmp1)75 call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0)76 %after = load ptr addrspace(1), ptr %p77 %cmp2 = call i1 @f(ptr addrspace(1) %after)78 ret i1 %cmp279 80; CHECK-OPT-LABEL: test_load_forward_nongc_heap81; CHECK-OPT: ret i1 %cmp282; CHECK-LLC-LABEL: test_load_forward_nongc_heap83; CHECK-LLC: callq f84}85 86;; Same as above, but forwarding from a store87define i1 @test_store_forward_nongc_heap(ptr %p,88 ptr addrspace(1) %v) gc "statepoint-example" {89entry:90 %cmp1 = call i1 @f(ptr addrspace(1) %v)91 call void @llvm.assume(i1 %cmp1)92 store ptr addrspace(1) %v, ptr %p93 call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0)94 %after = load ptr addrspace(1), ptr %p95 %cmp2 = call i1 @f(ptr addrspace(1) %after)96 ret i1 %cmp297 98; CHECK-OPT-LABEL: test_store_forward_nongc_heap99; CHECK-OPT: ret i1 %cmp2100; CHECK-LLC-LABEL: test_store_forward_nongc_heap101; CHECK-LLC: callq f102}103 104declare void @llvm.assume(i1)105declare token @llvm.experimental.gc.statepoint.p0(i64, i32, ptr, i32, i32, ...)106declare ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token, i32, i32) #3107