| Anna Thomas | 7df1a92 | 2017-12-05 21:39:37 +0000 | [diff] [blame] | 1 | ; RUN: opt -safepoint-ir-verifier-print-only -verify-safepoint-ir -S %s 2>&1 | FileCheck %s | 
|  | 2 |  | 
|  | 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 ()* undef, i32 0, i32 0, i32 0, i32 0, 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)* | 
|  | 12 | ret void | 
|  | 13 | } | 
|  | 14 |  | 
|  | 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 ()* undef, i32 0, i32 0, i32 0, i32 0, i8 addrspace(1)* %base1) | 
|  | 22 | %ptr2 = getelementptr i8, i8 addrspace(1)* %base2, i64 8 | 
|  | 23 | %c2 = icmp sgt i8 addrspace(1)* %ptr2, %ptr | 
|  | 24 | ret void | 
|  | 25 | } | 
|  | 26 |  | 
|  | 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 ()* undef, i32 0, i32 0, i32 0, i32 0, 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 | 
|  | 47 | ret void | 
|  | 48 | } | 
|  | 49 |  | 
|  | 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 ()* undef, i32 0, i32 0, i32 0, i32 0, 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 | 
|  | 61 | ret void | 
|  | 62 | } | 
|  | 63 |  | 
|  | 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 ()* undef, i32 0, i32 0, i32 0, i32 0, i8 addrspace(1)* %base2 , i32 -1, i32 0, i32 0, i32 0) | 
|  | 69 | %base2.relocated = call i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %safepoint_token, i32 7, i32 7) ; 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 | 
|  | 75 | ret void | 
|  | 76 | } | 
|  | 77 |  | 
|  | 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" { | 
|  | 80 | .b0: | 
|  | 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 ()* undef, i32 0, i32 0, i32 0, i32 0, i8 addrspace(1)* %base2 , i32 -1, i32 0, i32 0, i32 0) | 
|  | 83 | %base2.relocated = call i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %safepoint_token, i32 7, i32 7) ; base2, base2 | 
|  | 84 | %addr1 = getelementptr i8, i8 addrspace(1)* %base1, i64 %arg | 
|  | 85 | br label %.b1 | 
|  | 86 |  | 
|  | 87 | .b1: | 
|  | 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 | 
|  | 92 | ret void | 
|  | 93 | } | 
|  | 94 |  | 
|  | 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 ()* undef, i32 0, i32 0, i32 0, i32 0, i8 addrspace(1)* %base2 , i32 -1, i32 0, i32 0, i32 0) | 
|  | 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 | 
|  | 106 | ret void | 
|  | 107 | } | 
|  | 108 |  | 
|  | 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" { | 
|  | 111 | .b0: | 
|  | 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 ()* undef, i32 0, i32 0, i32 0, i32 0, i8 addrspace(1)* %base2 , i32 -1, i32 0, i32 0, i32 0) | 
|  | 115 | br label %.b1 | 
|  | 116 |  | 
|  | 117 | .b1: | 
|  | 118 | %addr2 = getelementptr i8, i8 addrspace(1)* %base2, i64 8 | 
|  | 119 | br label %.b2 | 
|  | 120 |  | 
|  | 121 | .b2: | 
|  | 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 | 
|  | 127 | ret void | 
|  | 128 | } | 
|  | 129 |  | 
|  | 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 ()* undef, i32 0, i32 0, i32 0, i32 0, i8 addrspace(1)* %base2 , i32 -1, i32 0, i32 0, i32 0) | 
|  | 136 | %base2.relocated = call i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %safepoint_token, i32 7, i32 7) ; 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 ()* undef, i32 0, i32 0, i32 0, i32 0, i8 addrspace(1)* %base2.relocated, i32 -1, i32 0, i32 0, i32 0) | 
|  | 139 | %base2.relocated2 = call i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %safepoint_token2, i32 7, i32 7) ; 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 ()* undef, i32 0, i32 0, i32 0, i32 0, i8 addrspace(1)* %base2.relocated2, i32 -1, i32 0, i32 0, i32 0) | 
|  | 143 | ret void | 
|  | 144 | } | 
|  | 145 |  | 
|  | 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) | 
|  | 149 |  |