llvm.org GIT mirror llvm / 7c6fd7e
[EarlyCSE] add more tests for double-negated select condition; NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358454 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 5 months ago
1 changed file(s) with 88 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
460460 ; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[INVCOND]], true
461461 ; CHECK-NEXT: [[M1:%.*]] = select i1 [[COND]], i32 [[T:%.*]], i32 [[F:%.*]]
462462 ; CHECK-NEXT: [[M2:%.*]] = select i1 [[NOT]], i32 [[T]], i32 [[F]]
463 ; CHECK-NEXT: [[R:%.*]] = xor i32 [[M1]], [[M2]]
463 ; CHECK-NEXT: [[R:%.*]] = sub i32 [[M1]], [[M2]]
464464 ; CHECK-NEXT: ret i32 [[R]]
465465 ;
466466 %cond = icmp ugt i8 %x, 42
468468 %not = xor i1 %invcond, -1
469469 %m1 = select i1 %cond, i32 %t, i32 %f
470470 %m2 = select i1 %not, i32 %t, i32 %f
471 %r = xor i32 %m1, %m2
472 ret i32 %r
473 }
471 %r = sub i32 %m1, %m2
472 ret i32 %r
473 }
474
475 ; TODO: If we have both an inverted predicate and a 'not' op, recognize the double-negation.
476
477 define i32 @select_not_invert_pred_cond_commute(i8 %x, i8 %y, i32 %t, i32 %f) {
478 ; CHECK-LABEL: @select_not_invert_pred_cond_commute(
479 ; CHECK-NEXT: [[INVCOND:%.*]] = icmp ule i8 [[X:%.*]], [[Y:%.*]]
480 ; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[INVCOND]], true
481 ; CHECK-NEXT: [[M2:%.*]] = select i1 [[NOT]], i32 [[T:%.*]], i32 [[F:%.*]]
482 ; CHECK-NEXT: [[COND:%.*]] = icmp ugt i8 [[X]], [[Y]]
483 ; CHECK-NEXT: [[M1:%.*]] = select i1 [[COND]], i32 [[T]], i32 [[F]]
484 ; CHECK-NEXT: [[R:%.*]] = sub i32 [[M2]], [[M1]]
485 ; CHECK-NEXT: ret i32 [[R]]
486 ;
487 %invcond = icmp ule i8 %x, %y
488 %not = xor i1 %invcond, -1
489 %m2 = select i1 %not, i32 %t, i32 %f
490 %cond = icmp ugt i8 %x, %y
491 %m1 = select i1 %cond, i32 %t, i32 %f
492 %r = sub i32 %m2, %m1
493 ret i32 %r
494 }
495
496 ; Negative test - not an inverted predicate.
497
498 define i32 @select_not_invert_pred_cond_wrong_pred(i8 %x, i8 %y, i32 %t, i32 %f) {
499 ; CHECK-LABEL: @select_not_invert_pred_cond_wrong_pred(
500 ; CHECK-NEXT: [[INVCOND:%.*]] = icmp ult i8 [[X:%.*]], [[Y:%.*]]
501 ; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[INVCOND]], true
502 ; CHECK-NEXT: [[M2:%.*]] = select i1 [[NOT]], i32 [[T:%.*]], i32 [[F:%.*]]
503 ; CHECK-NEXT: [[COND:%.*]] = icmp ugt i8 [[X]], [[Y]]
504 ; CHECK-NEXT: [[M1:%.*]] = select i1 [[COND]], i32 [[T]], i32 [[F]]
505 ; CHECK-NEXT: [[R:%.*]] = sub i32 [[M2]], [[M1]]
506 ; CHECK-NEXT: ret i32 [[R]]
507 ;
508 %invcond = icmp ult i8 %x, %y
509 %not = xor i1 %invcond, -1
510 %m2 = select i1 %not, i32 %t, i32 %f
511 %cond = icmp ugt i8 %x, %y
512 %m1 = select i1 %cond, i32 %t, i32 %f
513 %r = sub i32 %m2, %m1
514 ret i32 %r
515 }
516
517 ; Negative test - cmp ops must match.
518
519 define i32 @select_not_invert_pred_cond_wrong_cmp_op(i8 %x, i8 %y, i32 %t, i32 %f) {
520 ; CHECK-LABEL: @select_not_invert_pred_cond_wrong_cmp_op(
521 ; CHECK-NEXT: [[INVCOND:%.*]] = icmp ule i8 [[X:%.*]], 42
522 ; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[INVCOND]], true
523 ; CHECK-NEXT: [[M2:%.*]] = select i1 [[NOT]], i32 [[T:%.*]], i32 [[F:%.*]]
524 ; CHECK-NEXT: [[COND:%.*]] = icmp ugt i8 [[X]], [[Y:%.*]]
525 ; CHECK-NEXT: [[M1:%.*]] = select i1 [[COND]], i32 [[T]], i32 [[F]]
526 ; CHECK-NEXT: [[R:%.*]] = sub i32 [[M2]], [[M1]]
527 ; CHECK-NEXT: ret i32 [[R]]
528 ;
529 %invcond = icmp ule i8 %x, 42
530 %not = xor i1 %invcond, -1
531 %m2 = select i1 %not, i32 %t, i32 %f
532 %cond = icmp ugt i8 %x, %y
533 %m1 = select i1 %cond, i32 %t, i32 %f
534 %r = sub i32 %m2, %m1
535 ret i32 %r
536 }
537
538 ; Negative test - select ops must be same (and not commuted).
539
540 define i32 @select_not_invert_pred_cond_wrong_select_op(i8 %x, i8 %y, i32 %t, i32 %f) {
541 ; CHECK-LABEL: @select_not_invert_pred_cond_wrong_select_op(
542 ; CHECK-NEXT: [[INVCOND:%.*]] = icmp ule i8 [[X:%.*]], [[Y:%.*]]
543 ; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[INVCOND]], true
544 ; CHECK-NEXT: [[M2:%.*]] = select i1 [[NOT]], i32 [[T:%.*]], i32 [[F:%.*]]
545 ; CHECK-NEXT: [[COND:%.*]] = icmp ugt i8 [[X]], [[Y]]
546 ; CHECK-NEXT: [[M1:%.*]] = select i1 [[COND]], i32 [[F]], i32 [[T]]
547 ; CHECK-NEXT: [[R:%.*]] = sub i32 [[M2]], [[M1]]
548 ; CHECK-NEXT: ret i32 [[R]]
549 ;
550 %invcond = icmp ule i8 %x, %y
551 %not = xor i1 %invcond, -1
552 %m2 = select i1 %not, i32 %t, i32 %f
553 %cond = icmp ugt i8 %x, %y
554 %m1 = select i1 %cond, i32 %f, i32 %t
555 %r = sub i32 %m2, %m1
556 ret i32 %r
557 }