1 ; RUN: opt < %s -instcombine -S 2 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:n8:16:32" 3 target triple = "i386-apple-darwin10.0" 4 5 define i32 @test0(i8 %tmp2) ssp { 6 entry: 7 %tmp3 = zext i8 %tmp2 to i32 8 %tmp8 = lshr i32 %tmp3, 6 9 %tmp9 = lshr i32 %tmp3, 7 10 %tmp10 = xor i32 %tmp9, 67108858 11 %tmp11 = xor i32 %tmp10, %tmp8 12 %tmp12 = xor i32 %tmp11, 0 13 ret i32 %tmp12 14 } 15 16 ; PR4905 17 define <2 x i64> @test1(<2 x i64> %x, <2 x i64> %y) nounwind { 18 entry: 19 %conv.i94 = bitcast <2 x i64> %y to <4 x i32> ; <<4 x i32>> [#uses=1] 20 %sub.i97 = sub <4 x i32> %conv.i94, undef ; <<4 x i32>> [#uses=1] 21 %conv3.i98 = bitcast <4 x i32> %sub.i97 to <2 x i64> ; <<2 x i64>> [#uses=2] 22 %conv2.i86 = bitcast <2 x i64> %conv3.i98 to <4 x i32> ; <<4 x i32>> [#uses=1] 23 %cmp.i87 = icmp sgt <4 x i32> undef, %conv2.i86 ; <<4 x i1>> [#uses=1] 24 %sext.i88 = sext <4 x i1> %cmp.i87 to <4 x i32> ; <<4 x i32>> [#uses=1] 25 %conv3.i89 = bitcast <4 x i32> %sext.i88 to <2 x i64> ; <<2 x i64>> [#uses=1] 26 %and.i = and <2 x i64> %conv3.i89, %conv3.i98 ; <<2 x i64>> [#uses=1] 27 %or.i = or <2 x i64> zeroinitializer, %and.i ; <<2 x i64>> [#uses=1] 28 %conv2.i43 = bitcast <2 x i64> %or.i to <4 x i32> ; <<4 x i32>> [#uses=1] 29 %sub.i = sub <4 x i32> zeroinitializer, %conv2.i43 ; <<4 x i32>> [#uses=1] 30 %conv3.i44 = bitcast <4 x i32> %sub.i to <2 x i64> ; <<2 x i64>> [#uses=1] 31 ret <2 x i64> %conv3.i44 32 } 33 34 35 ; PR4908 36 define void @test2(<1 x i16>* nocapture %b, i32* nocapture %c) nounwind ssp { 37 entry: 38 %arrayidx = getelementptr inbounds <1 x i16>* %b, i64 undef ; <<1 x i16>*> 39 %tmp2 = load <1 x i16>* %arrayidx ; <<1 x i16>> [#uses=1] 40 %tmp6 = bitcast <1 x i16> %tmp2 to i16 ; <i16> [#uses=1] 41 %tmp7 = zext i16 %tmp6 to i32 ; <i32> [#uses=1] 42 %ins = or i32 0, %tmp7 ; <i32> [#uses=1] 43 %arrayidx20 = getelementptr inbounds i32* %c, i64 undef ; <i32*> [#uses=1] 44 store i32 %ins, i32* %arrayidx20 45 ret void 46 } 47 48 ; PR5262 49 @tmp2 = global i64 0 ; <i64*> [#uses=1] 50 51 declare void @use(i64) nounwind 52 53 define void @foo(i1) nounwind align 2 { 54 ; <label>:1 55 br i1 %0, label %2, label %3 56 57 ; <label>:2 ; preds = %1 58 br label %3 59 60 ; <label>:3 ; preds = %2, %1 61 %4 = phi i8 [ 1, %2 ], [ 0, %1 ] ; <i8> [#uses=1] 62 %5 = icmp eq i8 %4, 0 ; <i1> [#uses=1] 63 %6 = load i64* @tmp2, align 8 ; <i64> [#uses=1] 64 %7 = select i1 %5, i64 0, i64 %6 ; <i64> [#uses=1] 65 br label %8 66 67 ; <label>:8 ; preds = %3 68 call void @use(i64 %7) 69 ret void 70 } 71 72 %t0 = type { i32, i32 } 73 %t1 = type { i32, i32, i32, i32, i32* } 74 75 declare %t0* @bar2(i64) 76 77 define void @bar3(i1, i1) nounwind align 2 { 78 ; <label>:2 79 br i1 %1, label %10, label %3 80 81 ; <label>:3 ; preds = %2 82 %4 = getelementptr inbounds %t0* null, i64 0, i32 1 ; <i32*> [#uses=0] 83 %5 = getelementptr inbounds %t1* null, i64 0, i32 4 ; <i32**> [#uses=1] 84 %6 = load i32** %5, align 8 ; <i32*> [#uses=1] 85 %7 = icmp ne i32* %6, null ; <i1> [#uses=1] 86 %8 = zext i1 %7 to i32 ; <i32> [#uses=1] 87 %9 = add i32 %8, 0 ; <i32> [#uses=1] 88 br label %10 89 90 ; <label>:10 ; preds = %3, %2 91 %11 = phi i32 [ %9, %3 ], [ 0, %2 ] ; <i32> [#uses=1] 92 br i1 %1, label %12, label %13 93 94 ; <label>:12 ; preds = %10 95 br label %13 96 97 ; <label>:13 ; preds = %12, %10 98 %14 = zext i32 %11 to i64 ; <i64> [#uses=1] 99 %15 = tail call %t0* @bar2(i64 %14) nounwind ; <%0*> [#uses=0] 100 ret void 101 } 102 103 104 105 106 ; PR5262 107 ; Make sure the PHI node gets put in a place where all of its operands dominate 108 ; it. 109 define i64 @test4(i1 %c, i64* %P) nounwind align 2 { 110 BB0: 111 br i1 %c, label %BB1, label %BB2 112 113 BB1: 114 br label %BB2 115 116 BB2: 117 %v5_ = phi i1 [ true, %BB0], [false, %BB1] 118 %v6 = load i64* %P 119 br label %l8 120 121 l8: 122 br label %l10 123 124 l10: 125 %v11 = select i1 %v5_, i64 0, i64 %v6 126 ret i64 %v11 127 } 128 129 ; PR5471 130 define i32 @test5a() { 131 ret i32 0 132 } 133 134 define void @test5() { 135 store i1 true, i1* undef 136 %1 = invoke i32 @test5a() to label %exit unwind label %exit 137 exit: 138 %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0 139 cleanup 140 ret void 141 } 142 143 144 ; PR5673 145 146 @test6g = external global i32* 147 148 define arm_aapcs_vfpcc i32 @test6(i32 %argc, i8** %argv) nounwind { 149 entry: 150 store i32* getelementptr (i32* bitcast (i32 (i32, i8**)* @test6 to i32*), i32 -2048), i32** @test6g, align 4 151 unreachable 152 } 153 154 155 ; PR5827 156 157 %class.RuleBasedBreakIterator = type { i64 ()* } 158 %class.UStack = type { i8** } 159 160 define i32 @_ZN22RuleBasedBreakIterator15checkDictionaryEi(%class.RuleBasedBreakIterator* %this, i32 %x) align 2 { 161 entry: 162 %breaks = alloca %class.UStack, align 4 ; <%class.UStack*> [#uses=3] 163 call void @_ZN6UStackC1Ei(%class.UStack* %breaks, i32 0) 164 %tobool = icmp ne i32 %x, 0 ; <i1> [#uses=1] 165 br i1 %tobool, label %cond.end, label %cond.false 166 167 terminate.handler: ; preds = %ehcleanup 168 %exc = call i8* @llvm.eh.exception() ; <i8*> [#uses=1] 169 %0 = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exc, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i32 1) ; <i32> [#uses=0] 170 call void @_ZSt9terminatev() noreturn nounwind 171 unreachable 172 173 ehcleanup: ; preds = %cond.false 174 %exc1 = call i8* @llvm.eh.exception() ; <i8*> [#uses=2] 175 %1 = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exc1, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* null) ; <i32> [#uses=0] 176 invoke void @_ZN6UStackD1Ev(%class.UStack* %breaks) 177 to label %cont unwind label %terminate.handler 178 179 cont: ; preds = %ehcleanup 180 call void @_Unwind_Resume_or_Rethrow(i8* %exc1) 181 unreachable 182 183 cond.false: ; preds = %entry 184 %tmp4 = getelementptr inbounds %class.RuleBasedBreakIterator* %this, i32 0, i32 0 ; <i64 ()**> [#uses=1] 185 %tmp5 = load i64 ()** %tmp4 ; <i64 ()*> [#uses=1] 186 %call = invoke i64 %tmp5() 187 to label %cond.end unwind label %ehcleanup ; <i64> [#uses=1] 188 189 cond.end: ; preds = %cond.false, %entry 190 %cond = phi i64 [ 0, %entry ], [ %call, %cond.false ] ; <i64> [#uses=1] 191 %conv = trunc i64 %cond to i32 ; <i32> [#uses=1] 192 call void @_ZN6UStackD1Ev(%class.UStack* %breaks) 193 ret i32 %conv 194 } 195 196 declare void @_ZN6UStackC1Ei(%class.UStack*, i32) 197 198 declare void @_ZN6UStackD1Ev(%class.UStack*) 199 200 declare i32 @__gxx_personality_v0(...) 201 202 declare i8* @llvm.eh.exception() nounwind readonly 203 204 declare i32 @llvm.eh.selector(i8*, i8*, ...) nounwind 205 206 declare void @_ZSt9terminatev() 207 208 declare void @_Unwind_Resume_or_Rethrow(i8*) 209 210 211 212 ; rdar://7590304 213 define i8* @test10(i8* %self, i8* %tmp3) { 214 entry: 215 store i1 true, i1* undef 216 store i1 true, i1* undef 217 invoke void @test10a() 218 to label %invoke.cont unwind label %try.handler ; <i8*> [#uses=0] 219 220 invoke.cont: ; preds = %entry 221 unreachable 222 223 try.handler: ; preds = %entry 224 %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0 225 catch i8* null 226 ret i8* %self 227 } 228 229 define void @test10a() { 230 ret void 231 } 232 233 234 ; PR6193 235 define i32 @test11(i32 %aMaskWidth, i8 %aStride) nounwind { 236 entry: 237 %conv41 = sext i8 %aStride to i32 238 %neg = xor i32 %conv41, -1 239 %and42 = and i32 %aMaskWidth, %neg 240 %and47 = and i32 130, %conv41 241 %or = or i32 %and42, %and47 242 ret i32 %or 243 } 244 245 ; PR6503 246 define void @test12(i32* %A) nounwind { 247 entry: 248 %tmp1 = load i32* %A 249 %cmp = icmp ugt i32 1, %tmp1 ; <i1> [#uses=1] 250 %conv = zext i1 %cmp to i32 ; <i32> [#uses=1] 251 %tmp2 = load i32* %A 252 %cmp3 = icmp ne i32 %tmp2, 0 ; <i1> [#uses=1] 253 %conv4 = zext i1 %cmp3 to i32 ; <i32> [#uses=1] 254 %or = or i32 %conv, %conv4 ; <i32> [#uses=1] 255 %cmp5 = icmp ugt i32 undef, %or ; <i1> [#uses=1] 256 %conv6 = zext i1 %cmp5 to i32 ; <i32> [#uses=0] 257 ret void 258 } 259 260 %s1 = type { %s2, %s2, [6 x %s2], i32, i32, i32, [1 x i32], [0 x i8] } 261 %s2 = type { i64 } 262 define void @test13() nounwind ssp { 263 entry: 264 %0 = getelementptr inbounds %s1* null, i64 0, i32 2, i64 0, i32 0 265 %1 = bitcast i64* %0 to i32* 266 %2 = getelementptr inbounds %s1* null, i64 0, i32 2, i64 1, i32 0 267 %.pre = load i32* %1, align 8 268 %3 = lshr i32 %.pre, 19 269 %brmerge = or i1 undef, undef 270 %4 = and i32 %3, 3 271 %5 = add nsw i32 %4, 1 272 %6 = shl i32 %5, 19 273 %7 = add i32 %6, 1572864 274 %8 = and i32 %7, 1572864 275 %9 = load i64* %2, align 8 276 %trunc156 = trunc i64 %9 to i32 277 %10 = and i32 %trunc156, -1537 278 %11 = and i32 %10, -6145 279 %12 = or i32 %11, 2048 280 %13 = and i32 %12, -24577 281 %14 = or i32 %13, 16384 282 %15 = or i32 %14, 98304 283 store i32 %15, i32* undef, align 8 284 %16 = and i32 %15, -1572865 285 %17 = or i32 %16, %8 286 store i32 %17, i32* undef, align 8 287 %18 = and i32 %17, -449 288 %19 = or i32 %18, 64 289 store i32 %19, i32* undef, align 8 290 unreachable 291 } 292 293 294 ; PR8807 295 declare i32 @test14f(i8* (i8*)*) nounwind 296 297 define void @test14() nounwind readnone { 298 entry: 299 %tmp = bitcast i32 (i8* (i8*)*)* @test14f to i32 (i32*)* 300 %call10 = call i32 %tmp(i32* byval undef) 301 ret void 302 } 303 304 305 ; PR8896 306 @g_54 = external global [7 x i16] 307 308 define void @test15(i32* %p_92) nounwind { 309 entry: 310 %0 = load i32* %p_92, align 4 311 %1 = icmp ne i32 %0, 0 312 %2 = zext i1 %1 to i32 313 %3 = call i32 @func_14() nounwind 314 %4 = trunc i32 %3 to i16 315 %5 = sext i16 %4 to i32 316 %6 = trunc i32 %5 to i16 317 br i1 undef, label %"3", label %"5" 318 319 "3": ; preds = %entry 320 %7 = sext i16 %6 to i32 321 %8 = ashr i32 %7, -1649554541 322 %9 = trunc i32 %8 to i16 323 br label %"5" 324 325 "5": ; preds = %"3", %entry 326 %10 = phi i16 [ %9, %"3" ], [ %6, %entry ] 327 %11 = sext i16 %10 to i32 328 %12 = xor i32 %2, %11 329 %13 = sext i32 %12 to i64 330 %14 = icmp ne i64 %13, 0 331 br i1 %14, label %return, label %"7" 332 333 "7": ; preds = %"5" 334 ret void 335 336 return: ; preds = %"5" 337 ret void 338 } 339 340 declare i32 @func_14() 341 342 343 define double @test16(i32 %a) nounwind { 344 %cmp = icmp slt i32 %a, 2 345 %select = select i1 %cmp, double 2.000000e+00, double 3.141592e+00 346 ret double %select 347 } 348 349 350 ; PR8983 351 %struct.basic_ios = type { i8 } 352 353 define %struct.basic_ios *@test17() ssp { 354 entry: 355 %add.ptr.i = getelementptr i8* null, i64 undef 356 %0 = bitcast i8* %add.ptr.i to %struct.basic_ios* 357 ret %struct.basic_ios* %0 358 } 359 360 ; PR9013 361 define void @test18() nounwind ssp { 362 entry: 363 br label %for.cond 364 365 for.cond: ; preds = %for.inc, %entry 366 %l_197.0 = phi i32 [ 0, %entry ], [ %sub.i, %for.inc ] 367 br label %for.inc 368 369 for.inc: ; preds = %for.cond 370 %conv = and i32 %l_197.0, 255 371 %sub.i = add nsw i32 %conv, -1 372 br label %for.cond 373 374 return: ; No predecessors! 375 ret void 376 } 377 378 ; PR11275 379 declare void @test18b() noreturn 380 declare void @test18foo(double**) 381 declare void @test18a() noreturn 382 define fastcc void @test18x(i8* %t0, i1 %b) uwtable align 2 { 383 entry: 384 br i1 %b, label %e1, label %e2 385 e1: 386 %t2 = bitcast i8* %t0 to double** 387 invoke void @test18b() noreturn 388 to label %u unwind label %lpad 389 e2: 390 %t4 = bitcast i8* %t0 to double** 391 invoke void @test18a() noreturn 392 to label %u unwind label %lpad 393 lpad: 394 %t5 = phi double** [ %t2, %e1 ], [ %t4, %e2 ] 395 %lpad.nonloopexit262 = landingpad { i8*, i32 } personality i32 (...)* @__gxx_personality_v0 396 cleanup 397 call void @test18foo(double** %t5) 398 unreachable 399 u: 400 unreachable 401 } 402