1; RUN: opt < %s -instsimplify -S | FileCheck %s 2target datalayout = "p:32:32" 3 4define i1 @ptrtoint() { 5; CHECK-LABEL: @ptrtoint( 6 %a = alloca i8 7 %tmp = ptrtoint i8* %a to i32 8 %r = icmp eq i32 %tmp, 0 9 ret i1 %r 10; CHECK: ret i1 false 11} 12 13define i1 @bitcast() { 14; CHECK-LABEL: @bitcast( 15 %a = alloca i32 16 %b = alloca i64 17 %x = bitcast i32* %a to i8* 18 %y = bitcast i64* %b to i8* 19 %cmp = icmp eq i8* %x, %y 20 ret i1 %cmp 21; CHECK-NEXT: ret i1 false 22} 23 24define i1 @gep() { 25; CHECK-LABEL: @gep( 26 %a = alloca [3 x i8], align 8 27 %x = getelementptr inbounds [3 x i8], [3 x i8]* %a, i32 0, i32 0 28 %cmp = icmp eq i8* %x, null 29 ret i1 %cmp 30; CHECK-NEXT: ret i1 false 31} 32 33define i1 @gep2() { 34; CHECK-LABEL: @gep2( 35 %a = alloca [3 x i8], align 8 36 %x = getelementptr inbounds [3 x i8], [3 x i8]* %a, i32 0, i32 0 37 %y = getelementptr inbounds [3 x i8], [3 x i8]* %a, i32 0, i32 0 38 %cmp = icmp eq i8* %x, %y 39 ret i1 %cmp 40; CHECK-NEXT: ret i1 true 41} 42 43; PR11238 44%gept = type { i32, i32 } 45@gepy = global %gept zeroinitializer, align 8 46@gepz = extern_weak global %gept 47 48define i1 @gep3() { 49; CHECK-LABEL: @gep3( 50 %x = alloca %gept, align 8 51 %a = getelementptr %gept, %gept* %x, i64 0, i32 0 52 %b = getelementptr %gept, %gept* %x, i64 0, i32 1 53 %equal = icmp eq i32* %a, %b 54 ret i1 %equal 55; CHECK-NEXT: ret i1 false 56} 57 58define i1 @gep4() { 59; CHECK-LABEL: @gep4( 60 %x = alloca %gept, align 8 61 %a = getelementptr %gept, %gept* @gepy, i64 0, i32 0 62 %b = getelementptr %gept, %gept* @gepy, i64 0, i32 1 63 %equal = icmp eq i32* %a, %b 64 ret i1 %equal 65; CHECK-NEXT: ret i1 false 66} 67 68@a = common global [1 x i32] zeroinitializer, align 4 69 70define i1 @PR31262() { 71; CHECK-LABEL: @PR31262( 72; CHECK-NEXT: ret i1 icmp uge (i32* getelementptr ([1 x i32], [1 x i32]* @a, i32 0, i32 undef), i32* getelementptr inbounds ([1 x i32], [1 x i32]* @a, i32 0, i32 0)) 73; 74 %idx = getelementptr inbounds [1 x i32], [1 x i32]* @a, i64 0, i64 undef 75 %cmp = icmp uge i32* %idx, getelementptr inbounds ([1 x i32], [1 x i32]* @a, i32 0, i32 0) 76 ret i1 %cmp 77} 78 79define i1 @gep5() { 80; CHECK-LABEL: @gep5( 81 %x = alloca %gept, align 8 82 %a = getelementptr inbounds %gept, %gept* %x, i64 0, i32 1 83 %b = getelementptr %gept, %gept* @gepy, i64 0, i32 0 84 %equal = icmp eq i32* %a, %b 85 ret i1 %equal 86; CHECK-NEXT: ret i1 false 87} 88 89define i1 @gep6(%gept* %x) { 90; Same as @gep3 but potentially null. 91; CHECK-LABEL: @gep6( 92 %a = getelementptr %gept, %gept* %x, i64 0, i32 0 93 %b = getelementptr %gept, %gept* %x, i64 0, i32 1 94 %equal = icmp eq i32* %a, %b 95 ret i1 %equal 96; CHECK-NEXT: ret i1 false 97} 98 99define i1 @gep7(%gept* %x) { 100; CHECK-LABEL: @gep7( 101 %a = getelementptr %gept, %gept* %x, i64 0, i32 0 102 %b = getelementptr %gept, %gept* @gepz, i64 0, i32 0 103 %equal = icmp eq i32* %a, %b 104 ret i1 %equal 105; CHECK: ret i1 %equal 106} 107 108define i1 @gep8(%gept* %x) { 109; CHECK-LABEL: @gep8( 110 %a = getelementptr %gept, %gept* %x, i32 1 111 %b = getelementptr %gept, %gept* %x, i32 -1 112 %equal = icmp ugt %gept* %a, %b 113 ret i1 %equal 114; CHECK: ret i1 %equal 115} 116 117define i1 @gep9(i8* %ptr) { 118; CHECK-LABEL: @gep9( 119; CHECK-NOT: ret 120; CHECK: ret i1 true 121 122entry: 123 %first1 = getelementptr inbounds i8, i8* %ptr, i32 0 124 %first2 = getelementptr inbounds i8, i8* %first1, i32 1 125 %first3 = getelementptr inbounds i8, i8* %first2, i32 2 126 %first4 = getelementptr inbounds i8, i8* %first3, i32 4 127 %last1 = getelementptr inbounds i8, i8* %first2, i32 48 128 %last2 = getelementptr inbounds i8, i8* %last1, i32 8 129 %last3 = getelementptr inbounds i8, i8* %last2, i32 -4 130 %last4 = getelementptr inbounds i8, i8* %last3, i32 -4 131 %first.int = ptrtoint i8* %first4 to i32 132 %last.int = ptrtoint i8* %last4 to i32 133 %cmp = icmp ne i32 %last.int, %first.int 134 ret i1 %cmp 135} 136 137define i1 @gep10(i8* %ptr) { 138; CHECK-LABEL: @gep10( 139; CHECK-NOT: ret 140; CHECK: ret i1 true 141 142entry: 143 %first1 = getelementptr inbounds i8, i8* %ptr, i32 -2 144 %first2 = getelementptr inbounds i8, i8* %first1, i32 44 145 %last1 = getelementptr inbounds i8, i8* %ptr, i32 48 146 %last2 = getelementptr inbounds i8, i8* %last1, i32 -6 147 %first.int = ptrtoint i8* %first2 to i32 148 %last.int = ptrtoint i8* %last2 to i32 149 %cmp = icmp eq i32 %last.int, %first.int 150 ret i1 %cmp 151} 152 153define i1 @gep11(i8* %ptr) { 154; CHECK-LABEL: @gep11( 155; CHECK-NOT: ret 156; CHECK: ret i1 true 157 158entry: 159 %first1 = getelementptr inbounds i8, i8* %ptr, i32 -2 160 %last1 = getelementptr inbounds i8, i8* %ptr, i32 48 161 %last2 = getelementptr inbounds i8, i8* %last1, i32 -6 162 %cmp = icmp ult i8* %first1, %last2 163 ret i1 %cmp 164} 165 166define i1 @gep12(i8* %ptr) { 167; CHECK-LABEL: @gep12( 168; CHECK-NOT: ret 169; CHECK: ret i1 %cmp 170 171entry: 172 %first1 = getelementptr inbounds i8, i8* %ptr, i32 -2 173 %last1 = getelementptr inbounds i8, i8* %ptr, i32 48 174 %last2 = getelementptr inbounds i8, i8* %last1, i32 -6 175 %cmp = icmp slt i8* %first1, %last2 176 ret i1 %cmp 177} 178 179define i1 @gep13(i8* %ptr) { 180; CHECK-LABEL: @gep13( 181; We can prove this GEP is non-null because it is inbounds. 182 %x = getelementptr inbounds i8, i8* %ptr, i32 1 183 %cmp = icmp eq i8* %x, null 184 ret i1 %cmp 185; CHECK-NEXT: ret i1 false 186} 187 188define i1 @gep13_no_null_opt(i8* %ptr) #0 { 189; We can't prove this GEP is non-null. 190; CHECK-LABEL: @gep13_no_null_opt( 191; CHECK: getelementptr 192; CHECK: icmp 193; CHECK: ret 194 %x = getelementptr inbounds i8, i8* %ptr, i32 1 195 %cmp = icmp eq i8* %x, null 196 ret i1 %cmp 197} 198 199define i1 @gep14({ {}, i8 }* %ptr) { 200; CHECK-LABEL: @gep14( 201; We can't simplify this because the offset of one in the GEP actually doesn't 202; move the pointer. 203 %x = getelementptr inbounds { {}, i8 }, { {}, i8 }* %ptr, i32 0, i32 1 204 %cmp = icmp eq i8* %x, null 205 ret i1 %cmp 206; CHECK-NOT: ret i1 false 207} 208 209define i1 @gep15({ {}, [4 x {i8, i8}]}* %ptr, i32 %y) { 210; CHECK-LABEL: @gep15( 211; We can prove this GEP is non-null even though there is a user value, as we 212; would necessarily violate inbounds on one side or the other. 213 %x = getelementptr inbounds { {}, [4 x {i8, i8}]}, { {}, [4 x {i8, i8}]}* %ptr, i32 0, i32 1, i32 %y, i32 1 214 %cmp = icmp eq i8* %x, null 215 ret i1 %cmp 216; CHECK-NEXT: ret i1 false 217} 218 219define i1 @gep15_no_null_opt({ {}, [4 x {i8, i8}]}* %ptr, i32 %y) #0 { 220; We can't prove this GEP is non-null. 221; CHECK-LABEL: @gep15_no_null_opt( 222; CHECK: getelementptr 223; CHECK: icmp 224; CHECK: ret 225 %x = getelementptr inbounds { {}, [4 x {i8, i8}]}, { {}, [4 x {i8, i8}]}* %ptr, i32 0, i32 1, i32 %y, i32 1 226 %cmp = icmp eq i8* %x, null 227 ret i1 %cmp 228} 229 230define i1 @gep16(i8* %ptr, i32 %a) { 231; CHECK-LABEL: @gep16( 232; We can prove this GEP is non-null because it is inbounds and because we know 233; %b is non-zero even though we don't know its value. 234 %b = or i32 %a, 1 235 %x = getelementptr inbounds i8, i8* %ptr, i32 %b 236 %cmp = icmp eq i8* %x, null 237 ret i1 %cmp 238; CHECK-NEXT: ret i1 false 239} 240 241define i1 @gep16_no_null_opt(i8* %ptr, i32 %a) #0 { 242; We can't prove this GEP is non-null. 243; CHECK-LABEL: @gep16_no_null_opt( 244; CHECK getelementptr inbounds i8, i8* %ptr, i32 %b 245; CHECK: %cmp = icmp eq i8* %x, null 246; CHECK-NEXT: ret i1 %cmp 247 %b = or i32 %a, 1 248 %x = getelementptr inbounds i8, i8* %ptr, i32 %b 249 %cmp = icmp eq i8* %x, null 250 ret i1 %cmp 251} 252 253define i1 @gep17() { 254; CHECK-LABEL: @gep17( 255 %alloca = alloca i32, align 4 256 %bc = bitcast i32* %alloca to [4 x i8]* 257 %gep1 = getelementptr inbounds i32, i32* %alloca, i32 1 258 %pti1 = ptrtoint i32* %gep1 to i32 259 %gep2 = getelementptr inbounds [4 x i8], [4 x i8]* %bc, i32 0, i32 1 260 %pti2 = ptrtoint i8* %gep2 to i32 261 %cmp = icmp ugt i32 %pti1, %pti2 262 ret i1 %cmp 263; CHECK-NEXT: ret i1 true 264} 265 266define i1 @zext(i32 %x) { 267; CHECK-LABEL: @zext( 268 %e1 = zext i32 %x to i64 269 %e2 = zext i32 %x to i64 270 %r = icmp eq i64 %e1, %e2 271 ret i1 %r 272; CHECK: ret i1 true 273} 274 275define i1 @zext2(i1 %x) { 276; CHECK-LABEL: @zext2( 277 %e = zext i1 %x to i32 278 %c = icmp ne i32 %e, 0 279 ret i1 %c 280; CHECK: ret i1 %x 281} 282 283define i1 @zext3() { 284; CHECK-LABEL: @zext3( 285 %e = zext i1 1 to i32 286 %c = icmp ne i32 %e, 0 287 ret i1 %c 288; CHECK: ret i1 true 289} 290 291define i1 @sext(i32 %x) { 292; CHECK-LABEL: @sext( 293 %e1 = sext i32 %x to i64 294 %e2 = sext i32 %x to i64 295 %r = icmp eq i64 %e1, %e2 296 ret i1 %r 297; CHECK: ret i1 true 298} 299 300define i1 @sext2(i1 %x) { 301; CHECK-LABEL: @sext2( 302 %e = sext i1 %x to i32 303 %c = icmp ne i32 %e, 0 304 ret i1 %c 305; CHECK: ret i1 %x 306} 307 308define i1 @sext3() { 309; CHECK-LABEL: @sext3( 310 %e = sext i1 1 to i32 311 %c = icmp ne i32 %e, 0 312 ret i1 %c 313; CHECK: ret i1 true 314} 315 316define i1 @add(i32 %x, i32 %y) { 317; CHECK-LABEL: @add( 318 %l = lshr i32 %x, 1 319 %q = lshr i32 %y, 1 320 %r = or i32 %q, 1 321 %s = add i32 %l, %r 322 %c = icmp eq i32 %s, 0 323 ret i1 %c 324; CHECK: ret i1 false 325} 326 327define i1 @add2(i8 %x, i8 %y) { 328; CHECK-LABEL: @add2( 329 %l = or i8 %x, 128 330 %r = or i8 %y, 129 331 %s = add i8 %l, %r 332 %c = icmp eq i8 %s, 0 333 ret i1 %c 334; CHECK: ret i1 false 335} 336 337define i1 @add3(i8 %x, i8 %y) { 338; CHECK-LABEL: @add3( 339 %l = zext i8 %x to i32 340 %r = zext i8 %y to i32 341 %s = add i32 %l, %r 342 %c = icmp eq i32 %s, 0 343 ret i1 %c 344; CHECK: ret i1 %c 345} 346 347define i1 @add4(i32 %x, i32 %y) { 348; CHECK-LABEL: @add4( 349 %z = add nsw i32 %y, 1 350 %s1 = add nsw i32 %x, %y 351 %s2 = add nsw i32 %x, %z 352 %c = icmp slt i32 %s1, %s2 353 ret i1 %c 354; CHECK: ret i1 true 355} 356 357define i1 @add5(i32 %x, i32 %y) { 358; CHECK-LABEL: @add5( 359 %z = add nuw i32 %y, 1 360 %s1 = add nuw i32 %x, %z 361 %s2 = add nuw i32 %x, %y 362 %c = icmp ugt i32 %s1, %s2 363 ret i1 %c 364; CHECK: ret i1 true 365} 366 367define i1 @add6(i64 %A, i64 %B) { 368; CHECK-LABEL: @add6( 369 %s1 = add i64 %A, %B 370 %s2 = add i64 %B, %A 371 %cmp = icmp eq i64 %s1, %s2 372 ret i1 %cmp 373; CHECK: ret i1 true 374} 375 376define i1 @addpowtwo(i32 %x, i32 %y) { 377; CHECK-LABEL: @addpowtwo( 378 %l = lshr i32 %x, 1 379 %r = shl i32 1, %y 380 %s = add i32 %l, %r 381 %c = icmp eq i32 %s, 0 382 ret i1 %c 383; CHECK: ret i1 false 384} 385 386define i1 @or(i32 %x) { 387; CHECK-LABEL: @or( 388 %o = or i32 %x, 1 389 %c = icmp eq i32 %o, 0 390 ret i1 %c 391; CHECK: ret i1 false 392} 393 394; Do not simplify if we cannot guarantee that the ConstantExpr is a non-zero 395; constant. 396@GV = common global i32* null 397define i1 @or_constexp(i32 %x) { 398; CHECK-LABEL: @or_constexp( 399entry: 400 %0 = and i32 ptrtoint (i32** @GV to i32), 32 401 %o = or i32 %x, %0 402 %c = icmp eq i32 %o, 0 403 ret i1 %c 404; CHECK: or 405; CHECK-NEXT: icmp eq 406; CHECK-NOT: ret i1 false 407} 408 409define i1 @shl1(i32 %x) { 410; CHECK-LABEL: @shl1( 411 %s = shl i32 1, %x 412 %c = icmp eq i32 %s, 0 413 ret i1 %c 414; CHECK: ret i1 false 415} 416 417define i1 @shl3(i32 %X) { 418; CHECK: @shl3 419 %sub = shl nuw i32 4, %X 420 %cmp = icmp eq i32 %sub, 31 421 ret i1 %cmp 422; CHECK-NEXT: ret i1 false 423} 424 425define i1 @lshr1(i32 %x) { 426; CHECK-LABEL: @lshr1( 427 %s = lshr i32 -1, %x 428 %c = icmp eq i32 %s, 0 429 ret i1 %c 430; CHECK: ret i1 false 431} 432 433define i1 @lshr3(i32 %x) { 434; CHECK-LABEL: @lshr3( 435 %s = lshr i32 %x, %x 436 %c = icmp eq i32 %s, 0 437 ret i1 %c 438; CHECK: ret i1 true 439} 440 441define i1 @lshr4(i32 %X, i32 %Y) { 442; CHECK-LABEL: @lshr4( 443 %A = lshr i32 %X, %Y 444 %C = icmp ule i32 %A, %X 445 ret i1 %C 446; CHECK: ret i1 true 447} 448 449define i1 @lshr5(i32 %X, i32 %Y) { 450; CHECK-LABEL: @lshr5( 451 %A = lshr i32 %X, %Y 452 %C = icmp ugt i32 %A, %X 453 ret i1 %C 454; CHECK: ret i1 false 455} 456 457define i1 @lshr6(i32 %X, i32 %Y) { 458; CHECK-LABEL: @lshr6( 459 %A = lshr i32 %X, %Y 460 %C = icmp ult i32 %X, %A 461 ret i1 %C 462; CHECK: ret i1 false 463} 464 465define i1 @lshr7(i32 %X, i32 %Y) { 466; CHECK-LABEL: @lshr7( 467 %A = lshr i32 %X, %Y 468 %C = icmp uge i32 %X, %A 469 ret i1 %C 470; CHECK: ret i1 true 471} 472 473define i1 @ashr1(i32 %x) { 474; CHECK-LABEL: @ashr1( 475 %s = ashr i32 -1, %x 476 %c = icmp eq i32 %s, 0 477 ret i1 %c 478; CHECK: ret i1 false 479} 480 481define i1 @ashr3(i32 %x) { 482; CHECK-LABEL: @ashr3( 483 %s = ashr i32 %x, %x 484 %c = icmp eq i32 %s, 0 485 ret i1 %c 486; CHECK: ret i1 true 487} 488 489define i1 @select1(i1 %cond) { 490; CHECK-LABEL: @select1( 491 %s = select i1 %cond, i32 1, i32 0 492 %c = icmp eq i32 %s, 1 493 ret i1 %c 494; CHECK: ret i1 %cond 495} 496 497define i1 @select2(i1 %cond) { 498; CHECK-LABEL: @select2( 499 %x = zext i1 %cond to i32 500 %s = select i1 %cond, i32 %x, i32 0 501 %c = icmp ne i32 %s, 0 502 ret i1 %c 503; CHECK: ret i1 %cond 504} 505 506define i1 @select3(i1 %cond) { 507; CHECK-LABEL: @select3( 508 %x = zext i1 %cond to i32 509 %s = select i1 %cond, i32 1, i32 %x 510 %c = icmp ne i32 %s, 0 511 ret i1 %c 512; CHECK: ret i1 %cond 513} 514 515define i1 @select4(i1 %cond) { 516; CHECK-LABEL: @select4( 517 %invert = xor i1 %cond, 1 518 %s = select i1 %invert, i32 0, i32 1 519 %c = icmp ne i32 %s, 0 520 ret i1 %c 521; CHECK: ret i1 %cond 522} 523 524define i1 @select5(i32 %x) { 525; CHECK-LABEL: @select5( 526 %c = icmp eq i32 %x, 0 527 %s = select i1 %c, i32 1, i32 %x 528 %c2 = icmp eq i32 %s, 0 529 ret i1 %c2 530; CHECK: ret i1 false 531} 532 533define i1 @select6(i32 %x) { 534; CHECK-LABEL: @select6( 535 %c = icmp sgt i32 %x, 0 536 %s = select i1 %c, i32 %x, i32 4 537 %c2 = icmp eq i32 %s, 0 538 ret i1 %c2 539; CHECK: ret i1 %c2 540} 541 542define i1 @urem1(i32 %X, i32 %Y) { 543; CHECK-LABEL: @urem1( 544 %A = urem i32 %X, %Y 545 %B = icmp ult i32 %A, %Y 546 ret i1 %B 547; CHECK: ret i1 true 548} 549 550define i1 @urem2(i32 %X, i32 %Y) { 551; CHECK-LABEL: @urem2( 552 %A = urem i32 %X, %Y 553 %B = icmp eq i32 %A, %Y 554 ret i1 %B 555; CHECK: ret i1 false 556} 557 558define i1 @urem4(i32 %X) { 559; CHECK-LABEL: @urem4( 560 %A = urem i32 %X, 15 561 %B = icmp ult i32 %A, 10 562 ret i1 %B 563; CHECK: ret i1 %B 564} 565 566define i1 @urem5(i16 %X, i32 %Y) { 567; CHECK-LABEL: @urem5( 568 %A = zext i16 %X to i32 569 %B = urem i32 %A, %Y 570 %C = icmp slt i32 %B, %Y 571 ret i1 %C 572; CHECK-NOT: ret i1 true 573} 574 575define i1 @urem6(i32 %X, i32 %Y) { 576; CHECK-LABEL: @urem6( 577 %A = urem i32 %X, %Y 578 %B = icmp ugt i32 %Y, %A 579 ret i1 %B 580; CHECK: ret i1 true 581} 582 583define i1 @urem7(i32 %X) { 584; CHECK-LABEL: @urem7( 585 %A = urem i32 1, %X 586 %B = icmp sgt i32 %A, %X 587 ret i1 %B 588; CHECK-NOT: ret i1 false 589} 590 591; PR9343 #15 592; CHECK-LABEL: @srem2( 593; CHECK: ret i1 false 594define i1 @srem2(i16 %X, i32 %Y) { 595 %A = zext i16 %X to i32 596 %B = add nsw i32 %A, 1 597 %C = srem i32 %B, %Y 598 %D = icmp slt i32 %C, 0 599 ret i1 %D 600} 601 602; CHECK-LABEL: @srem3( 603; CHECK-NEXT: ret i1 false 604define i1 @srem3(i16 %X, i32 %Y) { 605 %A = zext i16 %X to i32 606 %B = or i32 2147483648, %A 607 %C = sub nsw i32 1, %B 608 %D = srem i32 %C, %Y 609 %E = icmp slt i32 %D, 0 610 ret i1 %E 611} 612 613define i1 @udiv2(i32 %Z) { 614; CHECK-LABEL: @udiv2( 615; CHECK-NEXT: ret i1 true 616; 617 %A = udiv exact i32 10, %Z 618 %B = udiv exact i32 20, %Z 619 %C = icmp ult i32 %A, %B 620 ret i1 %C 621} 622 623; Exact sdiv and equality preds can simplify. 624 625define i1 @sdiv_exact_equality(i32 %Z) { 626; CHECK-LABEL: @sdiv_exact_equality( 627; CHECK-NEXT: ret i1 false 628; 629 %A = sdiv exact i32 10, %Z 630 %B = sdiv exact i32 20, %Z 631 %C = icmp eq i32 %A, %B 632 ret i1 %C 633} 634 635; But not other preds: PR32949 - https://bugs.llvm.org/show_bug.cgi?id=32949 636 637define i1 @sdiv_exact_not_equality(i32 %Z) { 638; CHECK-LABEL: @sdiv_exact_not_equality( 639; CHECK-NEXT: [[A:%.*]] = sdiv exact i32 10, %Z 640; CHECK-NEXT: [[B:%.*]] = sdiv exact i32 20, %Z 641; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[A]], [[B]] 642; CHECK-NEXT: ret i1 [[C]] 643; 644 %A = sdiv exact i32 10, %Z 645 %B = sdiv exact i32 20, %Z 646 %C = icmp ult i32 %A, %B 647 ret i1 %C 648} 649 650define i1 @udiv3(i32 %X, i32 %Y) { 651; CHECK-LABEL: @udiv3( 652 %A = udiv i32 %X, %Y 653 %C = icmp ugt i32 %A, %X 654 ret i1 %C 655; CHECK: ret i1 false 656} 657 658define i1 @udiv4(i32 %X, i32 %Y) { 659; CHECK-LABEL: @udiv4( 660 %A = udiv i32 %X, %Y 661 %C = icmp ule i32 %A, %X 662 ret i1 %C 663; CHECK: ret i1 true 664} 665 666; PR11340 667define i1 @udiv6(i32 %X) nounwind { 668; CHECK-LABEL: @udiv6( 669 %A = udiv i32 1, %X 670 %C = icmp eq i32 %A, 0 671 ret i1 %C 672; CHECK: ret i1 %C 673} 674 675define i1 @udiv7(i32 %X, i32 %Y) { 676; CHECK-LABEL: @udiv7( 677 %A = udiv i32 %X, %Y 678 %C = icmp ult i32 %X, %A 679 ret i1 %C 680; CHECK: ret i1 false 681} 682 683define i1 @udiv8(i32 %X, i32 %Y) { 684; CHECK-LABEL: @udiv8( 685 %A = udiv i32 %X, %Y 686 %C = icmp uge i32 %X, %A 687 ret i1 %C 688; CHECK: ret i1 true 689} 690 691define i1 @mul1(i32 %X) { 692; CHECK-LABEL: @mul1( 693; Square of a non-zero number is non-zero if there is no overflow. 694 %Y = or i32 %X, 1 695 %M = mul nuw i32 %Y, %Y 696 %C = icmp eq i32 %M, 0 697 ret i1 %C 698; CHECK: ret i1 false 699} 700 701define i1 @mul2(i32 %X) { 702; CHECK-LABEL: @mul2( 703; Square of a non-zero number is positive if there is no signed overflow. 704 %Y = or i32 %X, 1 705 %M = mul nsw i32 %Y, %Y 706 %C = icmp sgt i32 %M, 0 707 ret i1 %C 708; CHECK: ret i1 true 709} 710 711define i1 @mul3(i32 %X, i32 %Y) { 712; CHECK-LABEL: @mul3( 713; Product of non-negative numbers is non-negative if there is no signed overflow. 714 %XX = mul nsw i32 %X, %X 715 %YY = mul nsw i32 %Y, %Y 716 %M = mul nsw i32 %XX, %YY 717 %C = icmp sge i32 %M, 0 718 ret i1 %C 719; CHECK: ret i1 true 720} 721 722define <2 x i1> @vectorselect1(<2 x i1> %cond) { 723; CHECK-LABEL: @vectorselect1( 724 %invert = xor <2 x i1> %cond, <i1 1, i1 1> 725 %s = select <2 x i1> %invert, <2 x i32> <i32 0, i32 0>, <2 x i32> <i32 1, i32 1> 726 %c = icmp ne <2 x i32> %s, <i32 0, i32 0> 727 ret <2 x i1> %c 728; CHECK: ret <2 x i1> %cond 729} 730 731; PR11948 732define <2 x i1> @vectorselectcrash(i32 %arg1) { 733 %tobool40 = icmp ne i32 %arg1, 0 734 %cond43 = select i1 %tobool40, <2 x i16> <i16 -5, i16 66>, <2 x i16> <i16 46, i16 1> 735 %cmp45 = icmp ugt <2 x i16> %cond43, <i16 73, i16 21> 736 ret <2 x i1> %cmp45 737} 738 739; PR12013 740define i1 @alloca_compare(i64 %idx) { 741 %sv = alloca { i32, i32, [124 x i32] } 742 %1 = getelementptr inbounds { i32, i32, [124 x i32] }, { i32, i32, [124 x i32] }* %sv, i32 0, i32 2, i64 %idx 743 %2 = icmp eq i32* %1, null 744 ret i1 %2 745 ; CHECK: alloca_compare 746 ; CHECK: ret i1 false 747} 748 749define i1 @alloca_compare_no_null_opt(i64 %idx) #0 { 750; CHECK-LABEL: alloca_compare_no_null_opt( 751; CHECK: %sv = alloca { i32, i32, [124 x i32] } 752; CHECK: %cmp = getelementptr inbounds { i32, i32, [124 x i32] }, { i32, i32, [124 x i32] }* %sv, i32 0, i32 2, i64 %idx 753; CHECK: %X = icmp eq i32* %cmp, null 754; CHECK: ret i1 %X 755 %sv = alloca { i32, i32, [124 x i32] } 756 %cmp = getelementptr inbounds { i32, i32, [124 x i32] }, { i32, i32, [124 x i32] }* %sv, i32 0, i32 2, i64 %idx 757 %X = icmp eq i32* %cmp, null 758 ret i1 %X 759} 760; PR12075 761define i1 @infinite_gep() { 762 ret i1 1 763 764unreachableblock: 765 %X = getelementptr i32, i32 *%X, i32 1 766 %Y = icmp eq i32* %X, null 767 ret i1 %Y 768} 769 770; It's not valid to fold a comparison of an argument with an alloca, even though 771; that's tempting. An argument can't *alias* an alloca, however the aliasing rule 772; relies on restrictions against guessing an object's address and dereferencing. 773; There are no restrictions against guessing an object's address and comparing. 774 775define i1 @alloca_argument_compare(i64* %arg) { 776 %alloc = alloca i64 777 %cmp = icmp eq i64* %arg, %alloc 778 ret i1 %cmp 779 ; CHECK: alloca_argument_compare 780 ; CHECK: ret i1 %cmp 781} 782 783; As above, but with the operands reversed. 784 785define i1 @alloca_argument_compare_swapped(i64* %arg) { 786 %alloc = alloca i64 787 %cmp = icmp eq i64* %alloc, %arg 788 ret i1 %cmp 789 ; CHECK: alloca_argument_compare_swapped 790 ; CHECK: ret i1 %cmp 791} 792 793; Don't assume that a noalias argument isn't equal to a global variable's 794; address. This is an example where AliasAnalysis' NoAlias concept is 795; different from actual pointer inequality. 796 797@y = external global i32 798define zeroext i1 @external_compare(i32* noalias %x) { 799 %cmp = icmp eq i32* %x, @y 800 ret i1 %cmp 801 ; CHECK: external_compare 802 ; CHECK: ret i1 %cmp 803} 804 805define i1 @alloca_gep(i64 %a, i64 %b) { 806; CHECK-LABEL: @alloca_gep( 807; We can prove this GEP is non-null because it is inbounds and the pointer 808; is non-null. 809 %strs = alloca [1000 x [1001 x i8]], align 16 810 %x = getelementptr inbounds [1000 x [1001 x i8]], [1000 x [1001 x i8]]* %strs, i64 0, i64 %a, i64 %b 811 %cmp = icmp eq i8* %x, null 812 ret i1 %cmp 813; CHECK-NEXT: ret i1 false 814} 815 816define i1 @alloca_gep_no_null_opt(i64 %a, i64 %b) #0 { 817; CHECK-LABEL: @alloca_gep_no_null_opt( 818; We can't prove this GEP is non-null. 819; CHECK: alloca 820; CHECK: getelementptr 821; CHECK: icmp 822; CHECK: ret 823 %strs = alloca [1000 x [1001 x i8]], align 16 824 %x = getelementptr inbounds [1000 x [1001 x i8]], [1000 x [1001 x i8]]* %strs, i64 0, i64 %a, i64 %b 825 %cmp = icmp eq i8* %x, null 826 ret i1 %cmp 827} 828 829define i1 @non_inbounds_gep_compare(i64* %a) { 830; CHECK-LABEL: @non_inbounds_gep_compare( 831; Equality compares with non-inbounds GEPs can be folded. 832 %x = getelementptr i64, i64* %a, i64 42 833 %y = getelementptr inbounds i64, i64* %x, i64 -42 834 %z = getelementptr i64, i64* %a, i64 -42 835 %w = getelementptr inbounds i64, i64* %z, i64 42 836 %cmp = icmp eq i64* %y, %w 837 ret i1 %cmp 838; CHECK-NEXT: ret i1 true 839} 840 841define i1 @non_inbounds_gep_compare2(i64* %a) { 842; CHECK-LABEL: @non_inbounds_gep_compare2( 843; Equality compares with non-inbounds GEPs can be folded. 844 %x = getelementptr i64, i64* %a, i64 4294967297 845 %y = getelementptr i64, i64* %a, i64 1 846 %cmp = icmp eq i64* %y, %y 847 ret i1 %cmp 848; CHECK-NEXT: ret i1 true 849} 850 851define i1 @compare_always_true_slt(i16 %a) { 852 %1 = zext i16 %a to i32 853 %2 = sub nsw i32 0, %1 854 %3 = icmp slt i32 %2, 1 855 ret i1 %3 856 857; CHECK-LABEL: @compare_always_true_slt 858; CHECK-NEXT: ret i1 true 859} 860 861define i1 @compare_always_true_sle(i16 %a) { 862 %1 = zext i16 %a to i32 863 %2 = sub nsw i32 0, %1 864 %3 = icmp sle i32 %2, 0 865 ret i1 %3 866 867; CHECK-LABEL: @compare_always_true_sle 868; CHECK-NEXT: ret i1 true 869} 870 871define i1 @compare_always_false_sgt(i16 %a) { 872 %1 = zext i16 %a to i32 873 %2 = sub nsw i32 0, %1 874 %3 = icmp sgt i32 %2, 0 875 ret i1 %3 876 877; CHECK-LABEL: @compare_always_false_sgt 878; CHECK-NEXT: ret i1 false 879} 880 881define i1 @compare_always_false_sge(i16 %a) { 882 %1 = zext i16 %a to i32 883 %2 = sub nsw i32 0, %1 884 %3 = icmp sge i32 %2, 1 885 ret i1 %3 886 887; CHECK-LABEL: @compare_always_false_sge 888; CHECK-NEXT: ret i1 false 889} 890 891define i1 @compare_always_false_eq(i16 %a) { 892 %1 = zext i16 %a to i32 893 %2 = sub nsw i32 0, %1 894 %3 = icmp eq i32 %2, 1 895 ret i1 %3 896 897; CHECK-LABEL: @compare_always_false_eq 898; CHECK-NEXT: ret i1 false 899} 900 901define i1 @compare_always_false_ne(i16 %a) { 902 %1 = zext i16 %a to i32 903 %2 = sub nsw i32 0, %1 904 %3 = icmp ne i32 %2, 1 905 ret i1 %3 906 907; CHECK-LABEL: @compare_always_false_ne 908; CHECK-NEXT: ret i1 true 909} 910 911define i1 @lshr_ugt_false(i32 %a) { 912 %shr = lshr i32 1, %a 913 %cmp = icmp ugt i32 %shr, 1 914 ret i1 %cmp 915; CHECK-LABEL: @lshr_ugt_false 916; CHECK-NEXT: ret i1 false 917} 918 919define i1 @nonnull_arg(i32* nonnull %i) { 920 %cmp = icmp eq i32* %i, null 921 ret i1 %cmp 922; CHECK-LABEL: @nonnull_arg 923; CHECK: ret i1 false 924} 925 926define i1 @nonnull_arg_no_null_opt(i32* nonnull %i) #0 { 927 %cmp = icmp eq i32* %i, null 928 ret i1 %cmp 929; CHECK-LABEL: @nonnull_arg_no_null_opt 930; CHECK: ret i1 false 931} 932 933define i1 @nonnull_deref_arg(i32* dereferenceable(4) %i) { 934 %cmp = icmp eq i32* %i, null 935 ret i1 %cmp 936; CHECK-LABEL: @nonnull_deref_arg 937; CHECK: ret i1 false 938} 939 940define i1 @nonnull_deref_arg_no_null_opt(i32* dereferenceable(4) %i) #0 { 941 %cmp = icmp eq i32* %i, null 942 ret i1 %cmp 943; CHECK-LABEL: @nonnull_deref_arg_no_null_opt 944; CHECK-NEXT: icmp 945; CHECK: ret 946} 947define i1 @nonnull_deref_as_arg(i32 addrspace(1)* dereferenceable(4) %i) { 948 %cmp = icmp eq i32 addrspace(1)* %i, null 949 ret i1 %cmp 950; CHECK-LABEL: @nonnull_deref_as_arg 951; CHECK: icmp 952; CHECK: ret 953} 954 955declare nonnull i32* @returns_nonnull_helper() 956define i1 @returns_nonnull() { 957 %call = call nonnull i32* @returns_nonnull_helper() 958 %cmp = icmp eq i32* %call, null 959 ret i1 %cmp 960; CHECK-LABEL: @returns_nonnull 961; CHECK: ret i1 false 962} 963 964declare dereferenceable(4) i32* @returns_nonnull_deref_helper() 965define i1 @returns_nonnull_deref() { 966 %call = call dereferenceable(4) i32* @returns_nonnull_deref_helper() 967 %cmp = icmp eq i32* %call, null 968 ret i1 %cmp 969; CHECK-LABEL: @returns_nonnull_deref 970; CHECK: ret i1 false 971} 972 973define i1 @returns_nonnull_deref_no_null_opt () #0 { 974 %call = call dereferenceable(4) i32* @returns_nonnull_deref_helper() 975 %cmp = icmp eq i32* %call, null 976 ret i1 %cmp 977; CHECK-LABEL: @returns_nonnull_deref_no_null_opt 978; CHECK: icmp 979; CHECK: ret 980} 981 982declare dereferenceable(4) i32 addrspace(1)* @returns_nonnull_deref_as_helper() 983define i1 @returns_nonnull_as_deref() { 984 %call = call dereferenceable(4) i32 addrspace(1)* @returns_nonnull_deref_as_helper() 985 %cmp = icmp eq i32 addrspace(1)* %call, null 986 ret i1 %cmp 987; CHECK-LABEL: @returns_nonnull_as_deref 988; CHECK: icmp 989; CHECK: ret 990} 991 992define i1 @nonnull_load(i32** %addr) { 993 %ptr = load i32*, i32** %addr, !nonnull !{} 994 %cmp = icmp eq i32* %ptr, null 995 ret i1 %cmp 996; CHECK-LABEL: @nonnull_load 997; CHECK: ret i1 false 998} 999 1000define i1 @nonnull_load_as_outer(i32* addrspace(1)* %addr) { 1001 %ptr = load i32*, i32* addrspace(1)* %addr, !nonnull !{} 1002 %cmp = icmp eq i32* %ptr, null 1003 ret i1 %cmp 1004; CHECK-LABEL: @nonnull_load_as_outer 1005; CHECK: ret i1 false 1006} 1007define i1 @nonnull_load_as_inner(i32 addrspace(1)** %addr) { 1008 %ptr = load i32 addrspace(1)*, i32 addrspace(1)** %addr, !nonnull !{} 1009 %cmp = icmp eq i32 addrspace(1)* %ptr, null 1010 ret i1 %cmp 1011; CHECK-LABEL: @nonnull_load_as_inner 1012; CHECK: ret i1 false 1013} 1014 1015; If a bit is known to be zero for A and known to be one for B, 1016; then A and B cannot be equal. 1017define i1 @icmp_eq_const(i32 %a) { 1018; CHECK-LABEL: @icmp_eq_const( 1019; CHECK-NEXT: ret i1 false 1020; 1021 %b = mul nsw i32 %a, -2 1022 %c = icmp eq i32 %b, 1 1023 ret i1 %c 1024} 1025 1026define <2 x i1> @icmp_eq_const_vec(<2 x i32> %a) { 1027; CHECK-LABEL: @icmp_eq_const_vec( 1028; CHECK-NEXT: ret <2 x i1> zeroinitializer 1029; 1030 %b = mul nsw <2 x i32> %a, <i32 -2, i32 -2> 1031 %c = icmp eq <2 x i32> %b, <i32 1, i32 1> 1032 ret <2 x i1> %c 1033} 1034 1035define i1 @icmp_ne_const(i32 %a) { 1036; CHECK-LABEL: @icmp_ne_const( 1037; CHECK-NEXT: ret i1 true 1038; 1039 %b = mul nsw i32 %a, -2 1040 %c = icmp ne i32 %b, 1 1041 ret i1 %c 1042} 1043 1044define <2 x i1> @icmp_ne_const_vec(<2 x i32> %a) { 1045; CHECK-LABEL: @icmp_ne_const_vec( 1046; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true> 1047; 1048 %b = mul nsw <2 x i32> %a, <i32 -2, i32 -2> 1049 %c = icmp ne <2 x i32> %b, <i32 1, i32 1> 1050 ret <2 x i1> %c 1051} 1052 1053define i1 @icmp_sdiv_int_min(i32 %a) { 1054 %div = sdiv i32 -2147483648, %a 1055 %cmp = icmp ne i32 %div, -1073741824 1056 ret i1 %cmp 1057 1058; CHECK-LABEL: @icmp_sdiv_int_min 1059; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 -2147483648, %a 1060; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[DIV]], -1073741824 1061; CHECK-NEXT: ret i1 [[CMP]] 1062} 1063 1064define i1 @icmp_sdiv_pr20288(i64 %a) { 1065 %div = sdiv i64 %a, -8589934592 1066 %cmp = icmp ne i64 %div, 1073741824 1067 ret i1 %cmp 1068 1069; CHECK-LABEL: @icmp_sdiv_pr20288 1070; CHECK-NEXT: [[DIV:%.*]] = sdiv i64 %a, -8589934592 1071; CHECK-NEXT: [[CMP:%.*]] = icmp ne i64 [[DIV]], 1073741824 1072; CHECK-NEXT: ret i1 [[CMP]] 1073} 1074 1075define i1 @icmp_sdiv_neg1(i64 %a) { 1076 %div = sdiv i64 %a, -1 1077 %cmp = icmp ne i64 %div, 1073741824 1078 ret i1 %cmp 1079 1080; CHECK-LABEL: @icmp_sdiv_neg1 1081; CHECK-NEXT: [[DIV:%.*]] = sdiv i64 %a, -1 1082; CHECK-NEXT: [[CMP:%.*]] = icmp ne i64 [[DIV]], 1073741824 1083; CHECK-NEXT: ret i1 [[CMP]] 1084} 1085 1086define i1 @icmp_known_bits(i4 %x, i4 %y) { 1087 %and1 = and i4 %y, -7 1088 %and2 = and i4 %x, -7 1089 %or1 = or i4 %and1, 2 1090 %or2 = or i4 %and2, 2 1091 %add = add i4 %or1, %or2 1092 %cmp = icmp eq i4 %add, 0 1093 ret i1 %cmp 1094 1095; CHECK-LABEL: @icmp_known_bits 1096; CHECK-NEXT: ret i1 false 1097} 1098 1099define i1 @icmp_shl_nuw_1(i64 %a) { 1100 %shl = shl nuw i64 1, %a 1101 %cmp = icmp ne i64 %shl, 0 1102 ret i1 %cmp 1103 1104; CHECK-LABEL: @icmp_shl_nuw_1 1105; CHECK-NEXT: ret i1 true 1106} 1107 1108define i1 @icmp_shl_1_V_ugt_2147483648(i32 %V) { 1109 %shl = shl i32 1, %V 1110 %cmp = icmp ugt i32 %shl, 2147483648 1111 ret i1 %cmp 1112 1113; CHECK-LABEL: @icmp_shl_1_V_ugt_2147483648( 1114; CHECK-NEXT: ret i1 false 1115} 1116 1117define i1 @icmp_shl_1_V_ule_2147483648(i32 %V) { 1118 %shl = shl i32 1, %V 1119 %cmp = icmp ule i32 %shl, 2147483648 1120 ret i1 %cmp 1121 1122; CHECK-LABEL: @icmp_shl_1_V_ule_2147483648( 1123; CHECK-NEXT: ret i1 true 1124} 1125 1126define i1 @icmp_shl_1_V_eq_31(i32 %V) { 1127 %shl = shl i32 1, %V 1128 %cmp = icmp eq i32 %shl, 31 1129 ret i1 %cmp 1130 1131; CHECK-LABEL: @icmp_shl_1_V_eq_31( 1132; CHECK-NEXT: ret i1 false 1133} 1134 1135define i1 @icmp_shl_1_V_ne_31(i32 %V) { 1136 %shl = shl i32 1, %V 1137 %cmp = icmp ne i32 %shl, 31 1138 ret i1 %cmp 1139 1140; CHECK-LABEL: @icmp_shl_1_V_ne_31( 1141; CHECK-NEXT: ret i1 true 1142} 1143 1144define i1 @tautological1(i32 %A, i32 %B) { 1145 %C = and i32 %A, %B 1146 %D = icmp ugt i32 %C, %A 1147 ret i1 %D 1148; CHECK-LABEL: @tautological1( 1149; CHECK: ret i1 false 1150} 1151 1152define i1 @tautological2(i32 %A, i32 %B) { 1153 %C = and i32 %A, %B 1154 %D = icmp ule i32 %C, %A 1155 ret i1 %D 1156; CHECK-LABEL: @tautological2( 1157; CHECK: ret i1 true 1158} 1159 1160define i1 @tautological3(i32 %A, i32 %B) { 1161 %C = or i32 %A, %B 1162 %D = icmp ule i32 %A, %C 1163 ret i1 %D 1164; CHECK-LABEL: @tautological3( 1165; CHECK: ret i1 true 1166} 1167 1168define i1 @tautological4(i32 %A, i32 %B) { 1169 %C = or i32 %A, %B 1170 %D = icmp ugt i32 %A, %C 1171 ret i1 %D 1172; CHECK-LABEL: @tautological4( 1173; CHECK: ret i1 false 1174} 1175 1176define i1 @tautological5(i32 %A, i32 %B) { 1177 %C = or i32 %A, %B 1178 %D = icmp ult i32 %C, %A 1179 ret i1 %D 1180; CHECK-LABEL: @tautological5( 1181; CHECK: ret i1 false 1182} 1183 1184define i1 @tautological6(i32 %A, i32 %B) { 1185 %C = or i32 %A, %B 1186 %D = icmp uge i32 %C, %A 1187 ret i1 %D 1188; CHECK-LABEL: @tautological6( 1189; CHECK: ret i1 true 1190} 1191 1192define i1 @tautological7(i32 %A, i32 %B) { 1193 %C = and i32 %A, %B 1194 %D = icmp uge i32 %A, %C 1195 ret i1 %D 1196; CHECK-LABEL: @tautological7( 1197; CHECK: ret i1 true 1198} 1199 1200define i1 @tautological8(i32 %A, i32 %B) { 1201 %C = and i32 %A, %B 1202 %D = icmp ult i32 %A, %C 1203 ret i1 %D 1204; CHECK-LABEL: @tautological8( 1205; CHECK: ret i1 false 1206} 1207 1208declare void @helper_i1(i1) 1209; Series of tests for icmp s[lt|ge] (or A, B), A and icmp s[gt|le] A, (or A, B) 1210define void @icmp_slt_sge_or(i32 %Ax, i32 %Bx) { 1211; 'p' for positive, 'n' for negative, 'x' for potentially either. 1212; %D is 'icmp slt (or A, B), A' 1213; %E is 'icmp sge (or A, B), A' making it the not of %D 1214; %F is 'icmp sgt A, (or A, B)' making it the same as %D 1215; %G is 'icmp sle A, (or A, B)' making it the not of %D 1216 %Aneg = or i32 %Ax, 2147483648 1217 %Apos = and i32 %Ax, 2147483647 1218 %Bneg = or i32 %Bx, 2147483648 1219 %Bpos = and i32 %Bx, 2147483647 1220 1221 %Cpp = or i32 %Apos, %Bpos 1222 %Dpp = icmp slt i32 %Cpp, %Apos 1223 %Epp = icmp sge i32 %Cpp, %Apos 1224 %Fpp = icmp sgt i32 %Apos, %Cpp 1225 %Gpp = icmp sle i32 %Apos, %Cpp 1226 %Cpx = or i32 %Apos, %Bx 1227 %Dpx = icmp slt i32 %Cpx, %Apos 1228 %Epx = icmp sge i32 %Cpx, %Apos 1229 %Fpx = icmp sgt i32 %Apos, %Cpx 1230 %Gpx = icmp sle i32 %Apos, %Cpx 1231 %Cpn = or i32 %Apos, %Bneg 1232 %Dpn = icmp slt i32 %Cpn, %Apos 1233 %Epn = icmp sge i32 %Cpn, %Apos 1234 %Fpn = icmp sgt i32 %Apos, %Cpn 1235 %Gpn = icmp sle i32 %Apos, %Cpn 1236 1237 %Cxp = or i32 %Ax, %Bpos 1238 %Dxp = icmp slt i32 %Cxp, %Ax 1239 %Exp = icmp sge i32 %Cxp, %Ax 1240 %Fxp = icmp sgt i32 %Ax, %Cxp 1241 %Gxp = icmp sle i32 %Ax, %Cxp 1242 %Cxx = or i32 %Ax, %Bx 1243 %Dxx = icmp slt i32 %Cxx, %Ax 1244 %Exx = icmp sge i32 %Cxx, %Ax 1245 %Fxx = icmp sgt i32 %Ax, %Cxx 1246 %Gxx = icmp sle i32 %Ax, %Cxx 1247 %Cxn = or i32 %Ax, %Bneg 1248 %Dxn = icmp slt i32 %Cxn, %Ax 1249 %Exn = icmp sge i32 %Cxn, %Ax 1250 %Fxn = icmp sgt i32 %Ax, %Cxn 1251 %Gxn = icmp sle i32 %Ax, %Cxn 1252 1253 %Cnp = or i32 %Aneg, %Bpos 1254 %Dnp = icmp slt i32 %Cnp, %Aneg 1255 %Enp = icmp sge i32 %Cnp, %Aneg 1256 %Fnp = icmp sgt i32 %Aneg, %Cnp 1257 %Gnp = icmp sle i32 %Aneg, %Cnp 1258 %Cnx = or i32 %Aneg, %Bx 1259 %Dnx = icmp slt i32 %Cnx, %Aneg 1260 %Enx = icmp sge i32 %Cnx, %Aneg 1261 %Fnx = icmp sgt i32 %Aneg, %Cnx 1262 %Gnx = icmp sle i32 %Aneg, %Cnx 1263 %Cnn = or i32 %Aneg, %Bneg 1264 %Dnn = icmp slt i32 %Cnn, %Aneg 1265 %Enn = icmp sge i32 %Cnn, %Aneg 1266 %Fnn = icmp sgt i32 %Aneg, %Cnn 1267 %Gnn = icmp sle i32 %Aneg, %Cnn 1268 1269 call void @helper_i1(i1 %Dpp) 1270 call void @helper_i1(i1 %Epp) 1271 call void @helper_i1(i1 %Fpp) 1272 call void @helper_i1(i1 %Gpp) 1273 call void @helper_i1(i1 %Dpx) 1274 call void @helper_i1(i1 %Epx) 1275 call void @helper_i1(i1 %Fpx) 1276 call void @helper_i1(i1 %Gpx) 1277 call void @helper_i1(i1 %Dpn) 1278 call void @helper_i1(i1 %Epn) 1279 call void @helper_i1(i1 %Fpn) 1280 call void @helper_i1(i1 %Gpn) 1281 call void @helper_i1(i1 %Dxp) 1282 call void @helper_i1(i1 %Exp) 1283 call void @helper_i1(i1 %Fxp) 1284 call void @helper_i1(i1 %Gxp) 1285 call void @helper_i1(i1 %Dxx) 1286 call void @helper_i1(i1 %Exx) 1287 call void @helper_i1(i1 %Fxx) 1288 call void @helper_i1(i1 %Gxx) 1289 call void @helper_i1(i1 %Dxn) 1290 call void @helper_i1(i1 %Exn) 1291 call void @helper_i1(i1 %Fxn) 1292 call void @helper_i1(i1 %Gxn) 1293 call void @helper_i1(i1 %Dnp) 1294 call void @helper_i1(i1 %Enp) 1295 call void @helper_i1(i1 %Fnp) 1296 call void @helper_i1(i1 %Gnp) 1297 call void @helper_i1(i1 %Dnx) 1298 call void @helper_i1(i1 %Enx) 1299 call void @helper_i1(i1 %Fnx) 1300 call void @helper_i1(i1 %Gnx) 1301 call void @helper_i1(i1 %Dnn) 1302 call void @helper_i1(i1 %Enn) 1303 call void @helper_i1(i1 %Fnn) 1304 call void @helper_i1(i1 %Gnn) 1305; CHECK-LABEL: @icmp_slt_sge_or 1306; CHECK: call void @helper_i1(i1 false) 1307; CHECK: call void @helper_i1(i1 true) 1308; CHECK: call void @helper_i1(i1 false) 1309; CHECK: call void @helper_i1(i1 true) 1310; CHECK: call void @helper_i1(i1 %Dpx) 1311; CHECK: call void @helper_i1(i1 %Epx) 1312; CHECK: call void @helper_i1(i1 %Fpx) 1313; CHECK: call void @helper_i1(i1 %Gpx) 1314; CHECK: call void @helper_i1(i1 true) 1315; CHECK: call void @helper_i1(i1 false) 1316; CHECK: call void @helper_i1(i1 true) 1317; CHECK: call void @helper_i1(i1 false) 1318; CHECK: call void @helper_i1(i1 false) 1319; CHECK: call void @helper_i1(i1 true) 1320; CHECK: call void @helper_i1(i1 false) 1321; CHECK: call void @helper_i1(i1 true) 1322; CHECK: call void @helper_i1(i1 %Dxx) 1323; CHECK: call void @helper_i1(i1 %Exx) 1324; CHECK: call void @helper_i1(i1 %Fxx) 1325; CHECK: call void @helper_i1(i1 %Gxx) 1326; CHECK: call void @helper_i1(i1 %Dxn) 1327; CHECK: call void @helper_i1(i1 %Exn) 1328; CHECK: call void @helper_i1(i1 %Fxn) 1329; CHECK: call void @helper_i1(i1 %Gxn) 1330; CHECK: call void @helper_i1(i1 false) 1331; CHECK: call void @helper_i1(i1 true) 1332; CHECK: call void @helper_i1(i1 false) 1333; CHECK: call void @helper_i1(i1 true) 1334; CHECK: call void @helper_i1(i1 false) 1335; CHECK: call void @helper_i1(i1 true) 1336; CHECK: call void @helper_i1(i1 false) 1337; CHECK: call void @helper_i1(i1 true) 1338; CHECK: call void @helper_i1(i1 false) 1339; CHECK: call void @helper_i1(i1 true) 1340; CHECK: call void @helper_i1(i1 false) 1341; CHECK: call void @helper_i1(i1 true) 1342 ret void 1343} 1344 1345define i1 @constant_fold_inttoptr_null() { 1346; CHECK-LABEL: @constant_fold_inttoptr_null( 1347; CHECK-NEXT: ret i1 false 1348; 1349 %x = icmp eq i32* inttoptr (i64 32 to i32*), null 1350 ret i1 %x 1351} 1352 1353define i1 @constant_fold_null_inttoptr() { 1354; CHECK-LABEL: @constant_fold_null_inttoptr( 1355; CHECK-NEXT: ret i1 false 1356; 1357 %x = icmp eq i32* null, inttoptr (i64 32 to i32*) 1358 ret i1 %x 1359} 1360 1361attributes #0 = { "null-pointer-is-valid"="true" } 1362