diff --git a/lib/Dialect/mhlo/transforms/chlo_legalize_to_hlo_patterns.td b/lib/Dialect/mhlo/transforms/chlo_legalize_to_hlo_patterns.td index 92a02ea..a4f425e 100644 --- a/lib/Dialect/mhlo/transforms/chlo_legalize_to_hlo_patterns.td +++ b/lib/Dialect/mhlo/transforms/chlo_legalize_to_hlo_patterns.td @@ -23,10 +23,18 @@ include "mlir-hlo/Dialect/mhlo/IR/chlo_ops.td" // Unary op patterns. //===----------------------------------------------------------------------===// +def NonComplexElementType : Type< + CPred<"!$_self.cast().getElementType().isa()">, + "Non complex element type">; + // Expand acos to MHLO dialect as follows: // acos(x) = 2 * atan2(sqrt(1 - x^2), (1 + x)) if x != -1 // = pi if x == -1 -def : Pat<(HLOClient_AcosOp $input), +// +// TODO(hinsu): Support operands with complex element types separately using +// the following formula. +// acos(x) = -(i * log(x + i * sqrt((1 + x) * (1 - x)))) +def : Pat<(HLOClient_AcosOp NonComplexElementType:$input), (HLO_SelectOp (HLO_CompareOp $input, @@ -68,7 +76,9 @@ def : Pat<(HLOClient_ConjOp $v), // Express `sinh` as // sinh(x) = (e^x - e^-x) / 2 if |x| < 1 // = e^(x + log(1/2)) - e^(-x + log(1/2)) otherwise. -def : Pat<(HLOClient_SinhOp $input), +// TODO(hinsu): Support operands with complex element types by always using the +// second formula. The compare op below is not legal for complex numbers. +def : Pat<(HLOClient_SinhOp NonComplexElementType:$input), (HLO_SelectOp (HLO_CompareOp (HLO_AbsOp $input),