1 ; RUN: opt < %s -instcombine -S | FileCheck %s 2 3 target datalayout = 4 "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" 5 6 define i32 @test1(i32 %X) { 7 entry: 8 icmp slt i32 %X, 0 ; <i1>:0 [#uses=1] 9 zext i1 %0 to i32 ; <i32>:1 [#uses=1] 10 ret i32 %1 11 ; CHECK-LABEL: @test1( 12 ; CHECK: lshr i32 %X, 31 13 ; CHECK-NEXT: ret i32 14 } 15 16 define i32 @test2(i32 %X) { 17 entry: 18 icmp ult i32 %X, -2147483648 ; <i1>:0 [#uses=1] 19 zext i1 %0 to i32 ; <i32>:1 [#uses=1] 20 ret i32 %1 21 ; CHECK-LABEL: @test2( 22 ; CHECK: lshr i32 %X, 31 23 ; CHECK-NEXT: xor i32 24 ; CHECK-NEXT: ret i32 25 } 26 27 define i32 @test3(i32 %X) { 28 entry: 29 icmp slt i32 %X, 0 ; <i1>:0 [#uses=1] 30 sext i1 %0 to i32 ; <i32>:1 [#uses=1] 31 ret i32 %1 32 ; CHECK-LABEL: @test3( 33 ; CHECK: ashr i32 %X, 31 34 ; CHECK-NEXT: ret i32 35 } 36 37 define i32 @test4(i32 %X) { 38 entry: 39 icmp ult i32 %X, -2147483648 ; <i1>:0 [#uses=1] 40 sext i1 %0 to i32 ; <i32>:1 [#uses=1] 41 ret i32 %1 42 ; CHECK-LABEL: @test4( 43 ; CHECK: ashr i32 %X, 31 44 ; CHECK-NEXT: xor i32 45 ; CHECK-NEXT: ret i32 46 } 47 48 ; PR4837 49 define <2 x i1> @test5(<2 x i64> %x) { 50 entry: 51 %V = icmp eq <2 x i64> %x, undef 52 ret <2 x i1> %V 53 ; CHECK-LABEL: @test5( 54 ; CHECK: ret <2 x i1> <i1 true, i1 true> 55 } 56 57 define i32 @test6(i32 %a, i32 %b) { 58 %c = icmp sle i32 %a, -1 59 %d = zext i1 %c to i32 60 %e = sub i32 0, %d 61 %f = and i32 %e, %b 62 ret i32 %f 63 ; CHECK-LABEL: @test6( 64 ; CHECK-NEXT: ashr i32 %a, 31 65 ; CHECK-NEXT: %f = and i32 %e, %b 66 ; CHECK-NEXT: ret i32 %f 67 } 68 69 70 define i1 @test7(i32 %x) { 71 entry: 72 %a = add i32 %x, -1 73 %b = icmp ult i32 %a, %x 74 ret i1 %b 75 ; CHECK-LABEL: @test7( 76 ; CHECK: %b = icmp ne i32 %x, 0 77 ; CHECK: ret i1 %b 78 } 79 80 define i1 @test8(i32 %x){ 81 entry: 82 %a = add i32 %x, -1 83 %b = icmp eq i32 %a, %x 84 ret i1 %b 85 ; CHECK-LABEL: @test8( 86 ; CHECK: ret i1 false 87 } 88 89 define i1 @test9(i32 %x) { 90 entry: 91 %a = add i32 %x, -2 92 %b = icmp ugt i32 %x, %a 93 ret i1 %b 94 ; CHECK-LABEL: @test9( 95 ; CHECK: icmp ugt i32 %x, 1 96 ; CHECK: ret i1 %b 97 } 98 99 define i1 @test10(i32 %x){ 100 entry: 101 %a = add i32 %x, -1 102 %b = icmp slt i32 %a, %x 103 ret i1 %b 104 105 ; CHECK-LABEL: @test10( 106 ; CHECK: %b = icmp ne i32 %x, -2147483648 107 ; CHECK: ret i1 %b 108 } 109 110 define i1 @test11(i32 %x) { 111 %a = add nsw i32 %x, 8 112 %b = icmp slt i32 %x, %a 113 ret i1 %b 114 ; CHECK-LABEL: @test11( 115 ; CHECK: ret i1 true 116 } 117 118 ; PR6195 119 define i1 @test12(i1 %A) { 120 %S = select i1 %A, i64 -4294967295, i64 8589934591 121 %B = icmp ne i64 bitcast (<2 x i32> <i32 1, i32 -1> to i64), %S 122 ret i1 %B 123 ; CHECK-LABEL: @test12( 124 ; CHECK-NEXT: = xor i1 %A, true 125 ; CHECK-NEXT: ret i1 126 } 127 128 ; PR6481 129 define i1 @test13(i8 %X) nounwind readnone { 130 entry: 131 %cmp = icmp slt i8 undef, %X 132 ret i1 %cmp 133 ; CHECK-LABEL: @test13( 134 ; CHECK: ret i1 false 135 } 136 137 define i1 @test14(i8 %X) nounwind readnone { 138 entry: 139 %cmp = icmp slt i8 undef, -128 140 ret i1 %cmp 141 ; CHECK-LABEL: @test14( 142 ; CHECK: ret i1 false 143 } 144 145 define i1 @test15() nounwind readnone { 146 entry: 147 %cmp = icmp eq i8 undef, -128 148 ret i1 %cmp 149 ; CHECK-LABEL: @test15( 150 ; CHECK: ret i1 undef 151 } 152 153 define i1 @test16() nounwind readnone { 154 entry: 155 %cmp = icmp ne i8 undef, -128 156 ret i1 %cmp 157 ; CHECK-LABEL: @test16( 158 ; CHECK: ret i1 undef 159 } 160 161 define i1 @test17(i32 %x) nounwind { 162 %shl = shl i32 1, %x 163 %and = and i32 %shl, 8 164 %cmp = icmp eq i32 %and, 0 165 ret i1 %cmp 166 ; CHECK-LABEL: @test17( 167 ; CHECK-NEXT: %cmp = icmp ne i32 %x, 3 168 } 169 170 171 define i1 @test18(i32 %x) nounwind { 172 %sh = lshr i32 8, %x 173 %and = and i32 %sh, 1 174 %cmp = icmp eq i32 %and, 0 175 ret i1 %cmp 176 ; CHECK-LABEL: @test18( 177 ; CHECK-NEXT: %cmp = icmp ne i32 %x, 3 178 } 179 180 define i1 @test19(i32 %x) nounwind { 181 %shl = shl i32 1, %x 182 %and = and i32 %shl, 8 183 %cmp = icmp eq i32 %and, 8 184 ret i1 %cmp 185 ; CHECK-LABEL: @test19( 186 ; CHECK-NEXT: %cmp = icmp eq i32 %x, 3 187 } 188 189 define i1 @test20(i32 %x) nounwind { 190 %shl = shl i32 1, %x 191 %and = and i32 %shl, 8 192 %cmp = icmp ne i32 %and, 0 193 ret i1 %cmp 194 ; CHECK-LABEL: @test20( 195 ; CHECK-NEXT: %cmp = icmp eq i32 %x, 3 196 } 197 198 define i1 @test21(i8 %x, i8 %y) { 199 ; CHECK-LABEL: @test21( 200 ; CHECK-NOT: or i8 201 ; CHECK: icmp ugt 202 %A = or i8 %x, 1 203 %B = icmp ugt i8 %A, 3 204 ret i1 %B 205 } 206 207 define i1 @test22(i8 %x, i8 %y) { 208 ; CHECK-LABEL: @test22( 209 ; CHECK-NOT: or i8 210 ; CHECK: icmp ult 211 %A = or i8 %x, 1 212 %B = icmp ult i8 %A, 4 213 ret i1 %B 214 } 215 216 ; PR2740 217 ; CHECK-LABEL: @test23( 218 ; CHECK: icmp sgt i32 %x, 1328634634 219 define i1 @test23(i32 %x) nounwind { 220 %i3 = sdiv i32 %x, -1328634635 221 %i4 = icmp eq i32 %i3, -1 222 ret i1 %i4 223 } 224 225 @X = global [1000 x i32] zeroinitializer 226 227 ; PR8882 228 ; CHECK-LABEL: @test24( 229 ; CHECK: %cmp = icmp eq i64 %i, 1000 230 ; CHECK: ret i1 %cmp 231 define i1 @test24(i64 %i) { 232 %p1 = getelementptr inbounds i32* getelementptr inbounds ([1000 x i32]* @X, i64 0, i64 0), i64 %i 233 %cmp = icmp eq i32* %p1, getelementptr inbounds ([1000 x i32]* @X, i64 1, i64 0) 234 ret i1 %cmp 235 } 236 237 ; CHECK-LABEL: @test25( 238 ; X + Z > Y + Z -> X > Y if there is no overflow. 239 ; CHECK: %c = icmp sgt i32 %x, %y 240 ; CHECK: ret i1 %c 241 define i1 @test25(i32 %x, i32 %y, i32 %z) { 242 %lhs = add nsw i32 %x, %z 243 %rhs = add nsw i32 %y, %z 244 %c = icmp sgt i32 %lhs, %rhs 245 ret i1 %c 246 } 247 248 ; CHECK-LABEL: @test26( 249 ; X + Z > Y + Z -> X > Y if there is no overflow. 250 ; CHECK: %c = icmp ugt i32 %x, %y 251 ; CHECK: ret i1 %c 252 define i1 @test26(i32 %x, i32 %y, i32 %z) { 253 %lhs = add nuw i32 %x, %z 254 %rhs = add nuw i32 %y, %z 255 %c = icmp ugt i32 %lhs, %rhs 256 ret i1 %c 257 } 258 259 ; CHECK-LABEL: @test27( 260 ; X - Z > Y - Z -> X > Y if there is no overflow. 261 ; CHECK: %c = icmp sgt i32 %x, %y 262 ; CHECK: ret i1 %c 263 define i1 @test27(i32 %x, i32 %y, i32 %z) { 264 %lhs = sub nsw i32 %x, %z 265 %rhs = sub nsw i32 %y, %z 266 %c = icmp sgt i32 %lhs, %rhs 267 ret i1 %c 268 } 269 270 ; CHECK-LABEL: @test28( 271 ; X - Z > Y - Z -> X > Y if there is no overflow. 272 ; CHECK: %c = icmp ugt i32 %x, %y 273 ; CHECK: ret i1 %c 274 define i1 @test28(i32 %x, i32 %y, i32 %z) { 275 %lhs = sub nuw i32 %x, %z 276 %rhs = sub nuw i32 %y, %z 277 %c = icmp ugt i32 %lhs, %rhs 278 ret i1 %c 279 } 280 281 ; CHECK-LABEL: @test29( 282 ; X + Y > X -> Y > 0 if there is no overflow. 283 ; CHECK: %c = icmp sgt i32 %y, 0 284 ; CHECK: ret i1 %c 285 define i1 @test29(i32 %x, i32 %y) { 286 %lhs = add nsw i32 %x, %y 287 %c = icmp sgt i32 %lhs, %x 288 ret i1 %c 289 } 290 291 ; CHECK-LABEL: @test30( 292 ; X + Y > X -> Y > 0 if there is no overflow. 293 ; CHECK: %c = icmp ne i32 %y, 0 294 ; CHECK: ret i1 %c 295 define i1 @test30(i32 %x, i32 %y) { 296 %lhs = add nuw i32 %x, %y 297 %c = icmp ugt i32 %lhs, %x 298 ret i1 %c 299 } 300 301 ; CHECK-LABEL: @test31( 302 ; X > X + Y -> 0 > Y if there is no overflow. 303 ; CHECK: %c = icmp slt i32 %y, 0 304 ; CHECK: ret i1 %c 305 define i1 @test31(i32 %x, i32 %y) { 306 %rhs = add nsw i32 %x, %y 307 %c = icmp sgt i32 %x, %rhs 308 ret i1 %c 309 } 310 311 ; CHECK-LABEL: @test32( 312 ; X > X + Y -> 0 > Y if there is no overflow. 313 ; CHECK: ret i1 false 314 define i1 @test32(i32 %x, i32 %y) { 315 %rhs = add nuw i32 %x, %y 316 %c = icmp ugt i32 %x, %rhs 317 ret i1 %c 318 } 319 320 ; CHECK-LABEL: @test33( 321 ; X - Y > X -> 0 > Y if there is no overflow. 322 ; CHECK: %c = icmp slt i32 %y, 0 323 ; CHECK: ret i1 %c 324 define i1 @test33(i32 %x, i32 %y) { 325 %lhs = sub nsw i32 %x, %y 326 %c = icmp sgt i32 %lhs, %x 327 ret i1 %c 328 } 329 330 ; CHECK-LABEL: @test34( 331 ; X - Y > X -> 0 > Y if there is no overflow. 332 ; CHECK: ret i1 false 333 define i1 @test34(i32 %x, i32 %y) { 334 %lhs = sub nuw i32 %x, %y 335 %c = icmp ugt i32 %lhs, %x 336 ret i1 %c 337 } 338 339 ; CHECK-LABEL: @test35( 340 ; X > X - Y -> Y > 0 if there is no overflow. 341 ; CHECK: %c = icmp sgt i32 %y, 0 342 ; CHECK: ret i1 %c 343 define i1 @test35(i32 %x, i32 %y) { 344 %rhs = sub nsw i32 %x, %y 345 %c = icmp sgt i32 %x, %rhs 346 ret i1 %c 347 } 348 349 ; CHECK-LABEL: @test36( 350 ; X > X - Y -> Y > 0 if there is no overflow. 351 ; CHECK: %c = icmp ne i32 %y, 0 352 ; CHECK: ret i1 %c 353 define i1 @test36(i32 %x, i32 %y) { 354 %rhs = sub nuw i32 %x, %y 355 %c = icmp ugt i32 %x, %rhs 356 ret i1 %c 357 } 358 359 ; CHECK-LABEL: @test37( 360 ; X - Y > X - Z -> Z > Y if there is no overflow. 361 ; CHECK: %c = icmp sgt i32 %z, %y 362 ; CHECK: ret i1 %c 363 define i1 @test37(i32 %x, i32 %y, i32 %z) { 364 %lhs = sub nsw i32 %x, %y 365 %rhs = sub nsw i32 %x, %z 366 %c = icmp sgt i32 %lhs, %rhs 367 ret i1 %c 368 } 369 370 ; CHECK-LABEL: @test38( 371 ; X - Y > X - Z -> Z > Y if there is no overflow. 372 ; CHECK: %c = icmp ugt i32 %z, %y 373 ; CHECK: ret i1 %c 374 define i1 @test38(i32 %x, i32 %y, i32 %z) { 375 %lhs = sub nuw i32 %x, %y 376 %rhs = sub nuw i32 %x, %z 377 %c = icmp ugt i32 %lhs, %rhs 378 ret i1 %c 379 } 380 381 ; PR9343 #1 382 ; CHECK-LABEL: @test39( 383 ; CHECK: %B = icmp eq i32 %X, 0 384 define i1 @test39(i32 %X, i32 %Y) { 385 %A = ashr exact i32 %X, %Y 386 %B = icmp eq i32 %A, 0 387 ret i1 %B 388 } 389 390 ; CHECK-LABEL: @test40( 391 ; CHECK: %B = icmp ne i32 %X, 0 392 define i1 @test40(i32 %X, i32 %Y) { 393 %A = lshr exact i32 %X, %Y 394 %B = icmp ne i32 %A, 0 395 ret i1 %B 396 } 397 398 ; PR9343 #3 399 ; CHECK-LABEL: @test41( 400 ; CHECK: ret i1 true 401 define i1 @test41(i32 %X, i32 %Y) { 402 %A = urem i32 %X, %Y 403 %B = icmp ugt i32 %Y, %A 404 ret i1 %B 405 } 406 407 ; CHECK-LABEL: @test42( 408 ; CHECK: %B = icmp sgt i32 %Y, -1 409 define i1 @test42(i32 %X, i32 %Y) { 410 %A = srem i32 %X, %Y 411 %B = icmp slt i32 %A, %Y 412 ret i1 %B 413 } 414 415 ; CHECK-LABEL: @test43( 416 ; CHECK: %B = icmp slt i32 %Y, 0 417 define i1 @test43(i32 %X, i32 %Y) { 418 %A = srem i32 %X, %Y 419 %B = icmp slt i32 %Y, %A 420 ret i1 %B 421 } 422 423 ; CHECK-LABEL: @test44( 424 ; CHECK: %B = icmp sgt i32 %Y, -1 425 define i1 @test44(i32 %X, i32 %Y) { 426 %A = srem i32 %X, %Y 427 %B = icmp slt i32 %A, %Y 428 ret i1 %B 429 } 430 431 ; CHECK-LABEL: @test45( 432 ; CHECK: %B = icmp slt i32 %Y, 0 433 define i1 @test45(i32 %X, i32 %Y) { 434 %A = srem i32 %X, %Y 435 %B = icmp slt i32 %Y, %A 436 ret i1 %B 437 } 438 439 ; PR9343 #4 440 ; CHECK-LABEL: @test46( 441 ; CHECK: %C = icmp ult i32 %X, %Y 442 define i1 @test46(i32 %X, i32 %Y, i32 %Z) { 443 %A = ashr exact i32 %X, %Z 444 %B = ashr exact i32 %Y, %Z 445 %C = icmp ult i32 %A, %B 446 ret i1 %C 447 } 448 449 ; PR9343 #5 450 ; CHECK-LABEL: @test47( 451 ; CHECK: %C = icmp ugt i32 %X, %Y 452 define i1 @test47(i32 %X, i32 %Y, i32 %Z) { 453 %A = ashr exact i32 %X, %Z 454 %B = ashr exact i32 %Y, %Z 455 %C = icmp ugt i32 %A, %B 456 ret i1 %C 457 } 458 459 ; PR9343 #8 460 ; CHECK-LABEL: @test48( 461 ; CHECK: %C = icmp eq i32 %X, %Y 462 define i1 @test48(i32 %X, i32 %Y, i32 %Z) { 463 %A = sdiv exact i32 %X, %Z 464 %B = sdiv exact i32 %Y, %Z 465 %C = icmp eq i32 %A, %B 466 ret i1 %C 467 } 468 469 ; PR8469 470 ; CHECK-LABEL: @test49( 471 ; CHECK: ret <2 x i1> <i1 true, i1 true> 472 define <2 x i1> @test49(<2 x i32> %tmp3) { 473 entry: 474 %tmp11 = and <2 x i32> %tmp3, <i32 3, i32 3> 475 %cmp = icmp ult <2 x i32> %tmp11, <i32 4, i32 4> 476 ret <2 x i1> %cmp 477 } 478 479 ; PR9343 #7 480 ; CHECK-LABEL: @test50( 481 ; CHECK: ret i1 true 482 define i1 @test50(i16 %X, i32 %Y) { 483 %A = zext i16 %X to i32 484 %B = srem i32 %A, %Y 485 %C = icmp sgt i32 %B, -1 486 ret i1 %C 487 } 488 489 ; CHECK-LABEL: @test51( 490 ; CHECK: ret i1 %C 491 define i1 @test51(i32 %X, i32 %Y) { 492 %A = and i32 %X, 2147483648 493 %B = srem i32 %A, %Y 494 %C = icmp sgt i32 %B, -1 495 ret i1 %C 496 } 497 498 ; CHECK-LABEL: @test52( 499 ; CHECK-NEXT: and i32 %x1, 16711935 500 ; CHECK-NEXT: icmp eq i32 {{.*}}, 4980863 501 ; CHECK-NEXT: ret i1 502 define i1 @test52(i32 %x1) nounwind { 503 %conv = and i32 %x1, 255 504 %cmp = icmp eq i32 %conv, 127 505 %tmp2 = lshr i32 %x1, 16 506 %tmp3 = trunc i32 %tmp2 to i8 507 %cmp15 = icmp eq i8 %tmp3, 76 508 509 %A = and i1 %cmp, %cmp15 510 ret i1 %A 511 } 512 513 ; PR9838 514 ; CHECK-LABEL: @test53( 515 ; CHECK-NEXT: ashr exact 516 ; CHECK-NEXT: ashr 517 ; CHECK-NEXT: icmp 518 define i1 @test53(i32 %a, i32 %b) nounwind { 519 %x = ashr exact i32 %a, 30 520 %y = ashr i32 %b, 30 521 %z = icmp eq i32 %x, %y 522 ret i1 %z 523 } 524 525 ; CHECK-LABEL: @test54( 526 ; CHECK-NEXT: %and = and i8 %a, -64 527 ; CHECK-NEXT: icmp eq i8 %and, -128 528 define i1 @test54(i8 %a) nounwind { 529 %ext = zext i8 %a to i32 530 %and = and i32 %ext, 192 531 %ret = icmp eq i32 %and, 128 532 ret i1 %ret 533 } 534 535 ; CHECK-LABEL: @test55( 536 ; CHECK-NEXT: icmp eq i32 %a, -123 537 define i1 @test55(i32 %a) { 538 %sub = sub i32 0, %a 539 %cmp = icmp eq i32 %sub, 123 540 ret i1 %cmp 541 } 542 543 ; CHECK-LABEL: @test56( 544 ; CHECK-NEXT: icmp eq i32 %a, -113 545 define i1 @test56(i32 %a) { 546 %sub = sub i32 10, %a 547 %cmp = icmp eq i32 %sub, 123 548 ret i1 %cmp 549 } 550 551 ; PR10267 Don't make icmps more expensive when no other inst is subsumed. 552 declare void @foo(i32) 553 ; CHECK-LABEL: @test57( 554 ; CHECK: %and = and i32 %a, -2 555 ; CHECK: %cmp = icmp ne i32 %and, 0 556 define i1 @test57(i32 %a) { 557 %and = and i32 %a, -2 558 %cmp = icmp ne i32 %and, 0 559 call void @foo(i32 %and) 560 ret i1 %cmp 561 } 562 563 ; rdar://problem/10482509 564 ; CHECK-LABEL: @cmpabs1( 565 ; CHECK-NEXT: icmp ne 566 define zeroext i1 @cmpabs1(i64 %val) { 567 %sub = sub nsw i64 0, %val 568 %cmp = icmp slt i64 %val, 0 569 %sub.val = select i1 %cmp, i64 %sub, i64 %val 570 %tobool = icmp ne i64 %sub.val, 0 571 ret i1 %tobool 572 } 573 574 ; CHECK-LABEL: @cmpabs2( 575 ; CHECK-NEXT: icmp ne 576 define zeroext i1 @cmpabs2(i64 %val) { 577 %sub = sub nsw i64 0, %val 578 %cmp = icmp slt i64 %val, 0 579 %sub.val = select i1 %cmp, i64 %val, i64 %sub 580 %tobool = icmp ne i64 %sub.val, 0 581 ret i1 %tobool 582 } 583 584 ; CHECK-LABEL: @test58( 585 ; CHECK-NEXT: call i32 @test58_d(i64 36029346783166592) 586 define void @test58() nounwind { 587 %cast = bitcast <1 x i64> <i64 36029346783166592> to i64 588 %call = call i32 @test58_d( i64 %cast) nounwind 589 ret void 590 } 591 declare i32 @test58_d(i64) 592 593 define i1 @test59(i8* %foo) { 594 %bit = bitcast i8* %foo to i32* 595 %gep1 = getelementptr inbounds i32* %bit, i64 2 596 %gep2 = getelementptr inbounds i8* %foo, i64 10 597 %cast1 = bitcast i32* %gep1 to i8* 598 %cmp = icmp ult i8* %cast1, %gep2 599 %use = ptrtoint i8* %cast1 to i64 600 %call = call i32 @test58_d(i64 %use) nounwind 601 ret i1 %cmp 602 ; CHECK-LABEL: @test59( 603 ; CHECK: ret i1 true 604 } 605 606 define i1 @test60(i8* %foo, i64 %i, i64 %j) { 607 %bit = bitcast i8* %foo to i32* 608 %gep1 = getelementptr inbounds i32* %bit, i64 %i 609 %gep2 = getelementptr inbounds i8* %foo, i64 %j 610 %cast1 = bitcast i32* %gep1 to i8* 611 %cmp = icmp ult i8* %cast1, %gep2 612 ret i1 %cmp 613 ; CHECK-LABEL: @test60( 614 ; CHECK-NEXT: %gep1.idx = shl nuw i64 %i, 2 615 ; CHECK-NEXT: icmp slt i64 %gep1.idx, %j 616 ; CHECK-NEXT: ret i1 617 } 618 619 define i1 @test61(i8* %foo, i64 %i, i64 %j) { 620 %bit = bitcast i8* %foo to i32* 621 %gep1 = getelementptr i32* %bit, i64 %i 622 %gep2 = getelementptr i8* %foo, i64 %j 623 %cast1 = bitcast i32* %gep1 to i8* 624 %cmp = icmp ult i8* %cast1, %gep2 625 ret i1 %cmp 626 ; Don't transform non-inbounds GEPs. 627 ; CHECK-LABEL: @test61( 628 ; CHECK: icmp ult i8* %cast1, %gep2 629 ; CHECK-NEXT: ret i1 630 } 631 632 define i1 @test62(i8* %a) { 633 %arrayidx1 = getelementptr inbounds i8* %a, i64 1 634 %arrayidx2 = getelementptr inbounds i8* %a, i64 10 635 %cmp = icmp slt i8* %arrayidx1, %arrayidx2 636 ret i1 %cmp 637 ; CHECK-LABEL: @test62( 638 ; CHECK-NEXT: ret i1 true 639 } 640 641 define i1 @test63(i8 %a, i32 %b) nounwind { 642 %z = zext i8 %a to i32 643 %t = and i32 %b, 255 644 %c = icmp eq i32 %z, %t 645 ret i1 %c 646 ; CHECK-LABEL: @test63( 647 ; CHECK-NEXT: %1 = trunc i32 %b to i8 648 ; CHECK-NEXT: %c = icmp eq i8 %1, %a 649 ; CHECK-NEXT: ret i1 %c 650 } 651 652 define i1 @test64(i8 %a, i32 %b) nounwind { 653 %t = and i32 %b, 255 654 %z = zext i8 %a to i32 655 %c = icmp eq i32 %t, %z 656 ret i1 %c 657 ; CHECK-LABEL: @test64( 658 ; CHECK-NEXT: %1 = trunc i32 %b to i8 659 ; CHECK-NEXT: %c = icmp eq i8 %1, %a 660 ; CHECK-NEXT: ret i1 %c 661 } 662 663 define i1 @test65(i64 %A, i64 %B) { 664 %s1 = add i64 %A, %B 665 %s2 = add i64 %A, %B 666 %cmp = icmp eq i64 %s1, %s2 667 ; CHECK-LABEL: @test65( 668 ; CHECK-NEXT: ret i1 true 669 ret i1 %cmp 670 } 671 672 define i1 @test66(i64 %A, i64 %B) { 673 %s1 = add i64 %A, %B 674 %s2 = add i64 %B, %A 675 %cmp = icmp eq i64 %s1, %s2 676 ; CHECK-LABEL: @test66( 677 ; CHECK-NEXT: ret i1 true 678 ret i1 %cmp 679 } 680 681 ; CHECK-LABEL: @test67( 682 ; CHECK: %and = and i32 %x, 96 683 ; CHECK: %cmp = icmp ne i32 %and, 0 684 define i1 @test67(i32 %x) nounwind uwtable { 685 %and = and i32 %x, 127 686 %cmp = icmp sgt i32 %and, 31 687 ret i1 %cmp 688 } 689 690 ; CHECK-LABEL: @test68( 691 ; CHECK: %cmp = icmp ugt i32 %and, 30 692 define i1 @test68(i32 %x) nounwind uwtable { 693 %and = and i32 %x, 127 694 %cmp = icmp sgt i32 %and, 30 695 ret i1 %cmp 696 } 697 698 ; PR14708 699 ; CHECK-LABEL: @test69( 700 ; CHECK: %1 = and i32 %c, -33 701 ; CHECK: %2 = icmp eq i32 %1, 65 702 ; CHECK: ret i1 %2 703 define i1 @test69(i32 %c) nounwind uwtable { 704 %1 = icmp eq i32 %c, 97 705 %2 = icmp eq i32 %c, 65 706 %3 = or i1 %1, %2 707 ret i1 %3 708 } 709 710 ; PR15940 711 ; CHECK-LABEL: @test70( 712 ; CHECK-NEXT: %A = srem i32 5, %X 713 ; CHECK-NEXT: %C = icmp ne i32 %A, 2 714 ; CHECK-NEXT: ret i1 %C 715 define i1 @test70(i32 %X) { 716 %A = srem i32 5, %X 717 %B = add i32 %A, 2 718 %C = icmp ne i32 %B, 4 719 ret i1 %C 720 } 721 722 ; CHECK-LABEL: @icmp_sext16trunc( 723 ; CHECK-NEXT: %1 = trunc i32 %x to i16 724 ; CHECK-NEXT: %cmp = icmp slt i16 %1, 36 725 define i1 @icmp_sext16trunc(i32 %x) { 726 %trunc = trunc i32 %x to i16 727 %sext = sext i16 %trunc to i32 728 %cmp = icmp slt i32 %sext, 36 729 ret i1 %cmp 730 } 731 732 ; CHECK-LABEL: @icmp_sext8trunc( 733 ; CHECK-NEXT: %1 = trunc i32 %x to i8 734 ; CHECK-NEXT: %cmp = icmp slt i8 %1, 36 735 define i1 @icmp_sext8trunc(i32 %x) { 736 %trunc = trunc i32 %x to i8 737 %sext = sext i8 %trunc to i32 738 %cmp = icmp slt i32 %sext, 36 739 ret i1 %cmp 740 } 741 742 ; CHECK-LABEL: @icmp_shl16( 743 ; CHECK-NEXT: %1 = trunc i32 %x to i16 744 ; CHECK-NEXT: %cmp = icmp slt i16 %1, 36 745 define i1 @icmp_shl16(i32 %x) { 746 %shl = shl i32 %x, 16 747 %cmp = icmp slt i32 %shl, 2359296 748 ret i1 %cmp 749 } 750 751 ; CHECK-LABEL: @icmp_shl24( 752 ; CHECK-NEXT: %1 = trunc i32 %x to i8 753 ; CHECK-NEXT: %cmp = icmp slt i8 %1, 36 754 define i1 @icmp_shl24(i32 %x) { 755 %shl = shl i32 %x, 24 756 %cmp = icmp slt i32 %shl, 603979776 757 ret i1 %cmp 758 } 759 760 ; If the (shl x, C) preserved the sign and this is a sign test, 761 ; compare the LHS operand instead 762 ; CHECK-LABEL: @icmp_shl_nsw_sgt( 763 ; CHECK-NEXT: icmp sgt i32 %x, 0 764 define i1 @icmp_shl_nsw_sgt(i32 %x) { 765 %shl = shl nsw i32 %x, 21 766 %cmp = icmp sgt i32 %shl, 0 767 ret i1 %cmp 768 } 769 770 ; CHECK-LABEL: @icmp_shl_nsw_sge0( 771 ; CHECK-NEXT: icmp sgt i32 %x, -1 772 define i1 @icmp_shl_nsw_sge0(i32 %x) { 773 %shl = shl nsw i32 %x, 21 774 %cmp = icmp sge i32 %shl, 0 775 ret i1 %cmp 776 } 777 778 ; CHECK-LABEL: @icmp_shl_nsw_sge1( 779 ; CHECK-NEXT: icmp sgt i32 %x, 0 780 define i1 @icmp_shl_nsw_sge1(i32 %x) { 781 %shl = shl nsw i32 %x, 21 782 %cmp = icmp sge i32 %shl, 1 783 ret i1 %cmp 784 } 785 786 ; Checks for icmp (eq|ne) (shl x, C), 0 787 ; CHECK-LABEL: @icmp_shl_nsw_eq( 788 ; CHECK-NEXT: icmp eq i32 %x, 0 789 define i1 @icmp_shl_nsw_eq(i32 %x) { 790 %mul = shl nsw i32 %x, 5 791 %cmp = icmp eq i32 %mul, 0 792 ret i1 %cmp 793 } 794 795 ; CHECK-LABEL: @icmp_shl_eq( 796 ; CHECK-NOT: icmp eq i32 %mul, 0 797 define i1 @icmp_shl_eq(i32 %x) { 798 %mul = shl i32 %x, 5 799 %cmp = icmp eq i32 %mul, 0 800 ret i1 %cmp 801 } 802 803 ; CHECK-LABEL: @icmp_shl_nsw_ne( 804 ; CHECK-NEXT: icmp ne i32 %x, 0 805 define i1 @icmp_shl_nsw_ne(i32 %x) { 806 %mul = shl nsw i32 %x, 7 807 %cmp = icmp ne i32 %mul, 0 808 ret i1 %cmp 809 } 810 811 ; CHECK-LABEL: @icmp_shl_ne( 812 ; CHECK-NOT: icmp ne i32 %x, 0 813 define i1 @icmp_shl_ne(i32 %x) { 814 %mul = shl i32 %x, 7 815 %cmp = icmp ne i32 %mul, 0 816 ret i1 %cmp 817 } 818 819 ; If the (mul x, C) preserved the sign and this is sign test, 820 ; compare the LHS operand instead 821 ; CHECK-LABEL: @icmp_mul_nsw( 822 ; CHECK-NEXT: icmp sgt i32 %x, 0 823 define i1 @icmp_mul_nsw(i32 %x) { 824 %mul = mul nsw i32 %x, 12 825 %cmp = icmp sgt i32 %mul, 0 826 ret i1 %cmp 827 } 828 829 ; CHECK-LABEL: @icmp_mul_nsw1( 830 ; CHECK-NEXT: icmp slt i32 %x, 0 831 define i1 @icmp_mul_nsw1(i32 %x) { 832 %mul = mul nsw i32 %x, 12 833 %cmp = icmp sle i32 %mul, -1 834 ret i1 %cmp 835 } 836 837 ; CHECK-LABEL: @icmp_mul_nsw_neg( 838 ; CHECK-NEXT: icmp slt i32 %x, 1 839 define i1 @icmp_mul_nsw_neg(i32 %x) { 840 %mul = mul nsw i32 %x, -12 841 %cmp = icmp sge i32 %mul, 0 842 ret i1 %cmp 843 } 844 845 ; CHECK-LABEL: @icmp_mul_nsw_neg1( 846 ; CHECK-NEXT: icmp slt i32 %x, 0 847 define i1 @icmp_mul_nsw_neg1(i32 %x) { 848 %mul = mul nsw i32 %x, -12 849 %cmp = icmp sge i32 %mul, 1 850 ret i1 %cmp 851 } 852 853 ; CHECK-LABEL: @icmp_mul_nsw_0( 854 ; CHECK-NOT: icmp sgt i32 %x, 0 855 define i1 @icmp_mul_nsw_0(i32 %x) { 856 %mul = mul nsw i32 %x, 0 857 %cmp = icmp sgt i32 %mul, 0 858 ret i1 %cmp 859 } 860 861 ; CHECK-LABEL: @icmp_mul( 862 ; CHECK-NEXT: %mul = mul i32 %x, -12 863 define i1 @icmp_mul(i32 %x) { 864 %mul = mul i32 %x, -12 865 %cmp = icmp sge i32 %mul, 0 866 ret i1 %cmp 867 } 868 869 ; Checks for icmp (eq|ne) (mul x, C), 0 870 ; CHECK-LABEL: @icmp_mul_neq0( 871 ; CHECK-NEXT: icmp ne i32 %x, 0 872 define i1 @icmp_mul_neq0(i32 %x) { 873 %mul = mul nsw i32 %x, -12 874 %cmp = icmp ne i32 %mul, 0 875 ret i1 %cmp 876 } 877 878 ; CHECK-LABEL: @icmp_mul_eq0( 879 ; CHECK-NEXT: icmp eq i32 %x, 0 880 define i1 @icmp_mul_eq0(i32 %x) { 881 %mul = mul nsw i32 %x, 12 882 %cmp = icmp eq i32 %mul, 0 883 ret i1 %cmp 884 } 885 886 ; CHECK-LABEL: @icmp_mul0_eq0( 887 ; CHECK-NEXT: ret i1 true 888 define i1 @icmp_mul0_eq0(i32 %x) { 889 %mul = mul i32 %x, 0 890 %cmp = icmp eq i32 %mul, 0 891 ret i1 %cmp 892 } 893 894 ; CHECK-LABEL: @icmp_mul0_ne0( 895 ; CHECK-NEXT: ret i1 false 896 define i1 @icmp_mul0_ne0(i32 %x) { 897 %mul = mul i32 %x, 0 898 %cmp = icmp ne i32 %mul, 0 899 ret i1 %cmp 900 } 901 902 ; CHECK-LABEL: @icmp_sub1_sge( 903 ; CHECK-NEXT: icmp sgt i32 %x, %y 904 define i1 @icmp_sub1_sge(i32 %x, i32 %y) { 905 %sub = add nsw i32 %x, -1 906 %cmp = icmp sge i32 %sub, %y 907 ret i1 %cmp 908 } 909 910 ; CHECK-LABEL: @icmp_add1_sgt( 911 ; CHECK-NEXT: icmp sge i32 %x, %y 912 define i1 @icmp_add1_sgt(i32 %x, i32 %y) { 913 %add = add nsw i32 %x, 1 914 %cmp = icmp sgt i32 %add, %y 915 ret i1 %cmp 916 } 917 918 ; CHECK-LABEL: @icmp_sub1_slt( 919 ; CHECK-NEXT: icmp sle i32 %x, %y 920 define i1 @icmp_sub1_slt(i32 %x, i32 %y) { 921 %sub = add nsw i32 %x, -1 922 %cmp = icmp slt i32 %sub, %y 923 ret i1 %cmp 924 } 925 926 ; CHECK-LABEL: @icmp_add1_sle( 927 ; CHECK-NEXT: icmp slt i32 %x, %y 928 define i1 @icmp_add1_sle(i32 %x, i32 %y) { 929 %add = add nsw i32 %x, 1 930 %cmp = icmp sle i32 %add, %y 931 ret i1 %cmp 932 } 933 934 ; CHECK-LABEL: @icmp_add20_sge_add57( 935 ; CHECK-NEXT: [[ADD:%[a-z0-9]+]] = add nsw i32 %y, 37 936 ; CHECK-NEXT: icmp sle i32 [[ADD]], %x 937 define i1 @icmp_add20_sge_add57(i32 %x, i32 %y) { 938 %1 = add nsw i32 %x, 20 939 %2 = add nsw i32 %y, 57 940 %cmp = icmp sge i32 %1, %2 941 ret i1 %cmp 942 } 943 944 ; CHECK-LABEL: @icmp_sub57_sge_sub20( 945 ; CHECK-NEXT: [[SUB:%[a-z0-9]+]] = add nsw i32 %x, -37 946 ; CHECK-NEXT: icmp sge i32 [[SUB]], %y 947 define i1 @icmp_sub57_sge_sub20(i32 %x, i32 %y) { 948 %1 = add nsw i32 %x, -57 949 %2 = add nsw i32 %y, -20 950 %cmp = icmp sge i32 %1, %2 951 ret i1 %cmp 952 } 953 954 ; CHECK-LABEL: @icmp_and_shl_neg_ne_0( 955 ; CHECK-NEXT: [[SHL:%[a-z0-9]+]] = shl i32 1, %B 956 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 [[SHL]], %A 957 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp eq i32 [[AND]], 0 958 ; CHECK-NEXT: ret i1 [[CMP]] 959 define i1 @icmp_and_shl_neg_ne_0(i32 %A, i32 %B) { 960 %neg = xor i32 %A, -1 961 %shl = shl i32 1, %B 962 %and = and i32 %shl, %neg 963 %cmp = icmp ne i32 %and, 0 964 ret i1 %cmp 965 } 966 967 ; CHECK-LABEL: @icmp_and_shl_neg_eq_0( 968 ; CHECK-NEXT: [[SHL:%[a-z0-9]+]] = shl i32 1, %B 969 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 [[SHL]], %A 970 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ne i32 [[AND]], 0 971 ; CHECK-NEXT: ret i1 [[CMP]] 972 define i1 @icmp_and_shl_neg_eq_0(i32 %A, i32 %B) { 973 %neg = xor i32 %A, -1 974 %shl = shl i32 1, %B 975 %and = and i32 %shl, %neg 976 %cmp = icmp eq i32 %and, 0 977 ret i1 %cmp 978 } 979 980 ; CHECK-LABEL: @icmp_add_and_shr_ne_0( 981 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 %X, 240 982 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ne i32 [[AND]], 224 983 ; CHECK-NEXT: ret i1 [[CMP]] 984 define i1 @icmp_add_and_shr_ne_0(i32 %X) { 985 %shr = lshr i32 %X, 4 986 %and = and i32 %shr, 15 987 %add = add i32 %and, -14 988 %tobool = icmp ne i32 %add, 0 989 ret i1 %tobool 990 } 991 992 ; PR16244 993 ; CHECK-LABEL: define i1 @test71( 994 ; CHECK-NEXT: ret i1 false 995 define i1 @test71(i8* %x) { 996 %a = getelementptr i8* %x, i64 8 997 %b = getelementptr inbounds i8* %x, i64 8 998 %c = icmp ugt i8* %a, %b 999 ret i1 %c 1000 } 1001 1002 ; CHECK-LABEL: @icmp_shl_1_V_ult_32( 1003 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ult i32 %V, 5 1004 ; CHECK-NEXT: ret i1 [[CMP]] 1005 define i1 @icmp_shl_1_V_ult_32(i32 %V) { 1006 %shl = shl i32 1, %V 1007 %cmp = icmp ult i32 %shl, 32 1008 ret i1 %cmp 1009 } 1010 1011 ; CHECK-LABEL: @icmp_shl_1_V_eq_32( 1012 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp eq i32 %V, 5 1013 ; CHECK-NEXT: ret i1 [[CMP]] 1014 define i1 @icmp_shl_1_V_eq_32(i32 %V) { 1015 %shl = shl i32 1, %V 1016 %cmp = icmp eq i32 %shl, 32 1017 ret i1 %cmp 1018 } 1019 1020 ; CHECK-LABEL: @icmp_shl_1_V_eq_31( 1021 ; CHECK-NEXT: ret i1 false 1022 define i1 @icmp_shl_1_V_eq_31(i32 %V) { 1023 %shl = shl i32 1, %V 1024 %cmp = icmp eq i32 %shl, 31 1025 ret i1 %cmp 1026 } 1027 1028 ; CHECK-LABEL: @icmp_shl_1_V_ne_31( 1029 ; CHECK-NEXT: ret i1 true 1030 define i1 @icmp_shl_1_V_ne_31(i32 %V) { 1031 %shl = shl i32 1, %V 1032 %cmp = icmp ne i32 %shl, 31 1033 ret i1 %cmp 1034 } 1035 1036 ; CHECK-LABEL: @icmp_shl_1_V_ult_30( 1037 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ult i32 %V, 5 1038 ; CHECK-NEXT: ret i1 [[CMP]] 1039 define i1 @icmp_shl_1_V_ult_30(i32 %V) { 1040 %shl = shl i32 1, %V 1041 %cmp = icmp ult i32 %shl, 30 1042 ret i1 %cmp 1043 } 1044 1045 ; CHECK-LABEL: @icmp_shl_1_V_ugt_30( 1046 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ugt i32 %V, 4 1047 ; CHECK-NEXT: ret i1 [[CMP]] 1048 define i1 @icmp_shl_1_V_ugt_30(i32 %V) { 1049 %shl = shl i32 1, %V 1050 %cmp = icmp ugt i32 %shl, 30 1051 ret i1 %cmp 1052 } 1053 1054 ; CHECK-LABEL: @icmp_shl_1_V_ule_30( 1055 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ult i32 %V, 5 1056 ; CHECK-NEXT: ret i1 [[CMP]] 1057 define i1 @icmp_shl_1_V_ule_30(i32 %V) { 1058 %shl = shl i32 1, %V 1059 %cmp = icmp ule i32 %shl, 30 1060 ret i1 %cmp 1061 } 1062 1063 ; CHECK-LABEL: @icmp_shl_1_V_uge_30( 1064 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ugt i32 %V, 4 1065 ; CHECK-NEXT: ret i1 [[CMP]] 1066 define i1 @icmp_shl_1_V_uge_30(i32 %V) { 1067 %shl = shl i32 1, %V 1068 %cmp = icmp uge i32 %shl, 30 1069 ret i1 %cmp 1070 } 1071 1072 ; CHECK-LABEL: @icmp_shl_1_V_uge_2147483648( 1073 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp eq i32 %V, 31 1074 ; CHECK-NEXT: ret i1 [[CMP]] 1075 define i1 @icmp_shl_1_V_uge_2147483648(i32 %V) { 1076 %shl = shl i32 1, %V 1077 %cmp = icmp uge i32 %shl, 2147483648 1078 ret i1 %cmp 1079 } 1080 1081 ; CHECK-LABEL: @icmp_shl_1_V_ugt_2147483648( 1082 ; CHECK-NEXT: ret i1 false 1083 define i1 @icmp_shl_1_V_ugt_2147483648(i32 %V) { 1084 %shl = shl i32 1, %V 1085 %cmp = icmp ugt i32 %shl, 2147483648 1086 ret i1 %cmp 1087 } 1088 1089 ; CHECK-LABEL: @icmp_shl_1_V_ule_2147483648( 1090 ; CHECK-NEXT: ret i1 true 1091 define i1 @icmp_shl_1_V_ule_2147483648(i32 %V) { 1092 %shl = shl i32 1, %V 1093 %cmp = icmp ule i32 %shl, 2147483648 1094 ret i1 %cmp 1095 } 1096 1097 ; CHECK-LABEL: @icmp_shl_1_V_ult_2147483648( 1098 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ne i32 %V, 31 1099 ; CHECK-NEXT: ret i1 [[CMP]] 1100 define i1 @icmp_shl_1_V_ult_2147483648(i32 %V) { 1101 %shl = shl i32 1, %V 1102 %cmp = icmp ult i32 %shl, 2147483648 1103 ret i1 %cmp 1104 } 1105 1106 ; CHECK-LABEL: @or_icmp_eq_B_0_icmp_ult_A_B( 1107 ; CHECK-NEXT: [[SUB:%[a-z0-9]+]] = add i64 %b, -1 1108 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp uge i64 [[SUB]], %a 1109 ; CHECK-NEXT: ret i1 [[CMP]] 1110 define i1 @or_icmp_eq_B_0_icmp_ult_A_B(i64 %a, i64 %b) { 1111 %1 = icmp eq i64 %b, 0 1112 %2 = icmp ult i64 %a, %b 1113 %3 = or i1 %1, %2 1114 ret i1 %3 1115 } 1116 1117 ; CHECK-LABEL: @icmp_add_ult_2( 1118 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 %X, -2 1119 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp eq i32 [[AND]], 14 1120 ; CHECK-NEXT: ret i1 [[CMP]] 1121 define i1 @icmp_add_ult_2(i32 %X) { 1122 %add = add i32 %X, -14 1123 %cmp = icmp ult i32 %add, 2 1124 ret i1 %cmp 1125 } 1126 1127 ; CHECK: @icmp_add_X_-14_ult_2 1128 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 %X, -2 1129 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp eq i32 [[AND]], 14 1130 ; CHECK-NEXT: ret i1 [[CMP]] 1131 define i1 @icmp_add_X_-14_ult_2(i32 %X) { 1132 %add = add i32 %X, -14 1133 %cmp = icmp ult i32 %add, 2 1134 ret i1 %cmp 1135 } 1136 1137 ; CHECK-LABEL: @icmp_sub_3_X_ult_2( 1138 ; CHECK-NEXT: [[OR:%[a-z0-9]+]] = or i32 %X, 1 1139 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp eq i32 [[OR]], 3 1140 ; CHECK-NEXT: ret i1 [[CMP]] 1141 define i1 @icmp_sub_3_X_ult_2(i32 %X) { 1142 %add = sub i32 3, %X 1143 %cmp = icmp ult i32 %add, 2 1144 ret i1 %cmp 1145 } 1146 1147 ; CHECK: @icmp_add_X_-14_uge_2 1148 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 %X, -2 1149 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ne i32 [[AND]], 14 1150 ; CHECK-NEXT: ret i1 [[CMP]] 1151 define i1 @icmp_add_X_-14_uge_2(i32 %X) { 1152 %add = add i32 %X, -14 1153 %cmp = icmp uge i32 %add, 2 1154 ret i1 %cmp 1155 } 1156 1157 ; CHECK-LABEL: @icmp_sub_3_X_uge_2( 1158 ; CHECK-NEXT: [[OR:%[a-z0-9]+]] = or i32 %X, 1 1159 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ne i32 [[OR]], 3 1160 ; CHECK-NEXT: ret i1 [[CMP]] 1161 define i1 @icmp_sub_3_X_uge_2(i32 %X) { 1162 %add = sub i32 3, %X 1163 %cmp = icmp uge i32 %add, 2 1164 ret i1 %cmp 1165 } 1166 1167 ; CHECK: @icmp_and_X_-16_eq-16 1168 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ugt i32 %X, -17 1169 ; CHECK-NEXT: ret i1 [[CMP]] 1170 define i1 @icmp_and_X_-16_eq-16(i32 %X) { 1171 %and = and i32 %X, -16 1172 %cmp = icmp eq i32 %and, -16 1173 ret i1 %cmp 1174 } 1175 1176 ; CHECK: @icmp_and_X_-16_ne-16 1177 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ult i32 %X, -16 1178 ; CHECK-NEXT: ret i1 [[CMP]] 1179 define i1 @icmp_and_X_-16_ne-16(i32 %X) { 1180 %and = and i32 %X, -16 1181 %cmp = icmp ne i32 %and, -16 1182 ret i1 %cmp 1183 } 1184 1185 ; CHECK: @icmp_sub_-1_X_ult_4 1186 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ugt i32 %X, -5 1187 ; CHECK-NEXT: ret i1 [[CMP]] 1188 define i1 @icmp_sub_-1_X_ult_4(i32 %X) { 1189 %sub = sub i32 -1, %X 1190 %cmp = icmp ult i32 %sub, 4 1191 ret i1 %cmp 1192 } 1193 1194 ; CHECK: @icmp_sub_-1_X_uge_4 1195 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ult i32 %X, -4 1196 ; CHECK-NEXT: ret i1 [[CMP]] 1197 define i1 @icmp_sub_-1_X_uge_4(i32 %X) { 1198 %sub = sub i32 -1, %X 1199 %cmp = icmp uge i32 %sub, 4 1200 ret i1 %cmp 1201 } 1202