1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -ipsccp -S | FileCheck %s 3 4declare void @use(i1) 5 6define void @f1(i32 %a, i32 %b) { 7; CHECK-LABEL: @f1( 8; CHECK-NEXT: entry: 9; CHECK-NEXT: [[A_255:%.*]] = and i32 [[A:%.*]], 255 10; CHECK-NEXT: [[A_2:%.*]] = add i32 [[A_255]], 20 11; CHECK-NEXT: [[BC:%.*]] = icmp ugt i32 [[B:%.*]], [[A_2]] 12; CHECK-NEXT: br i1 [[BC]], label [[TRUE:%.*]], label [[FALSE:%.*]] 13; CHECK: true: 14; CHECK-NEXT: call void @use(i1 false) 15; CHECK-NEXT: call void @use(i1 false) 16; CHECK-NEXT: call void @use(i1 false) 17; CHECK-NEXT: call void @use(i1 true) 18; CHECK-NEXT: call void @use(i1 true) 19; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[B]], 21 20; CHECK-NEXT: call void @use(i1 [[C_1]]) 21; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i32 [[B]], 21 22; CHECK-NEXT: call void @use(i1 [[C_2]]) 23; CHECK-NEXT: [[C_3:%.*]] = icmp ugt i32 [[B]], 255 24; CHECK-NEXT: call void @use(i1 [[C_3]]) 25; CHECK-NEXT: ret void 26; CHECK: false: 27; CHECK-NEXT: call void @use(i1 false) 28; CHECK-NEXT: call void @use(i1 false) 29; CHECK-NEXT: call void @use(i1 true) 30; CHECK-NEXT: call void @use(i1 true) 31; CHECK-NEXT: [[C_4:%.*]] = icmp eq i32 [[B]], 21 32; CHECK-NEXT: call void @use(i1 [[C_4]]) 33; CHECK-NEXT: [[C_5:%.*]] = icmp eq i32 [[B]], 275 34; CHECK-NEXT: call void @use(i1 [[C_5]]) 35; CHECK-NEXT: ret void 36; 37entry: 38 %a.255 = and i32 %a, 255 39 %a.2 = add i32 %a.255, 20 40 %bc = icmp ugt i32 %b, %a.2 41 br i1 %bc, label %true, label %false 42 43true: ; %b in [21, 0) 44 ; Conditions below are false. 45 %f.1 = icmp eq i32 %b, 0 46 call void @use(i1 %f.1) 47 %f.2 = icmp eq i32 %b, 20 48 call void @use(i1 %f.2) 49 %f.3 = icmp ult i32 %b, 20 50 call void @use(i1 %f.3) 51 52 ; Conditions below are true. 53 %t.1 = icmp ugt i32 %b, 5 54 call void @use(i1 %t.1) 55 %t.2 = icmp ne i32 %b, 20 56 call void @use(i1 %t.2) 57 58 ; Conditions below cannot be simplified. 59 %c.1 = icmp eq i32 %b, 21 60 call void @use(i1 %c.1) 61 %c.2 = icmp ugt i32 %b, 21 62 call void @use(i1 %c.2) 63 %c.3 = icmp ugt i32 %b, 255 64 call void @use(i1 %c.3) 65 ret void 66 67false: ;%b in [0, 276) 68 ; Conditions below are false; 69 %f.4 = icmp eq i32 %b, 276 70 call void @use(i1 %f.4) 71 %f.5 = icmp ugt i32 %b, 275 72 call void @use(i1 %f.5) 73 74 ; Conditions below are true; 75 %t.3 = icmp ne i32 %b, 276 76 call void @use(i1 %t.3) 77 %t.4 = icmp ule i32 %b, 275 78 call void @use(i1 %t.4) 79 80 ; Conditions below cannot be simplified. 81 %c.4 = icmp eq i32 %b, 21 82 call void @use(i1 %c.4) 83 %c.5 = icmp eq i32 %b, 275 84 call void @use(i1 %c.5) 85 ret void 86} 87 88; TODO: Use information %a != 0 in false branch. 89define void @f2_ptr(i8* %a, i8* %b) { 90; CHECK-LABEL: @f2_ptr( 91; CHECK-NEXT: entry: 92; CHECK-NEXT: [[BC:%.*]] = icmp eq i8* [[A:%.*]], null 93; CHECK-NEXT: br i1 [[BC]], label [[TRUE:%.*]], label [[FALSE:%.*]] 94; CHECK: true: 95; CHECK-NEXT: call void @use(i1 false) 96; CHECK-NEXT: call void @use(i1 true) 97; CHECK-NEXT: [[C_1:%.*]] = icmp eq i8* null, [[B:%.*]] 98; CHECK-NEXT: call void @use(i1 [[C_1]]) 99; CHECK-NEXT: ret void 100; CHECK: false: 101; CHECK-NEXT: [[F_2:%.*]] = icmp eq i8* [[A]], null 102; CHECK-NEXT: call void @use(i1 [[F_2]]) 103; CHECK-NEXT: [[T_2:%.*]] = icmp ne i8* [[A]], null 104; CHECK-NEXT: call void @use(i1 [[T_2]]) 105; CHECK-NEXT: [[C_2:%.*]] = icmp eq i8* [[A]], [[B]] 106; CHECK-NEXT: call void @use(i1 [[C_2]]) 107; CHECK-NEXT: ret void 108; 109entry: 110 %bc = icmp eq i8* %a, null 111 br i1 %bc, label %true, label %false 112 113true: ; %a == 0 114 %f.1 = icmp ne i8* %a, null 115 call void @use(i1 %f.1) 116 117 %t.1 = icmp eq i8* %a, null 118 call void @use(i1 %t.1) 119 120 %c.1 = icmp eq i8* %a, %b 121 call void @use(i1 %c.1) 122 ret void 123 124false: ; %a != 0 125 %f.2 = icmp eq i8* %a, null 126 call void @use(i1 %f.2) 127 128 %t.2 = icmp ne i8* %a, null 129 call void @use(i1 %t.2) 130 131 %c.2 = icmp eq i8* %a, %b 132 call void @use(i1 %c.2) 133 ret void 134} 135 136define i8* @f3(i8* %a, i8* %b, i1 %c) { 137; CHECK-LABEL: @f3( 138; CHECK-NEXT: entry: 139; CHECK-NEXT: [[C_1:%.*]] = icmp eq i8* [[A:%.*]], null 140; CHECK-NEXT: br i1 [[C_1]], label [[TRUE:%.*]], label [[FALSE:%.*]] 141; CHECK: true: 142; CHECK-NEXT: br i1 [[C:%.*]], label [[TRUE_2:%.*]], label [[FALSE_2:%.*]] 143; CHECK: true.2: 144; CHECK-NEXT: br label [[EXIT_2:%.*]] 145; CHECK: false.2: 146; CHECK-NEXT: br label [[EXIT_2]] 147; CHECK: exit.2: 148; CHECK-NEXT: [[P:%.*]] = phi i8* [ null, [[TRUE_2]] ], [ [[B:%.*]], [[FALSE_2]] ] 149; CHECK-NEXT: ret i8* [[P]] 150; CHECK: false: 151; CHECK-NEXT: ret i8* null 152; 153entry: 154 %c.1 = icmp eq i8* %a, null 155 br i1 %c.1, label %true, label %false 156 157true: 158 br i1 %c, label %true.2, label %false.2 159 160true.2: 161 br label %exit.2 162 163false.2: 164 br label %exit.2 165 166exit.2: 167 %p = phi i8* [ %a, %true.2 ], [ %b, %false.2 ] 168 ret i8* %p 169 170false: 171 ret i8* null 172} 173 174define i32 @f5(i64 %sz) { 175; CHECK-LABEL: @f5( 176; CHECK-NEXT: entry: 177; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 4088, [[SZ:%.*]] 178; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]] 179; CHECK: cond.true: 180; CHECK-NEXT: [[DIV:%.*]] = udiv i64 4088, [[SZ]] 181; CHECK-NEXT: br label [[COND_END]] 182; CHECK: cond.end: 183; CHECK-NEXT: [[COND:%.*]] = phi i64 [ [[DIV]], [[COND_TRUE]] ], [ 1, [[ENTRY:%.*]] ] 184; CHECK-NEXT: [[CONV:%.*]] = trunc i64 [[COND]] to i32 185; CHECK-NEXT: ret i32 [[CONV]] 186; 187entry: 188 %cmp = icmp ugt i64 4088, %sz 189 br i1 %cmp, label %cond.true, label %cond.end 190 191cond.true: ; preds = %entry 192 %div = udiv i64 4088, %sz 193 br label %cond.end 194 195cond.end: ; preds = %entry, %cond.true 196 %cond = phi i64 [ %div, %cond.true ], [ 1, %entry ] 197 %conv = trunc i64 %cond to i32 198 ret i32 %conv 199} 200 201define void @f6(i32 %b) { 202; CHECK-LABEL: @f6( 203; CHECK-NEXT: entry: 204; CHECK-NEXT: [[C_1:%.*]] = icmp ugt i32 [[B:%.*]], 20 205; CHECK-NEXT: br i1 [[C_1]], label [[TRUE:%.*]], label [[FALSE:%.*]] 206; CHECK: true: 207; CHECK-NEXT: call void @use(i1 true) 208; CHECK-NEXT: ret void 209; CHECK: false: 210; CHECK-NEXT: ret void 211; 212entry: 213 %a = add i32 10, 10 214 %c.1 = icmp ugt i32 %b, %a 215 br i1 %c.1, label %true, label %false 216 217true: 218 %c.2 = icmp eq i32 %a, 20 219 call void @use(i1 %c.2) 220 ret void 221 222false: 223 ret void 224} 225 226; Test with 2 unrelated nested conditions. 227define void @f7_nested_conds(i32* %a, i32 %b) { 228; CHECK-LABEL: @f7_nested_conds( 229; CHECK-NEXT: entry: 230; CHECK-NEXT: [[A_V:%.*]] = load i32, i32* [[A:%.*]], align 4 231; CHECK-NEXT: [[C_1:%.*]] = icmp ne i32 [[A_V]], 0 232; CHECK-NEXT: br i1 [[C_1]], label [[TRUE:%.*]], label [[FALSE:%.*]] 233; CHECK: false: 234; CHECK-NEXT: br label [[TRUE_2:%.*]] 235; CHECK: true.2: 236; CHECK-NEXT: call void @use(i1 true) 237; CHECK-NEXT: ret void 238; CHECK: true: 239; CHECK-NEXT: store i32 [[B:%.*]], i32* [[A]], align 4 240; CHECK-NEXT: ret void 241; 242entry: 243 %a.v = load i32, i32* %a 244 %c.1 = icmp ne i32 %a.v, 0 245 br i1 %c.1, label %true, label %false 246 247false: 248 %c.2 = icmp ult i32 %a.v, 3 249 br i1 %c.2, label %true.2, label %true 250 251true.2: 252 %c.3 = icmp eq i32 %a.v, 0 253 call void @use(i1 %c.3) 254 ret void 255 256true: 257 store i32 %b, i32* %a 258 ret void 259} 260 261; Test with 2 related nested conditions (%b > [20, 276) && %b < 255). 262define void @f8_nested_conds(i32 %a, i32 %b) { 263; CHECK-LABEL: @f8_nested_conds( 264; CHECK-NEXT: entry: 265; CHECK-NEXT: [[A_255:%.*]] = and i32 [[A:%.*]], 255 266; CHECK-NEXT: [[A_2:%.*]] = add i32 [[A_255]], 20 267; CHECK-NEXT: [[BC_1:%.*]] = icmp ugt i32 [[B:%.*]], [[A_2]] 268; CHECK-NEXT: br i1 [[BC_1]], label [[TRUE:%.*]], label [[FALSE:%.*]] 269; CHECK: true: 270; CHECK-NEXT: [[BC_2:%.*]] = icmp ult i32 [[B]], 255 271; CHECK-NEXT: br i1 [[BC_2]], label [[TRUE_2:%.*]], label [[FALSE_2:%.*]] 272; CHECK: true.2: 273; CHECK-NEXT: call void @use(i1 false) 274; CHECK-NEXT: call void @use(i1 false) 275; CHECK-NEXT: call void @use(i1 false) 276; CHECK-NEXT: call void @use(i1 false) 277; CHECK-NEXT: call void @use(i1 false) 278; CHECK-NEXT: call void @use(i1 true) 279; CHECK-NEXT: call void @use(i1 true) 280; CHECK-NEXT: call void @use(i1 true) 281; CHECK-NEXT: call void @use(i1 true) 282; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[B]], 21 283; CHECK-NEXT: call void @use(i1 [[C_1]]) 284; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i32 [[B]], 21 285; CHECK-NEXT: call void @use(i1 [[C_2]]) 286; CHECK-NEXT: [[C_3:%.*]] = icmp ugt i32 [[B]], 34 287; CHECK-NEXT: call void @use(i1 [[C_3]]) 288; CHECK-NEXT: ret void 289; CHECK: false.2: 290; CHECK-NEXT: call void @use(i1 false) 291; CHECK-NEXT: call void @use(i1 false) 292; CHECK-NEXT: call void @use(i1 true) 293; CHECK-NEXT: call void @use(i1 true) 294; CHECK-NEXT: [[C_4:%.*]] = icmp eq i32 [[B]], 255 295; CHECK-NEXT: call void @use(i1 [[C_4]]) 296; CHECK-NEXT: [[C_5:%.*]] = icmp ne i32 [[B]], 275 297; CHECK-NEXT: call void @use(i1 [[C_5]]) 298; CHECK-NEXT: ret void 299; CHECK: false: 300; CHECK-NEXT: ret void 301; 302entry: 303 %a.255 = and i32 %a, 255 304 %a.2 = add i32 %a.255, 20 305 %bc.1 = icmp ugt i32 %b, %a.2 306 br i1 %bc.1, label %true, label %false 307 308true: ; %b in [21, 0) 309 %bc.2 = icmp ult i32 %b, 255 310 br i1 %bc.2, label %true.2, label %false.2 311 312true.2: ; %b in [21, 255) 313 ; Conditions below are false. 314 %f.1 = icmp eq i32 %b, 0 315 call void @use(i1 %f.1) 316 %f.2 = icmp eq i32 %b, 20 317 call void @use(i1 %f.2) 318 %f.3 = icmp ult i32 %b, 20 319 call void @use(i1 %f.3) 320 %f.4 = icmp eq i32 %b, 255 321 call void @use(i1 %f.4) 322 %f.5 = icmp ugt i32 %b, 255 323 call void @use(i1 %f.5) 324 325 326 ; Conditions below are true. 327 %t.1 = icmp ugt i32 %b, 5 328 call void @use(i1 %t.1) 329 %t.2 = icmp ne i32 %b, 20 330 call void @use(i1 %t.2) 331 %t.3 = icmp ult i32 %b, 255 332 call void @use(i1 %t.3) 333 %t.4 = icmp ne i32 %b, 300 334 call void @use(i1 %t.4) 335 336 ; Conditions below cannot be simplified. 337 %c.1 = icmp eq i32 %b, 21 338 call void @use(i1 %c.1) 339 %c.2 = icmp ugt i32 %b, 21 340 call void @use(i1 %c.2) 341 %c.3 = icmp ugt i32 %b, 34 342 call void @use(i1 %c.3) 343 ret void 344 345false.2: ;%b in [255, 0) 346 ; Conditions below are false; 347 %f.6 = icmp eq i32 %b, 254 348 call void @use(i1 %f.6) 349 %f.7 = icmp ult i32 %b, 255 350 call void @use(i1 %f.7) 351 352 ; Conditions below are true; 353 %t.5 = icmp ne i32 %b, 254 354 call void @use(i1 %t.5) 355 %t.6 = icmp uge i32 %b, 255 356 call void @use(i1 %t.6) 357 358 ; Conditions below cannot be simplified. 359 %c.4 = icmp eq i32 %b, 255 360 call void @use(i1 %c.4) 361 %c.5 = icmp ne i32 %b, 275 362 call void @use(i1 %c.5) 363 ret void 364 365false: 366 ret void 367} 368 369; Test with with nested conditions where the second conditions is more limiting than the first one. 370define void @f9_nested_conds(i32 %a, i32 %b) { 371; CHECK-LABEL: @f9_nested_conds( 372; CHECK-NEXT: entry: 373; CHECK-NEXT: [[BC_1:%.*]] = icmp ugt i32 [[B:%.*]], 10 374; CHECK-NEXT: br i1 [[BC_1]], label [[TRUE:%.*]], label [[FALSE:%.*]] 375; CHECK: true: 376; CHECK-NEXT: call void @use(i1 false) 377; CHECK-NEXT: call void @use(i1 false) 378; CHECK-NEXT: call void @use(i1 true) 379; CHECK-NEXT: call void @use(i1 true) 380; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[B]], 11 381; CHECK-NEXT: call void @use(i1 [[C_1]]) 382; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i32 [[B]], 11 383; CHECK-NEXT: call void @use(i1 [[C_2]]) 384; CHECK-NEXT: [[BC_2:%.*]] = icmp ugt i32 [[B]], 20 385; CHECK-NEXT: br i1 [[BC_2]], label [[TRUE_2:%.*]], label [[FALSE_2:%.*]] 386; CHECK: true.2: 387; CHECK-NEXT: call void @use(i1 false) 388; CHECK-NEXT: call void @use(i1 false) 389; CHECK-NEXT: call void @use(i1 true) 390; CHECK-NEXT: call void @use(i1 true) 391; CHECK-NEXT: [[C_3:%.*]] = icmp eq i32 [[B]], 21 392; CHECK-NEXT: call void @use(i1 [[C_3]]) 393; CHECK-NEXT: [[C_4:%.*]] = icmp ugt i32 [[B]], 21 394; CHECK-NEXT: call void @use(i1 [[C_4]]) 395; CHECK-NEXT: [[C_5:%.*]] = icmp ugt i32 [[B]], 34 396; CHECK-NEXT: call void @use(i1 [[C_5]]) 397; CHECK-NEXT: ret void 398; CHECK: false.2: 399; CHECK-NEXT: call void @use(i1 false) 400; CHECK-NEXT: call void @use(i1 false) 401; CHECK-NEXT: call void @use(i1 true) 402; CHECK-NEXT: call void @use(i1 true) 403; CHECK-NEXT: call void @use(i1 true) 404; CHECK-NEXT: call void @use(i1 true) 405; CHECK-NEXT: [[C_6:%.*]] = icmp eq i32 [[B]], 11 406; CHECK-NEXT: call void @use(i1 [[C_6]]) 407; CHECK-NEXT: [[C_7:%.*]] = icmp ne i32 [[B]], 15 408; CHECK-NEXT: call void @use(i1 [[C_7]]) 409; CHECK-NEXT: ret void 410; CHECK: false: 411; CHECK-NEXT: ret void 412; 413entry: 414 %bc.1 = icmp ugt i32 %b, 10 415 br i1 %bc.1, label %true, label %false 416 417true: ; %b in [11, 0) 418 ; Conditions below are false. 419 %f.1 = icmp eq i32 %b, 0 420 call void @use(i1 %f.1) 421 %f.2 = icmp eq i32 %b, 10 422 call void @use(i1 %f.2) 423 424 ; Conditions below are true. 425 %t.1 = icmp ugt i32 %b, 5 426 call void @use(i1 %t.1) 427 %t.2 = icmp ne i32 %b, 10 428 call void @use(i1 %t.2) 429 430 ; Conditions below cannot be simplified. 431 %c.1 = icmp eq i32 %b, 11 432 call void @use(i1 %c.1) 433 %c.2 = icmp ugt i32 %b, 11 434 call void @use(i1 %c.2) 435 436 %bc.2 = icmp ugt i32 %b, 20 437 br i1 %bc.2, label %true.2, label %false.2 438 439true.2: ; %b in [21, 0) 440 ; Conditions below are false. 441 %f.3 = icmp eq i32 %b, 11 442 call void @use(i1 %f.3) 443 %f.4 = icmp eq i32 %b, 20 444 call void @use(i1 %f.4) 445 446 ; Conditions below are true. 447 %t.3 = icmp ugt i32 %b, 11 448 call void @use(i1 %t.3) 449 %t.4 = icmp ne i32 %b, 20 450 call void @use(i1 %t.4) 451 452 ; Conditions below cannot be simplified. 453 %c.3 = icmp eq i32 %b, 21 454 call void @use(i1 %c.3) 455 %c.4 = icmp ugt i32 %b, 21 456 call void @use(i1 %c.4) 457 %c.5 = icmp ugt i32 %b, 34 458 call void @use(i1 %c.5) 459 ret void 460 461false.2: ;%b in [11, 21) 462 ; Conditions below are false; 463 %f.5 = icmp eq i32 %b, 21 464 call void @use(i1 %f.5) 465 %f.6 = icmp ugt i32 %b, 21 466 call void @use(i1 %f.6) 467 %f.7 = icmp ne i32 %b, 5 468 call void @use(i1 %f.7) 469 470 ; Conditions below are true; 471 %t.5 = icmp ne i32 %b, 21 472 call void @use(i1 %t.5) 473 %t.6 = icmp ult i32 %b, 21 474 call void @use(i1 %t.6) 475 %t.7 = icmp ne i32 %b, 5 476 call void @use(i1 %t.7) 477 478 ; Conditions below cannot be simplified. 479 %c.6 = icmp eq i32 %b, 11 480 call void @use(i1 %c.6) 481 %c.7 = icmp ne i32 %b, 15 482 call void @use(i1 %c.7) 483 ret void 484 485false: 486 ret void 487} 488 489 490; Test with with nested conditions where the second conditions is more limiting than the first one. 491define void @f10_cond_does_not_restrict_range(i32 %a, i32 %b) { 492; CHECK-LABEL: @f10_cond_does_not_restrict_range( 493; CHECK-NEXT: entry: 494; CHECK-NEXT: [[B_255:%.*]] = and i32 [[B:%.*]], 255 495; CHECK-NEXT: br label [[TRUE:%.*]] 496; CHECK: true: 497; CHECK-NEXT: call void @use(i1 false) 498; CHECK-NEXT: call void @use(i1 false) 499; CHECK-NEXT: call void @use(i1 true) 500; CHECK-NEXT: call void @use(i1 true) 501; CHECK-NEXT: call void @use(i1 true) 502; CHECK-NEXT: call void @use(i1 true) 503; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[B_255]], 11 504; CHECK-NEXT: call void @use(i1 [[C_1]]) 505; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i32 [[B_255]], 30 506; CHECK-NEXT: call void @use(i1 [[C_2]]) 507; CHECK-NEXT: ret void 508; 509entry: 510 %b.255 = and i32 %b, 255 511 %bc.1 = icmp ult i32 %b.255, 300 512 br i1 %bc.1, label %true, label %false 513 514true: ; %b in [0, 256) 515 ; Conditions below are false. 516 %f.1 = icmp eq i32 %b.255, 256 517 call void @use(i1 %f.1) 518 %f.2 = icmp eq i32 %b.255, 300 519 call void @use(i1 %f.2) 520 521 ; Conditions below are true. 522 %t.1 = icmp ult i32 %b.255, 256 523 call void @use(i1 %t.1) 524 %t.2 = icmp ult i32 %b.255, 300 525 call void @use(i1 %t.2) 526 %t.3 = icmp ne i32 %b.255, 256 527 call void @use(i1 %t.3) 528 %t.4 = icmp ne i32 %b.255, 300 529 call void @use(i1 %t.4) 530 531 ; Conditions below cannot be simplified. 532 %c.1 = icmp eq i32 %b.255, 11 533 call void @use(i1 %c.1) 534 %c.2 = icmp ugt i32 %b.255, 30 535 call void @use(i1 %c.2) 536 ret void 537 538false: 539 ret void 540} 541 542define void @f11_contradiction(i32 %a, i32 %b) { 543; CHECK-LABEL: @f11_contradiction( 544; CHECK-NEXT: entry: 545; CHECK-NEXT: [[BC_1:%.*]] = icmp eq i32 [[B:%.*]], 10 546; CHECK-NEXT: br i1 [[BC_1]], label [[TRUE:%.*]], label [[FALSE:%.*]] 547; CHECK: true: 548; CHECK-NEXT: br label [[FALSE]] 549; CHECK: false: 550; CHECK-NEXT: ret void 551; 552entry: 553 %bc.1 = icmp eq i32 %b, 10 554 br i1 %bc.1, label %true, label %false 555 556true: ; %b in [10, 11) 557 %bc.2 = icmp eq i32 %b, 20 558 br i1 %bc.2, label %true.2, label %false 559 560true.2: 561 %f.1 = icmp eq i32 %b, 256 562 call void @use(i1 %f.1) 563 %f.2 = icmp ne i32 %b, 300 564 call void @use(i1 %f.2) 565 ret void 566 567false: 568 ret void 569} 570 571define void @f12_float(float %b) { 572; CHECK-LABEL: @f12_float( 573; CHECK-NEXT: entry: 574; CHECK-NEXT: [[BC_1:%.*]] = fcmp olt float 1.000000e+00, [[B:%.*]] 575; CHECK-NEXT: br i1 [[BC_1]], label [[TRUE:%.*]], label [[FALSE:%.*]] 576; CHECK: true: 577; CHECK-NEXT: call void @use(i1 false) 578; CHECK-NEXT: call void @use(i1 true) 579; CHECK-NEXT: ret void 580; CHECK: false: 581; CHECK-NEXT: ret void 582; 583entry: 584 %a = fadd float 0.0, 1.0 585 %bc.1 = fcmp olt float %a, %b 586 br i1 %bc.1, label %true, label %false 587 588true: ; %b in [10, 11) 589 %f.1 = fcmp one float %a, 1.0 590 call void @use(i1 %f.1) 591 592 %t.1 = fcmp oeq float %a, 1.0 593 call void @use(i1 %t.1) 594 ret void 595 596false: 597 ret void 598} 599 600 601@A = global i32 17 602@B = global i32 17 603 604define void @f13_constexpr1() { 605; CHECK-LABEL: @f13_constexpr1( 606; CHECK-NEXT: entry: 607; CHECK-NEXT: [[BC_1:%.*]] = icmp eq i32 add (i32 ptrtoint (i32* @A to i32), i32 10), 55 608; CHECK-NEXT: br i1 [[BC_1]], label [[TRUE:%.*]], label [[FALSE:%.*]] 609; CHECK: true: 610; CHECK-NEXT: call void @use(i1 false) 611; CHECK-NEXT: call void @use(i1 true) 612; CHECK-NEXT: ret void 613; CHECK: false: 614; CHECK-NEXT: ret void 615; 616entry: 617 %a = add i32 ptrtoint (i32* @A to i32), 10 618 %bc.1 = icmp eq i32 %a, 55 619 br i1 %bc.1, label %true, label %false 620 621true: ; %b in [10, 11) 622 %f.1 = icmp eq i32 %a, 10 623 call void @use(i1 %f.1) 624 %f.2 = icmp eq i32 %a, 55 625 call void @use(i1 %f.2) 626 627 ret void 628 629false: 630 ret void 631} 632 633; TODO: can we fold the compares in the true block? 634define void @f14_constexpr2() { 635; CHECK-LABEL: @f14_constexpr2( 636; CHECK-NEXT: entry: 637; CHECK-NEXT: br i1 icmp eq (i32 ptrtoint (i32* @A to i32), i32 ptrtoint (i32* @B to i32)), label [[TRUE:%.*]], label [[FALSE:%.*]] 638; CHECK: true: 639; CHECK-NEXT: call void @use(i1 icmp ne (i32 ptrtoint (i32* @B to i32), i32 ptrtoint (i32* @A to i32))) 640; CHECK-NEXT: call void @use(i1 icmp eq (i32 ptrtoint (i32* @B to i32), i32 ptrtoint (i32* @A to i32))) 641; CHECK-NEXT: ret void 642; CHECK: false: 643; CHECK-NEXT: ret void 644; 645entry: 646 %a = add i32 ptrtoint (i32* @A to i32), 0 647 %b = add i32 ptrtoint (i32* @B to i32), 0 648 %bc.1 = icmp eq i32 %a, %b 649 br i1 %bc.1, label %true, label %false 650 651true: ; %b in [10, 11) 652 %f.1 = icmp ne i32 %a, %b 653 call void @use(i1 %f.1) 654 %f.2 = icmp eq i32 %a, %b 655 call void @use(i1 %f.2) 656 657 ret void 658 659false: 660 ret void 661} 662 663define void @loop_1() { 664; CHECK-LABEL: @loop_1( 665; CHECK-NEXT: entry: 666; CHECK-NEXT: br label [[FOR_COND:%.*]] 667; CHECK: for.cond: 668; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC27:%.*]], [[FOR_COND_CLEANUP13:%.*]] ] 669; CHECK-NEXT: [[CMP9:%.*]] = icmp sle i32 [[I_0]], 3 670; CHECK-NEXT: br i1 [[CMP9]], label [[FOR_BODY:%.*]], label [[FOR_COND_CLEANUP:%.*]] 671; CHECK: for.cond.cleanup: 672; CHECK-NEXT: ret void 673; CHECK: for.body: 674; CHECK-NEXT: br label [[FOR_COND11:%.*]] 675; CHECK: for.cond11: 676; CHECK-NEXT: br label [[FOR_COND_CLEANUP13]] 677; CHECK: for.cond.cleanup13: 678; CHECK-NEXT: [[INC27]] = add nsw i32 [[I_0]], 1 679; CHECK-NEXT: br label [[FOR_COND]] 680; 681entry: 682 br label %for.cond 683 684for.cond: ; preds = %for.cond.cleanup13, %if.then 685 %i.0 = phi i32 [ 0, %entry ], [ %inc27, %for.cond.cleanup13 ] 686 %cmp9 = icmp sle i32 %i.0, 3 687 br i1 %cmp9, label %for.body, label %for.cond.cleanup 688 689for.cond.cleanup: ; preds = %for.cond 690 ret void 691 692for.body: ; preds = %for.cond 693 br label %for.cond11 694 695for.cond11: ; preds = %arrayctor.cont21, %for.body 696 br label %for.cond.cleanup13 697 698for.cond.cleanup13: ; preds = %for.cond11 699 %inc27 = add nsw i32 %i.0, 1 700 br label %for.cond 701} 702 703 704define void @loop() { 705; CHECK-LABEL: @loop( 706; CHECK-NEXT: entry: 707; CHECK-NEXT: br label [[FOR_COND:%.*]] 708; CHECK: for.cond: 709; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC27:%.*]], [[FOR_COND_CLEANUP13:%.*]] ] 710; CHECK-NEXT: [[CMP9:%.*]] = icmp sle i32 [[I_0]], 3 711; CHECK-NEXT: br i1 [[CMP9]], label [[FOR_BODY:%.*]], label [[FOR_COND_CLEANUP:%.*]] 712; CHECK: for.cond.cleanup: 713; CHECK-NEXT: ret void 714; CHECK: for.body: 715; CHECK-NEXT: br label [[FOR_COND11:%.*]] 716; CHECK: for.cond11: 717; CHECK-NEXT: [[J_0:%.*]] = phi i32 [ 0, [[FOR_BODY]] ], [ [[INC:%.*]], [[FOR_BODY14:%.*]] ] 718; CHECK-NEXT: [[CMP12:%.*]] = icmp slt i32 [[J_0]], 2 719; CHECK-NEXT: br i1 [[CMP12]], label [[FOR_BODY14]], label [[FOR_COND_CLEANUP13]] 720; CHECK: for.cond.cleanup13: 721; CHECK-NEXT: [[INC27]] = add nsw i32 [[I_0]], 1 722; CHECK-NEXT: br label [[FOR_COND]] 723; CHECK: for.body14: 724; CHECK-NEXT: [[INC]] = add nsw i32 [[J_0]], 1 725; CHECK-NEXT: br label [[FOR_COND11]] 726; 727entry: 728 br label %for.cond 729 730for.cond: ; preds = %for.cond.cleanup13, %if.then 731 %i.0 = phi i32 [ 0, %entry ], [ %inc27, %for.cond.cleanup13 ] 732 %cmp9 = icmp sle i32 %i.0, 3 733 br i1 %cmp9, label %for.body, label %for.cond.cleanup 734 735for.cond.cleanup: ; preds = %for.cond 736 ret void 737 738for.body: ; preds = %for.cond 739 br label %for.cond11 740 741for.cond11: ; preds = %arrayctor.cont21, %for.body 742 %j.0 = phi i32 [ 0, %for.body ], [ %inc, %for.body14 ] 743 %cmp12 = icmp slt i32 %j.0, 2 744 br i1 %cmp12, label %for.body14, label %for.cond.cleanup13 745 746for.cond.cleanup13: ; preds = %for.cond11 747 %inc27 = add nsw i32 %i.0, 1 748 br label %for.cond 749 750for.body14: 751 %inc = add nsw i32 %j.0, 1 752 br label %for.cond11 753} 754 755define i32 @udiv_1(i64 %sz) { 756; CHECK-LABEL: @udiv_1( 757; CHECK-NEXT: entry: 758; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 4088, [[SZ:%.*]] 759; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]] 760; CHECK: cond.true: 761; CHECK-NEXT: [[DIV:%.*]] = udiv i64 4088, [[SZ]] 762; CHECK-NEXT: br label [[COND_END]] 763; CHECK: cond.end: 764; CHECK-NEXT: [[COND:%.*]] = phi i64 [ [[DIV]], [[COND_TRUE]] ], [ 1, [[ENTRY:%.*]] ] 765; CHECK-NEXT: [[CONV:%.*]] = trunc i64 [[COND]] to i32 766; CHECK-NEXT: ret i32 [[CONV]] 767; 768entry: 769 %cmp = icmp ugt i64 4088, %sz 770 br i1 %cmp, label %cond.true, label %cond.end 771 772cond.true: ; preds = %entry 773 %div = udiv i64 4088, %sz 774 br label %cond.end 775 776cond.end: ; preds = %entry, %cond.true 777 %cond = phi i64 [ %div, %cond.true ], [ 1, %entry ] 778 %conv = trunc i64 %cond to i32 779 ret i32 %conv 780} 781 782; Same as @udiv_1, but with the condition switched. 783define i32 @udiv_2(i64 %sz) { 784; CHECK-LABEL: @udiv_2( 785; CHECK-NEXT: entry: 786; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i64 [[SZ:%.*]], 4088 787; CHECK-NEXT: br i1 [[CMP]], label [[COND_TRUE:%.*]], label [[COND_END:%.*]] 788; CHECK: cond.true: 789; CHECK-NEXT: br label [[COND_END]] 790; CHECK: cond.end: 791; CHECK-NEXT: [[COND:%.*]] = phi i64 [ 0, [[COND_TRUE]] ], [ 1, [[ENTRY:%.*]] ] 792; CHECK-NEXT: [[CONV:%.*]] = trunc i64 [[COND]] to i32 793; CHECK-NEXT: ret i32 [[CONV]] 794; 795entry: 796 %cmp = icmp ugt i64 %sz, 4088 797 br i1 %cmp, label %cond.true, label %cond.end 798 799cond.true: ; preds = %entry 800 %div = udiv i64 4088, %sz 801 br label %cond.end 802 803cond.end: ; preds = %entry, %cond.true 804 %cond = phi i64 [ %div, %cond.true ], [ 1, %entry ] 805 %conv = trunc i64 %cond to i32 806 ret i32 %conv 807} 808 809define void @f16_conditions_and(i32 %a, i32 %b) { 810; CHECK-LABEL: @f16_conditions_and( 811; CHECK-NEXT: entry: 812; CHECK-NEXT: [[LT:%.*]] = icmp ult i32 [[A:%.*]], 100 813; CHECK-NEXT: [[GT:%.*]] = icmp ugt i32 [[A]], 20 814; CHECK-NEXT: [[BC:%.*]] = and i1 [[LT]], [[GT]] 815; CHECK-NEXT: br i1 [[BC]], label [[TRUE:%.*]], label [[FALSE:%.*]] 816; CHECK: true: 817; CHECK-NEXT: call void @use(i1 false) 818; CHECK-NEXT: call void @use(i1 false) 819; CHECK-NEXT: call void @use(i1 false) 820; CHECK-NEXT: call void @use(i1 true) 821; CHECK-NEXT: call void @use(i1 true) 822; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[A]], 21 823; CHECK-NEXT: call void @use(i1 [[C_1]]) 824; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i32 [[A]], 21 825; CHECK-NEXT: call void @use(i1 [[C_2]]) 826; CHECK-NEXT: [[C_3:%.*]] = icmp ugt i32 [[A]], 50 827; CHECK-NEXT: call void @use(i1 [[C_3]]) 828; CHECK-NEXT: ret void 829; CHECK: false: 830; CHECK-NEXT: [[F_4:%.*]] = icmp eq i32 [[A]], 50 831; CHECK-NEXT: call void @use(i1 [[F_4]]) 832; CHECK-NEXT: [[T_3:%.*]] = icmp ne i32 [[A]], 50 833; CHECK-NEXT: call void @use(i1 [[T_3]]) 834; CHECK-NEXT: [[C_4:%.*]] = icmp eq i32 [[A]], 10 835; CHECK-NEXT: call void @use(i1 [[C_4]]) 836; CHECK-NEXT: [[C_5:%.*]] = icmp eq i32 [[B:%.*]], 100 837; CHECK-NEXT: call void @use(i1 [[C_5]]) 838; CHECK-NEXT: ret void 839; 840entry: 841 %lt = icmp ult i32 %a, 100 842 %gt = icmp ugt i32 %a, 20 843 %bc = and i1 %lt, %gt 844 br i1 %bc, label %true, label %false 845 846true: ; %a in [21, 100) 847 ; Conditions below are false. 848 %f.1 = icmp eq i32 %a, 0 849 call void @use(i1 %f.1) 850 %f.2 = icmp eq i32 %a, 20 851 call void @use(i1 %f.2) 852 %f.3 = icmp ugt i32 %a, 100 853 call void @use(i1 %f.3) 854 855 ; Conditions below are true. 856 %t.1 = icmp ult i32 %a, 100 857 call void @use(i1 %t.1) 858 %t.2 = icmp ne i32 %a, 20 859 call void @use(i1 %t.2) 860 861 ; Conditions below cannot be simplified. 862 %c.1 = icmp eq i32 %a, 21 863 call void @use(i1 %c.1) 864 %c.2 = icmp ugt i32 %a, 21 865 call void @use(i1 %c.2) 866 %c.3 = icmp ugt i32 %a, 50 867 call void @use(i1 %c.3) 868 ret void 869 870false: 871; TODO: Currently there is no conditional range info in the false branch for branch conditions with an AND. 872; %a should be in in [100, 21) 873 ; Conditions below are false; 874 %f.4 = icmp eq i32 %a, 50 875 call void @use(i1 %f.4) 876 877 ; Conditions below are true; 878 %t.3 = icmp ne i32 %a, 50 879 call void @use(i1 %t.3) 880 881 ; Conditions below cannot be simplified. 882 %c.4 = icmp eq i32 %a, 10 883 call void @use(i1 %c.4) 884 %c.5 = icmp eq i32 %b, 100 885 call void @use(i1 %c.5) 886 ret void 887} 888 889define void @f17_conditions_or(i32 %a, i32 %b) { 890; CHECK-LABEL: @f17_conditions_or( 891; CHECK-NEXT: entry: 892; CHECK-NEXT: [[GT:%.*]] = icmp uge i32 [[A:%.*]], 100 893; CHECK-NEXT: [[LT:%.*]] = icmp ule i32 [[A]], 20 894; CHECK-NEXT: [[BC:%.*]] = or i1 [[LT]], [[GT]] 895; CHECK-NEXT: br i1 [[BC]], label [[TRUE:%.*]], label [[FALSE:%.*]] 896; CHECK: false: 897; CHECK-NEXT: call void @use(i1 false) 898; CHECK-NEXT: call void @use(i1 false) 899; CHECK-NEXT: call void @use(i1 false) 900; CHECK-NEXT: call void @use(i1 true) 901; CHECK-NEXT: call void @use(i1 true) 902; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[A]], 21 903; CHECK-NEXT: call void @use(i1 [[C_1]]) 904; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i32 [[A]], 21 905; CHECK-NEXT: call void @use(i1 [[C_2]]) 906; CHECK-NEXT: [[C_3:%.*]] = icmp ugt i32 [[A]], 50 907; CHECK-NEXT: call void @use(i1 [[C_3]]) 908; CHECK-NEXT: ret void 909; CHECK: true: 910; CHECK-NEXT: [[F_4:%.*]] = icmp eq i32 [[A]], 50 911; CHECK-NEXT: call void @use(i1 [[F_4]]) 912; CHECK-NEXT: [[T_3:%.*]] = icmp ne i32 [[A]], 50 913; CHECK-NEXT: call void @use(i1 [[T_3]]) 914; CHECK-NEXT: [[C_4:%.*]] = icmp eq i32 [[A]], 10 915; CHECK-NEXT: call void @use(i1 [[C_4]]) 916; CHECK-NEXT: [[C_5:%.*]] = icmp eq i32 [[B:%.*]], 100 917; CHECK-NEXT: call void @use(i1 [[C_5]]) 918; CHECK-NEXT: ret void 919; 920entry: 921 %gt = icmp uge i32 %a, 100 922 %lt = icmp ule i32 %a, 20 923 %bc = or i1 %lt, %gt 924 br i1 %bc, label %true, label %false 925 926false: ; %a in [21, 100) 927 ; Conditions below are false. 928 %f.1 = icmp eq i32 %a, 0 929 call void @use(i1 %f.1) 930 %f.2 = icmp eq i32 %a, 20 931 call void @use(i1 %f.2) 932 %f.3 = icmp ugt i32 %a, 100 933 call void @use(i1 %f.3) 934 935 ; Conditions below are true. 936 %t.1 = icmp ult i32 %a, 100 937 call void @use(i1 %t.1) 938 %t.2 = icmp ne i32 %a, 20 939 call void @use(i1 %t.2) 940 941 ; Conditions below cannot be simplified. 942 %c.1 = icmp eq i32 %a, 21 943 call void @use(i1 %c.1) 944 %c.2 = icmp ugt i32 %a, 21 945 call void @use(i1 %c.2) 946 %c.3 = icmp ugt i32 %a, 50 947 call void @use(i1 %c.3) 948 ret void 949 950true: 951; TODO: Currently there is no conditional range info in the false branch for branch conditions with an AND. 952; %a should be in in [100, 21) 953 ; Conditions below are false; 954 %f.4 = icmp eq i32 %a, 50 955 call void @use(i1 %f.4) 956 957 ; Conditions below are true; 958 %t.3 = icmp ne i32 %a, 50 959 call void @use(i1 %t.3) 960 961 ; Conditions below cannot be simplified. 962 %c.4 = icmp eq i32 %a, 10 963 call void @use(i1 %c.4) 964 %c.5 = icmp eq i32 %b, 100 965 call void @use(i1 %c.5) 966 ret void 967} 968 969; TODO: Currently only the information of the AND used as branch condition is 970; used. 971define void @f18_conditions_chained_and(i32 %a, i32 %b) { 972; CHECK-LABEL: @f18_conditions_chained_and( 973; CHECK-NEXT: entry: 974; CHECK-NEXT: [[LT:%.*]] = icmp ult i32 [[A:%.*]], 100 975; CHECK-NEXT: [[GT:%.*]] = icmp ugt i32 [[A]], 20 976; CHECK-NEXT: [[BC:%.*]] = and i1 [[LT]], [[GT]] 977; CHECK-NEXT: [[B_LT:%.*]] = icmp ult i32 [[B:%.*]], 50 978; CHECK-NEXT: [[BC_2:%.*]] = and i1 [[BC]], [[B_LT]] 979; CHECK-NEXT: br i1 [[BC_2]], label [[TRUE:%.*]], label [[FALSE:%.*]] 980; CHECK: true: 981; CHECK-NEXT: [[F_1:%.*]] = icmp eq i32 [[A]], 0 982; CHECK-NEXT: call void @use(i1 [[F_1]]) 983; CHECK-NEXT: [[F_2:%.*]] = icmp eq i32 [[A]], 20 984; CHECK-NEXT: call void @use(i1 [[F_2]]) 985; CHECK-NEXT: [[F_3:%.*]] = icmp ugt i32 [[A]], 100 986; CHECK-NEXT: call void @use(i1 [[F_3]]) 987; CHECK-NEXT: [[F_4:%.*]] = icmp eq i32 [[B]], 0 988; CHECK-NEXT: call void @use(i1 [[F_3]]) 989; CHECK-NEXT: [[F_5:%.*]] = icmp eq i32 [[B]], 20 990; CHECK-NEXT: call void @use(i1 [[F_5]]) 991; CHECK-NEXT: [[F_6:%.*]] = icmp ugt i32 [[B]], 100 992; CHECK-NEXT: call void @use(i1 [[F_6]]) 993; CHECK-NEXT: [[T_1:%.*]] = icmp ult i32 [[A]], 100 994; CHECK-NEXT: call void @use(i1 [[T_1]]) 995; CHECK-NEXT: [[T_2:%.*]] = icmp ne i32 [[A]], 20 996; CHECK-NEXT: call void @use(i1 [[T_2]]) 997; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[A]], 21 998; CHECK-NEXT: call void @use(i1 [[C_1]]) 999; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i32 [[A]], 21 1000; CHECK-NEXT: call void @use(i1 [[C_2]]) 1001; CHECK-NEXT: [[C_3:%.*]] = icmp ugt i32 [[A]], 50 1002; CHECK-NEXT: call void @use(i1 [[C_3]]) 1003; CHECK-NEXT: ret void 1004; CHECK: false: 1005; CHECK-NEXT: [[F_7:%.*]] = icmp eq i32 [[A]], 50 1006; CHECK-NEXT: call void @use(i1 [[F_7]]) 1007; CHECK-NEXT: [[T_3:%.*]] = icmp ne i32 [[A]], 50 1008; CHECK-NEXT: call void @use(i1 [[T_3]]) 1009; CHECK-NEXT: [[C_4:%.*]] = icmp eq i32 [[A]], 10 1010; CHECK-NEXT: call void @use(i1 [[C_4]]) 1011; CHECK-NEXT: [[C_5:%.*]] = icmp eq i32 [[B]], 100 1012; CHECK-NEXT: call void @use(i1 [[C_5]]) 1013; CHECK-NEXT: ret void 1014; 1015entry: 1016 %lt = icmp ult i32 %a, 100 1017 %gt = icmp ugt i32 %a, 20 1018 %bc = and i1 %lt, %gt 1019 %b.lt = icmp ult i32 %b, 50 1020 %bc.2 = and i1 %bc, %b.lt 1021 br i1 %bc.2, label %true, label %false 1022 1023true: ; %a in [21, 100) 1024 ; Conditions below are false. 1025 %f.1 = icmp eq i32 %a, 0 1026 call void @use(i1 %f.1) 1027 %f.2 = icmp eq i32 %a, 20 1028 call void @use(i1 %f.2) 1029 %f.3 = icmp ugt i32 %a, 100 1030 call void @use(i1 %f.3) 1031 %f.4 = icmp eq i32 %b, 0 1032 call void @use(i1 %f.3) 1033 %f.5 = icmp eq i32 %b, 20 1034 call void @use(i1 %f.5) 1035 %f.6 = icmp ugt i32 %b, 100 1036 call void @use(i1 %f.6) 1037 1038 1039 ; Conditions below are true. 1040 %t.1 = icmp ult i32 %a, 100 1041 call void @use(i1 %t.1) 1042 %t.2 = icmp ne i32 %a, 20 1043 call void @use(i1 %t.2) 1044 1045 ; Conditions below cannot be simplified. 1046 %c.1 = icmp eq i32 %a, 21 1047 call void @use(i1 %c.1) 1048 %c.2 = icmp ugt i32 %a, 21 1049 call void @use(i1 %c.2) 1050 %c.3 = icmp ugt i32 %a, 50 1051 call void @use(i1 %c.3) 1052 ret void 1053 1054false: 1055 ; Conditions below are false; 1056 %f.7 = icmp eq i32 %a, 50 1057 call void @use(i1 %f.7) 1058 1059 ; Conditions below are true; 1060 %t.3 = icmp ne i32 %a, 50 1061 call void @use(i1 %t.3) 1062 1063 ; Conditions below cannot be simplified. 1064 %c.4 = icmp eq i32 %a, 10 1065 call void @use(i1 %c.4) 1066 %c.5 = icmp eq i32 %b, 100 1067 call void @use(i1 %c.5) 1068 ret void 1069} 1070 1071define void @f19_conditions_chained_and_nested_and(i32 %a, i32 %b) { 1072; CHECK-LABEL: @f19_conditions_chained_and_nested_and( 1073; CHECK-NEXT: entry: 1074; CHECK-NEXT: [[LT_A:%.*]] = icmp ult i32 [[A:%.*]], 100 1075; CHECK-NEXT: [[LT_B:%.*]] = icmp ult i32 [[B:%.*]], 1000 1076; CHECK-NEXT: [[BC:%.*]] = and i1 [[LT_A]], [[LT_B]] 1077; CHECK-NEXT: br i1 [[BC]], label [[TRUE:%.*]], label [[FALSE:%.*]] 1078; CHECK: true: 1079; CHECK-NEXT: [[GT_A:%.*]] = icmp ugt i32 [[A]], 30 1080; CHECK-NEXT: [[GT_B:%.*]] = icmp ugt i32 [[B]], 300 1081; CHECK-NEXT: [[BC_2:%.*]] = and i1 [[GT_A]], [[GT_B]] 1082; CHECK-NEXT: br i1 [[BC_2]], label [[TRUE_2:%.*]], label [[FALSE]] 1083; CHECK: true.2: 1084; CHECK-NEXT: call void @use(i1 false) 1085; CHECK-NEXT: call void @use(i1 false) 1086; CHECK-NEXT: call void @use(i1 false) 1087; CHECK-NEXT: call void @use(i1 false) 1088; CHECK-NEXT: call void @use(i1 false) 1089; CHECK-NEXT: call void @use(i1 false) 1090; CHECK-NEXT: call void @use(i1 true) 1091; CHECK-NEXT: call void @use(i1 true) 1092; CHECK-NEXT: call void @use(i1 true) 1093; CHECK-NEXT: call void @use(i1 true) 1094; CHECK-NEXT: [[C_1:%.*]] = icmp eq i32 [[A]], 31 1095; CHECK-NEXT: call void @use(i1 [[C_1]]) 1096; CHECK-NEXT: [[C_2:%.*]] = icmp ugt i32 [[A]], 31 1097; CHECK-NEXT: call void @use(i1 [[C_2]]) 1098; CHECK-NEXT: [[C_3:%.*]] = icmp ugt i32 [[A]], 50 1099; CHECK-NEXT: call void @use(i1 [[C_3]]) 1100; CHECK-NEXT: [[C_4:%.*]] = icmp eq i32 [[B]], 301 1101; CHECK-NEXT: call void @use(i1 [[C_4]]) 1102; CHECK-NEXT: [[C_5:%.*]] = icmp ugt i32 [[B]], 301 1103; CHECK-NEXT: call void @use(i1 [[C_5]]) 1104; CHECK-NEXT: [[C_6:%.*]] = icmp ugt i32 [[B]], 500 1105; CHECK-NEXT: call void @use(i1 [[C_6]]) 1106; CHECK-NEXT: ret void 1107; CHECK: false: 1108; CHECK-NEXT: ret void 1109; 1110entry: 1111 %lt.a = icmp ult i32 %a, 100 1112 %lt.b = icmp ult i32 %b, 1000 1113 %bc = and i1 %lt.a, %lt.b 1114 br i1 %bc, label %true, label %false 1115 1116true: 1117 %gt.a = icmp ugt i32 %a, 30 1118 %gt.b = icmp ugt i32 %b, 300 1119 %bc.2 = and i1 %gt.a, %gt.b 1120 br i1 %bc.2, label %true.2, label %false 1121 1122true.2: 1123 ; Conditions below are false. 1124 %f.1 = icmp eq i32 %a, 0 1125 call void @use(i1 %f.1) 1126 %f.2 = icmp eq i32 %a, 20 1127 call void @use(i1 %f.2) 1128 %f.3 = icmp ugt i32 %a, 100 1129 call void @use(i1 %f.3) 1130 %f.4 = icmp eq i32 %b, 0 1131 call void @use(i1 %f.4) 1132 %f.5 = icmp eq i32 %b, 300 1133 call void @use(i1 %f.5) 1134 %f.6 = icmp ugt i32 %b, 1000 1135 call void @use(i1 %f.6) 1136 1137 1138 ; Conditions below are true. 1139 %t.1 = icmp ult i32 %a, 100 1140 call void @use(i1 %t.1) 1141 %t.2 = icmp ne i32 %a, 20 1142 call void @use(i1 %t.2) 1143 %t.3 = icmp ult i32 %b, 1000 1144 call void @use(i1 %t.3) 1145 %t.4 = icmp ne i32 %b, 300 1146 call void @use(i1 %t.4) 1147 1148 1149 ; Conditions below cannot be simplified. 1150 %c.1 = icmp eq i32 %a, 31 1151 call void @use(i1 %c.1) 1152 %c.2 = icmp ugt i32 %a, 31 1153 call void @use(i1 %c.2) 1154 %c.3 = icmp ugt i32 %a, 50 1155 call void @use(i1 %c.3) 1156 %c.4 = icmp eq i32 %b, 301 1157 call void @use(i1 %c.4) 1158 %c.5 = icmp ugt i32 %b, 301 1159 call void @use(i1 %c.5) 1160 %c.6 = icmp ugt i32 %b, 500 1161 call void @use(i1 %c.6) 1162 1163 ret void 1164 1165false: 1166 ret void 1167} 1168 1169declare i64 @get_i64() 1170 1171declare i1 @cond() 1172 1173define void @f20_ne_0_nuked_by_and(i32 %arg) local_unnamed_addr #0 { 1174; CHECK-LABEL: @f20_ne_0_nuked_by_and( 1175; CHECK-NEXT: bb11: 1176; CHECK-NEXT: br label [[BB122:%.*]] 1177; CHECK: bb122: 1178; CHECK-NEXT: [[TMP123:%.*]] = phi i32 [ 256, [[BB11:%.*]] ], [ [[TMP136:%.*]], [[BB135:%.*]] ] 1179; CHECK-NEXT: [[TMP127:%.*]] = call i64 @get_i64() 1180; CHECK-NEXT: [[TMP128:%.*]] = trunc i64 [[TMP127]] to i32 1181; CHECK-NEXT: [[TMP131:%.*]] = icmp ne i32 [[TMP128]], 0 1182; CHECK-NEXT: [[TMP132:%.*]] = icmp sgt i32 [[TMP123]], [[TMP128]] 1183; CHECK-NEXT: [[TMP133:%.*]] = and i1 [[TMP131]], [[TMP132]] 1184; CHECK-NEXT: br i1 [[TMP133]], label [[BB134:%.*]], label [[BB135]] 1185; CHECK: bb134: 1186; CHECK-NEXT: br label [[BB135]] 1187; CHECK: bb135: 1188; CHECK-NEXT: [[TMP136]] = phi i32 [ [[TMP123]], [[BB122]] ], [ [[TMP128]], [[BB134]] ] 1189; CHECK-NEXT: [[BC:%.*]] = call i1 @cond() 1190; CHECK-NEXT: br i1 [[BC]], label [[BB139:%.*]], label [[BB122]] 1191; CHECK: bb139: 1192; CHECK-NEXT: call void @use(i1 false) 1193; CHECK-NEXT: ret void 1194; 1195bb11: ; preds = %bb1 1196 br label %bb122 1197 1198bb122: ; preds = %bb135, %bb120 1199 %tmp123 = phi i32 [ 256, %bb11 ], [ %tmp136, %bb135 ] 1200 %tmp127 = call i64 @get_i64() 1201 %tmp128 = trunc i64 %tmp127 to i32 1202 %tmp131 = icmp ne i32 %tmp128, 0 1203 %tmp132 = icmp sgt i32 %tmp123, %tmp128 1204 %tmp133 = and i1 %tmp131, %tmp132 1205 br i1 %tmp133, label %bb134, label %bb135 1206 1207bb134: ; preds = %bb122 1208 br label %bb135 1209 1210bb135: ; preds = %bb134, %bb122 1211 %tmp136 = phi i32 [ %tmp123, %bb122 ], [ %tmp128, %bb134 ] 1212 %bc = call i1 @cond() 1213 br i1 %bc, label %bb139, label %bb122 1214 1215bb139: ; preds = %bb135 1216 %tmp140 = icmp eq i32 %tmp136, 0 1217 call void @use(i1 %tmp140) 1218 ret void 1219 1220bb142: ; preds = %bb139 1221 ret void 1222} 1223