From 9466cffaf3b473fef5377e663aa992fa9957fb74 Mon Sep 17 00:00:00 2001 From: Smit Hinsu Date: Fri, 18 Dec 2020 11:31:03 -0800 Subject: [PATCH] Restrict CHLO Acos and Sinh op lowering to non complex types These are failing for complex types. Complex types require special handling. We have a fallback lowering for these ops so we can disable complex element types for now. PiperOrigin-RevId: 348205002 --- .../transforms/chlo_legalize_to_hlo_patterns.td | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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),