| 2308 | } |
| 2309 | |
| 2310 | Status AlgebraicSimplifierVisitor::HandleOr(HloInstruction* logical_or) { |
| 2311 | HloInstruction *lhs, *rhs; |
| 2312 | CHECK(Match(logical_or, m::Or(m::Op(&lhs), m::Op(&rhs)))); |
| 2313 | |
| 2314 | // Simplify logical or |
| 2315 | if (ShapeUtil::HasPrimitiveType(lhs->shape(), xla::PRED) && |
| 2316 | ShapeUtil::HasPrimitiveType(rhs->shape(), xla::PRED)) { |
| 2317 | // A || True => True |
| 2318 | VLOG(10) << "trying transform [A || True => True]: " |
| 2319 | << logical_or->ToString(); |
| 2320 | if (IsAll(rhs, 1) && ReplaceInstructionIfSameShape(logical_or, rhs)) { |
| 2321 | return Status::OK(); |
| 2322 | } |
| 2323 | // True || A => True |
| 2324 | VLOG(10) << "trying transform [True || A => True]: " |
| 2325 | << logical_or->ToString(); |
| 2326 | if (IsAll(lhs, 1) && ReplaceInstructionIfSameShape(logical_or, lhs)) { |
| 2327 | return Status::OK(); |
| 2328 | } |
| 2329 | } |
| 2330 | |
| 2331 | // A || False => A and A | 0 => A |
| 2332 | VLOG(10) << "trying transform [A || False => A]: " << logical_or->ToString(); |
| 2333 | if (IsAll(rhs, 0) && ReplaceInstructionIfSameShape(logical_or, lhs)) { |
| 2334 | return Status::OK(); |
| 2335 | } |
| 2336 | |
| 2337 | // False || A => A and 0 | A => A |
| 2338 | VLOG(10) << "trying transform [False || A => A]: " << logical_or->ToString(); |
| 2339 | if (IsAll(lhs, 0) && ReplaceInstructionIfSameShape(logical_or, rhs)) { |
| 2340 | return Status::OK(); |
| 2341 | } |
| 2342 | |
| 2343 | return Status::OK(); |
| 2344 | } |
| 2345 | |
| 2346 | Status AlgebraicSimplifierVisitor::HandleLog(HloInstruction* log) { |
| 2347 | // ln(exp(A)) => A |