1 ; RUN: opt -safepoint-ir-verifier-print-only -verify-safepoint-ir -S %s 2>&1 | FileCheck %s
3 ; Checking if verifier accepts chain of GEPs/bitcasts.
4 define void @test.deriving.ok(i32, i8 addrspace(1)* %base1, i8 addrspace(1)* %base2) gc "statepoint-example" {
5 ; CHECK-LABEL: Verifying gc pointers in function: test.deriving.ok
6 ; CHECK-NEXT: No illegal uses found by SafepointIRVerifier in: test.deriving.ok
7 %ptr = getelementptr i8, i8 addrspace(1)* %base1, i64 4
8 %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)* %base1)]
9 %ptr2 = getelementptr i8, i8 addrspace(1)* %base2, i64 8
10 %ptr.i32 = bitcast i8 addrspace(1)* %ptr to i32 addrspace(1)*
11 %ptr2.i32 = bitcast i8 addrspace(1)* %ptr2 to i32 addrspace(1)*
15 ; Checking if verifier accepts cmp of two derived pointers when one defined
16 ; before safepoint and one after and both have unrelocated base.
17 define void @test.cmp.ok(i32, i8 addrspace(1)* %base1, i8 addrspace(1)* %base2) gc "statepoint-example" {
18 ; CHECK-LABEL: Verifying gc pointers in function: test.cmp.ok
19 ; CHECK-NEXT: No illegal uses found by SafepointIRVerifier in: test.cmp.ok
20 %ptr = getelementptr i8, i8 addrspace(1)* %base1, i64 4
21 %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)* %base1)]
22 %ptr2 = getelementptr i8, i8 addrspace(1)* %base2, i64 8
23 %c2 = icmp sgt i8 addrspace(1)* %ptr2, %ptr
27 ; Checking if verifier accepts cmp of two derived pointers when one defined
28 ; before safepoint and one after and both have unrelocated base. One of pointers
29 ; defined as a long chain of geps/bitcasts.
30 define void @test.cmp-long_chain.ok(i32, i8 addrspace(1)* %base1, i8 addrspace(1)* %base2) gc "statepoint-example" {
31 ; CHECK-LABEL: Verifying gc pointers in function: test.cmp-long_chain.ok
32 ; CHECK-NEXT: No illegal uses found by SafepointIRVerifier in: test.cmp-long_chain.ok
33 %ptr = getelementptr i8, i8 addrspace(1)* %base1, i64 4
34 %ptr.i32 = bitcast i8 addrspace(1)* %ptr to i32 addrspace(1)*
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) ["gc-live"(i8 addrspace(1)* %base1)]
36 %ptr2 = getelementptr i8, i8 addrspace(1)* %base2, i64 8
37 %ptr2.i32 = bitcast i8 addrspace(1)* %ptr2 to i32 addrspace(1)*
38 %ptr2.i32.2 = getelementptr i32, i32 addrspace(1)* %ptr2.i32, i64 4
39 %ptr2.i32.3 = getelementptr i32, i32 addrspace(1)* %ptr2.i32.2, i64 8
40 %ptr2.i32.4 = getelementptr i32, i32 addrspace(1)* %ptr2.i32.3, i64 8
41 %ptr2.i32.5 = getelementptr i32, i32 addrspace(1)* %ptr2.i32.4, i64 8
42 %ptr2.i32.6 = getelementptr i32, i32 addrspace(1)* %ptr2.i32.5, i64 8
43 %ptr2.i32.6.i8 = bitcast i32 addrspace(1)* %ptr2.i32.6 to i8 addrspace(1)*
44 %ptr2.i32.6.i8.i32 = bitcast i8 addrspace(1)* %ptr2.i32.6.i8 to i32 addrspace(1)*
45 %ptr2.i32.6.i8.i32.2 = getelementptr i32, i32 addrspace(1)* %ptr2.i32.6.i8.i32, i64 8
46 %c2 = icmp sgt i32 addrspace(1)* %ptr2.i32.6.i8.i32.2, %ptr.i32
50 ; GEP and bitcast of unrelocated pointer is acceptable, but load by resulting
51 ; pointer should be reported.
52 define void @test.load.fail(i32, i8 addrspace(1)* %base) gc "statepoint-example" {
53 ; CHECK-LABEL: Verifying gc pointers in function: test.load.fail
54 %ptr = getelementptr i8, i8 addrspace(1)* %base, i64 4
55 %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)* %base)]
56 %ptr.i32 = bitcast i8 addrspace(1)* %ptr to i32 addrspace(1)* ; it's ok
57 ; CHECK-NEXT: Illegal use of unrelocated value found!
58 ; CHECK-NEXT: Def: %ptr.i32 = bitcast i8 addrspace(1)* %ptr to i32 addrspace(1)*
59 ; CHECK-NEXT: Use: %ptr.val = load i32, i32 addrspace(1)* %ptr.i32
60 %ptr.val = load i32, i32 addrspace(1)* %ptr.i32
64 ; Comparison between pointer derived from unrelocated one (though defined after
65 ; safepoint) and relocated pointer should be reported.
66 define void @test.cmp.fail(i64 %arg, i8 addrspace(1)* %base1, i8 addrspace(1)* %base2) gc "statepoint-example" {
67 ; CHECK-LABEL: Verifying gc pointers in function: test.cmp.fail
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) ["gc-live"(i8 addrspace(1)* %base2)]
69 %base2.relocated = call i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %safepoint_token, i32 0, i32 0) ; base2, base2
70 %addr1 = getelementptr i8, i8 addrspace(1)* %base1, i64 %arg
71 ; CHECK-NEXT: Illegal use of unrelocated value found!
72 ; CHECK-NEXT: Def: %addr1 = getelementptr i8, i8 addrspace(1)* %base1, i64 %arg
73 ; CHECK-NEXT: Use: %cmp = icmp eq i8 addrspace(1)* %addr1, %base2.relocated
74 %cmp = icmp eq i8 addrspace(1)* %addr1, %base2.relocated
78 ; Same as test.cmp.fail but splitted into two BBs.
79 define void @test.cmp2.fail(i64 %arg, i8 addrspace(1)* %base1, i8 addrspace(1)* %base2) gc "statepoint-example" {
81 ; CHECK-LABEL: Verifying gc pointers in function: test.cmp2.fail
82 %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)]
83 %base2.relocated = call i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %safepoint_token, i32 0, i32 0) ; base2, base2
84 %addr1 = getelementptr i8, i8 addrspace(1)* %base1, i64 %arg
88 ; CHECK-NEXT: Illegal use of unrelocated value found!
89 ; CHECK-NEXT: Def: %addr1 = getelementptr i8, i8 addrspace(1)* %base1, i64 %arg
90 ; CHECK-NEXT: Use: %cmp = icmp eq i8 addrspace(1)* %addr1, %base2.relocated
91 %cmp = icmp eq i8 addrspace(1)* %addr1, %base2.relocated
95 ; Checking that cmp of two unrelocated pointers is OK and load is not.
96 define void @test.cmp-load.fail(i64 %arg, i8 addrspace(1)* %base1, i8 addrspace(1)* %base2) gc "statepoint-example" {
97 ; CHECK-LABEL: Verifying gc pointers in function: test.cmp-load.fail
98 %addr1 = getelementptr i8, i8 addrspace(1)* %base1, i64 %arg
99 %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)]
100 %addr2 = getelementptr i8, i8 addrspace(1)* %base2, i64 8
101 %cmp = icmp eq i8 addrspace(1)* %addr1, %addr2
102 ; CHECK-NEXT: Illegal use of unrelocated value found!
103 ; CHECK-NEXT: Def: %addr2 = getelementptr i8, i8 addrspace(1)* %base2, i64 8
104 ; CHECK-NEXT: Use: %val = load i8, i8 addrspace(1)* %addr2
105 %val = load i8, i8 addrspace(1)* %addr2
109 ; Same as test.cmp-load.fail but splitted into thee BBs.
110 define void @test.cmp-load2.fail(i64 %arg, i8 addrspace(1)* %base1, i8 addrspace(1)* %base2) gc "statepoint-example" {
112 ; CHECK-LABEL: Verifying gc pointers in function: test.cmp-load2.fail
113 %addr1 = getelementptr i8, i8 addrspace(1)* %base1, i64 %arg
114 %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)]
118 %addr2 = getelementptr i8, i8 addrspace(1)* %base2, i64 8
122 %cmp = icmp eq i8 addrspace(1)* %addr1, %addr2
123 ; CHECK-NEXT: Illegal use of unrelocated value found!
124 ; CHECK-NEXT: Def: %addr2 = getelementptr i8, i8 addrspace(1)* %base2, i64 8
125 ; CHECK-NEXT: Use: %val = load i8, i8 addrspace(1)* %addr2
126 %val = load i8, i8 addrspace(1)* %addr2
130 ; Same as test.cmp.ok but with multiple safepoints within one BB. And the last
131 ; one is in the very end of BB so that Contribution of this BB is empty.
132 define void @test.cmp.multi-sp.ok(i64 %arg, i8 addrspace(1)* %base1, i8 addrspace(1)* %base2) gc "statepoint-example" {
133 ; CHECK-LABEL: Verifying gc pointers in function: test.cmp.multi-sp.ok
134 ; CHECK-NEXT: No illegal uses found by SafepointIRVerifier in: test.cmp.multi-sp.ok
135 %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)]
136 %base2.relocated = call i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %safepoint_token, i32 0, i32 0) ; base2, base2
137 %addr1 = getelementptr i8, i8 addrspace(1)* %base1, i64 %arg
138 %safepoint_token2 = 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.relocated)]
139 %base2.relocated2 = call i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %safepoint_token2, i32 0, i32 0) ; base2.relocated, base2.relocated
140 %addr2 = getelementptr i8, i8 addrspace(1)* %base2, i64 %arg
141 %cmp = icmp eq i8 addrspace(1)* %addr1, %addr2
142 %safepoint_token3 = 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.relocated2)]
146 ; Function Attrs: nounwind
147 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
148 declare i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token, i32, i32)