1 ; RUN: opt -safepoint-ir-verifier-print-only -verify-safepoint-ir -S %s 2>&1 | FileCheck %s
3 ; In some cases, it is valid to have unrelocated pointers used as compare
4 ; operands. Make sure the verifier knows to spot these exceptions.
7 ; comparison against null.
8 define i8 addrspace(1)* @test1(i64 %arg, i8 addrspace(1)* %addr) gc "statepoint-example" {
9 ; CHECK: No illegal uses found by SafepointIRVerifier in: test1
11 %load_addr = getelementptr i8, i8 addrspace(1)* %addr, i64 %arg
12 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* elementtype(void ()) undef, i32 0, i32 0, i32 0, i32 0)
13 %cmp = icmp eq i8 addrspace(1)* %load_addr, null
14 ret i8 addrspace(1)* null
17 ; comparison against exclusively derived null.
18 define void @test2(i64 %arg, i1 %cond, i8 addrspace(1)* %addr) gc "statepoint-example" {
19 ; CHECK: No illegal uses found by SafepointIRVerifier in: test2
20 %load_addr = getelementptr i8, i8 addrspace(1)* null, i64 %arg
21 %load_addr_sel = select i1 %cond, i8 addrspace(1)* null, i8 addrspace(1)* %load_addr
22 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* elementtype(void ()) undef, i32 0, i32 0, i32 0, i32 0)
23 %cmp = icmp eq i8 addrspace(1)* %addr, %load_addr_sel
27 ; comparison against a constant non-null pointer. This is unrelocated use, since
28 ; that pointer bits may mean something in a VM.
29 define void @test3(i64 %arg, i32 addrspace(1)* %addr) gc "statepoint-example" {
30 ; CHECK-LABEL: Verifying gc pointers in function: test3
31 ; CHECK: Illegal use of unrelocated value found!
33 %load_addr = getelementptr i32, i32 addrspace(1)* %addr, i64 %arg
34 %load_addr_const = getelementptr i32, i32 addrspace(1)* inttoptr (i64 15 to i32 addrspace(1)*), i64 %arg
35 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* elementtype(void ()) undef, i32 0, i32 0, i32 0, i32 0)
36 %cmp = icmp eq i32 addrspace(1)* %load_addr, %load_addr_const
40 ; comparison against a derived pointer that is *not* exclusively derived from
41 ; null. An unrelocated use since the derived pointer could be from the constant
42 ; non-null pointer (load_addr.2).
43 define void @test4(i64 %arg, i1 %cond, i8 addrspace(1)* %base) gc "statepoint-example" {
44 ; CHECK-LABEL: Verifying gc pointers in function: test4
45 ; CHECK: Illegal use of unrelocated value found!
47 %load_addr.1 = getelementptr i8, i8 addrspace(1)* null, i64 %arg
48 br i1 %cond, label %split, label %join
51 %load_addr.2 = getelementptr i8, i8 addrspace(1)* inttoptr (i64 30 to i8 addrspace(1)*), i64 %arg
55 %load_addr = phi i8 addrspace(1)* [%load_addr.1, %entry], [%load_addr.2, %split]
56 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* elementtype(void ()) undef, i32 0, i32 0, i32 0, i32 0)
57 %cmp = icmp eq i8 addrspace(1)* %load_addr, %base
61 ; comparison between 2 unrelocated base pointers.
62 ; Since the cmp can be reordered legally before the safepoint, these are correct
63 ; unrelocated uses of the pointers.
64 define void @test5(i64 %arg, i8 addrspace(1)* %base1, i8 addrspace(1)* %base2) gc "statepoint-example" {
65 ; CHECK: No illegal uses found by SafepointIRVerifier in: test5
66 %load_addr1 = getelementptr i8, i8 addrspace(1)* %base1, i64 %arg
67 %load_addr2 = getelementptr i8, i8 addrspace(1)* %base2, i64 %arg
68 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* elementtype(void ()) undef, i32 0, i32 0, i32 0, i32 0)
69 %cmp = icmp eq i8 addrspace(1)* %load_addr1, %load_addr2
73 ; comparison between a relocated and an unrelocated pointer.
74 ; this is invalid use of the unrelocated pointer.
75 define void @test6(i64 %arg, i8 addrspace(1)* %base1, i8 addrspace(1)* %base2) gc "statepoint-example" {
76 ; CHECK-LABEL: Verifying gc pointers in function: test6
77 ; CHECK: Illegal use of unrelocated value found!
78 %load_addr1 = getelementptr i8, i8 addrspace(1)* %base1, i64 %arg
79 %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* elementtype(void ()) undef, i32 0, i32 0, i32 0, i32 0) ["gc-live"(i8 addrspace(1)* %base2)]
80 %ptr2.relocated = call i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %safepoint_token, i32 0, i32 0) ; base2, base2
81 %cmp = icmp eq i8 addrspace(1)* %load_addr1, %ptr2.relocated
84 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
85 declare i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token, i32, i32)