| 2132 | } // namespace |
| 2133 | |
| 2134 | Status AlgebraicSimplifierVisitor::HandleMaximum(HloInstruction* maximum) { |
| 2135 | HloInstruction *lhs, *rhs; |
| 2136 | CHECK(Match(maximum, m::Maximum(m::Op(&lhs), m::Op(&rhs)))); |
| 2137 | |
| 2138 | HloInstruction* clamp_upper_bound_bcast; |
| 2139 | HloInstruction* clamp_lower_bound_bcast; |
| 2140 | HloInstruction* to_clamp; |
| 2141 | if (Match(maximum, m::MaximumAnyOrder( |
| 2142 | m::Broadcast(&clamp_lower_bound_bcast, |
| 2143 | m::ConstantEffectiveScalar()), |
| 2144 | m::MinimumAnyOrder( |
| 2145 | m::Op(&to_clamp), |
| 2146 | m::Broadcast(&clamp_upper_bound_bcast, |
| 2147 | m::ConstantEffectiveScalar()))))) { |
| 2148 | TF_ASSIGN_OR_RETURN(auto clamp, |
| 2149 | MinMaxToClamp(clamp_lower_bound_bcast, to_clamp, |
| 2150 | clamp_upper_bound_bcast)); |
| 2151 | if (clamp) { |
| 2152 | return ReplaceWithNewInstruction(maximum, std::move(clamp)); |
| 2153 | } |
| 2154 | } |
| 2155 | |
| 2156 | HloInstruction* clamp_lower_bound; |
| 2157 | HloInstruction* clamp_upper_bound; |
| 2158 | HloInstruction* max_operand; |
| 2159 | HloInstruction* clamp; |
| 2160 | if (Match(maximum, |
| 2161 | m::MaximumAnyOrder( |
| 2162 | m::Op(&max_operand), |
| 2163 | m::Clamp(&clamp, m::Op(&clamp_lower_bound), m::Op(&to_clamp), |
| 2164 | m::Op(&clamp_upper_bound))))) { |
| 2165 | if (max_operand == clamp_lower_bound && |
| 2166 | ReplaceInstructionIfSameShape(maximum, clamp)) { |
| 2167 | return Status::OK(); |
| 2168 | } |
| 2169 | } |
| 2170 | |
| 2171 | return Status::OK(); |
| 2172 | } |
| 2173 | |
| 2174 | Status AlgebraicSimplifierVisitor::HandleMinimum(HloInstruction* minimum) { |
| 2175 | HloInstruction *lhs, *rhs; |