| 710 | } |
| 711 | |
| 712 | Status AlgebraicSimplifierVisitor::HandleAnd(HloInstruction* logical_and) { |
| 713 | HloInstruction *lhs, *rhs; |
| 714 | CHECK(Match(logical_and, m::And(m::Op(&lhs), m::Op(&rhs)))); |
| 715 | // Simplify logical and |
| 716 | if (ShapeUtil::HasPrimitiveType(lhs->shape(), xla::PRED) && |
| 717 | ShapeUtil::HasPrimitiveType(rhs->shape(), xla::PRED)) { |
| 718 | // A && True => A |
| 719 | VLOG(10) << "trying transform [A && True => A]: " |
| 720 | << logical_and->ToString(); |
| 721 | if (IsAll(rhs, 1) && ReplaceInstructionIfSameShape(logical_and, lhs)) { |
| 722 | return Status::OK(); |
| 723 | } |
| 724 | // True && A => A |
| 725 | VLOG(10) << "trying transform [True && A => A]: " |
| 726 | << logical_and->ToString(); |
| 727 | if (IsAll(lhs, 1) && ReplaceInstructionIfSameShape(logical_and, rhs)) { |
| 728 | return Status::OK(); |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | // A && False => False or A & 0 => 0 |
| 733 | VLOG(10) << "trying transform [A && False => False]: " |
| 734 | << logical_and->ToString(); |
| 735 | if (IsAll(rhs, 0) && ReplaceInstructionIfSameShape(logical_and, rhs)) { |
| 736 | return Status::OK(); |
| 737 | } |
| 738 | |
| 739 | // False && A => False or A & 0 => 0 |
| 740 | VLOG(10) << "trying transform [False && A => False]: " |
| 741 | << logical_and->ToString(); |
| 742 | if (IsAll(lhs, 0) && ReplaceInstructionIfSameShape(logical_and, lhs)) { |
| 743 | return Status::OK(); |
| 744 | } |
| 745 | |
| 746 | return Status::OK(); |
| 747 | } |
| 748 | |
| 749 | Status AlgebraicSimplifierVisitor::HandleBitcast(HloInstruction* bitcast) { |
| 750 | // If a bitcast feeds a bitcast, make it a single bitcast. |