1 ; RUN: opt < %s -basicaa -gvn -instcombine -S 2>&1 | FileCheck %s 2 3 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" 4 5 ; Make sure that basicaa thinks R and r are must aliases. 6 define i32 @test1(i8 * %P) { 7 entry: 8 %Q = bitcast i8* %P to {i32, i32}* 9 %R = getelementptr {i32, i32}* %Q, i32 0, i32 1 10 %S = load i32* %R 11 12 %q = bitcast i8* %P to {i32, i32}* 13 %r = getelementptr {i32, i32}* %q, i32 0, i32 1 14 %s = load i32* %r 15 16 %t = sub i32 %S, %s 17 ret i32 %t 18 ; CHECK: @test1 19 ; CHECK: ret i32 0 20 } 21 22 define i32 @test2(i8 * %P) { 23 entry: 24 %Q = bitcast i8* %P to {i32, i32, i32}* 25 %R = getelementptr {i32, i32, i32}* %Q, i32 0, i32 1 26 %S = load i32* %R 27 28 %r = getelementptr {i32, i32, i32}* %Q, i32 0, i32 2 29 store i32 42, i32* %r 30 31 %s = load i32* %R 32 33 %t = sub i32 %S, %s 34 ret i32 %t 35 ; CHECK: @test2 36 ; CHECK: ret i32 0 37 } 38 39 40 ; This was a miscompilation. 41 define i32 @test3({float, {i32, i32, i32}}* %P) { 42 entry: 43 %P2 = getelementptr {float, {i32, i32, i32}}* %P, i32 0, i32 1 44 %R = getelementptr {i32, i32, i32}* %P2, i32 0, i32 1 45 %S = load i32* %R 46 47 %r = getelementptr {i32, i32, i32}* %P2, i32 0, i32 2 48 store i32 42, i32* %r 49 50 %s = load i32* %R 51 52 %t = sub i32 %S, %s 53 ret i32 %t 54 ; CHECK: @test3 55 ; CHECK: ret i32 0 56 } 57 58 59 ;; This is reduced from the SmallPtrSet constructor. 60 %SmallPtrSetImpl = type { i8**, i32, i32, i32, [1 x i8*] } 61 %SmallPtrSet64 = type { %SmallPtrSetImpl, [64 x i8*] } 62 63 define i32 @test4(%SmallPtrSet64* %P) { 64 entry: 65 %tmp2 = getelementptr inbounds %SmallPtrSet64* %P, i64 0, i32 0, i32 1 66 store i32 64, i32* %tmp2, align 8 67 %tmp3 = getelementptr inbounds %SmallPtrSet64* %P, i64 0, i32 0, i32 4, i64 64 68 store i8* null, i8** %tmp3, align 8 69 %tmp4 = load i32* %tmp2, align 8 70 ret i32 %tmp4 71 ; CHECK: @test4 72 ; CHECK: ret i32 64 73 } 74 75 ; P[i] != p[i+1] 76 define i32 @test5(i32* %p, i64 %i) { 77 %pi = getelementptr i32* %p, i64 %i 78 %i.next = add i64 %i, 1 79 %pi.next = getelementptr i32* %p, i64 %i.next 80 %x = load i32* %pi 81 store i32 42, i32* %pi.next 82 %y = load i32* %pi 83 %z = sub i32 %x, %y 84 ret i32 %z 85 ; CHECK: @test5 86 ; CHECK: ret i32 0 87 } 88 89 ; P[i] != p[(i*4)|1] 90 define i32 @test6(i32* %p, i64 %i1) { 91 %i = shl i64 %i1, 2 92 %pi = getelementptr i32* %p, i64 %i 93 %i.next = or i64 %i, 1 94 %pi.next = getelementptr i32* %p, i64 %i.next 95 %x = load i32* %pi 96 store i32 42, i32* %pi.next 97 %y = load i32* %pi 98 %z = sub i32 %x, %y 99 ret i32 %z 100 ; CHECK: @test6 101 ; CHECK: ret i32 0 102 } 103 104 ; P[1] != P[i*4] 105 define i32 @test7(i32* %p, i64 %i) { 106 %pi = getelementptr i32* %p, i64 1 107 %i.next = shl i64 %i, 2 108 %pi.next = getelementptr i32* %p, i64 %i.next 109 %x = load i32* %pi 110 store i32 42, i32* %pi.next 111 %y = load i32* %pi 112 %z = sub i32 %x, %y 113 ret i32 %z 114 ; CHECK: @test7 115 ; CHECK: ret i32 0 116 } 117 118 ; P[zext(i)] != p[zext(i+1)] 119 ; PR1143 120 define i32 @test8(i32* %p, i16 %i) { 121 %i1 = zext i16 %i to i32 122 %pi = getelementptr i32* %p, i32 %i1 123 %i.next = add i16 %i, 1 124 %i.next2 = zext i16 %i.next to i32 125 %pi.next = getelementptr i32* %p, i32 %i.next2 126 %x = load i32* %pi 127 store i32 42, i32* %pi.next 128 %y = load i32* %pi 129 %z = sub i32 %x, %y 130 ret i32 %z 131 ; CHECK: @test8 132 ; CHECK: ret i32 0 133 } 134 135 define i8 @test9([4 x i8] *%P, i32 %i, i32 %j) { 136 %i2 = shl i32 %i, 2 137 %i3 = add i32 %i2, 1 138 ; P2 = P + 1 + 4*i 139 %P2 = getelementptr [4 x i8] *%P, i32 0, i32 %i3 140 141 %j2 = shl i32 %j, 2 142 143 ; P4 = P + 4*j 144 %P4 = getelementptr [4 x i8]* %P, i32 0, i32 %j2 145 146 %x = load i8* %P2 147 store i8 42, i8* %P4 148 %y = load i8* %P2 149 %z = sub i8 %x, %y 150 ret i8 %z 151 ; CHECK: @test9 152 ; CHECK: ret i8 0 153 } 154 155 define i8 @test10([4 x i8] *%P, i32 %i) { 156 %i2 = shl i32 %i, 2 157 %i3 = add i32 %i2, 4 158 ; P2 = P + 4 + 4*i 159 %P2 = getelementptr [4 x i8] *%P, i32 0, i32 %i3 160 161 ; P4 = P + 4*i 162 %P4 = getelementptr [4 x i8]* %P, i32 0, i32 %i2 163 164 %x = load i8* %P2 165 store i8 42, i8* %P4 166 %y = load i8* %P2 167 %z = sub i8 %x, %y 168 ret i8 %z 169 ; CHECK: @test10 170 ; CHECK: ret i8 0 171 } 172 173 ; (This was a miscompilation.) 174 define float @test11(i32 %indvar, [4 x [2 x float]]* %q) nounwind ssp { 175 %tmp = mul i32 %indvar, -1 176 %dec = add i32 %tmp, 3 177 %scevgep = getelementptr [4 x [2 x float]]* %q, i32 0, i32 %dec 178 %scevgep35 = bitcast [2 x float]* %scevgep to i64* 179 %arrayidx28 = getelementptr inbounds [4 x [2 x float]]* %q, i32 0, i32 0 180 %y29 = getelementptr inbounds [2 x float]* %arrayidx28, i32 0, i32 1 181 store float 1.0, float* %y29, align 4 182 store i64 0, i64* %scevgep35, align 4 183 %tmp30 = load float* %y29, align 4 184 ret float %tmp30 185 ; CHECK: @test11 186 ; CHECK: ret float %tmp30 187 } 188 189 ; (This was a miscompilation.) 190 define i32 @test12(i32 %x, i32 %y, i8* %p) nounwind { 191 %a = bitcast i8* %p to [13 x i8]* 192 %b = getelementptr [13 x i8]* %a, i32 %x 193 %c = bitcast [13 x i8]* %b to [15 x i8]* 194 %d = getelementptr [15 x i8]* %c, i32 %y, i32 8 195 %castd = bitcast i8* %d to i32* 196 %castp = bitcast i8* %p to i32* 197 store i32 1, i32* %castp 198 store i32 0, i32* %castd 199 %r = load i32* %castp 200 ret i32 %r 201 ; CHECK: @test12 202 ; CHECK: ret i32 %r 203 } 204