[Mlir-commits] [mlir] [mlir][complex] Convert complex.tan to libm ctan call (PR #78250)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Jan 16 02:25:42 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Kai Sasaki (Lewuathe)

<details>
<summary>Changes</summary>

We can convert `complex.tan` op to [ctan/ctanf](https://sourceware.org/newlib/libm.html#ctan) function in libm in the complex to libm conversion. 

---
Full diff: https://github.com/llvm/llvm-project/pull/78250.diff


2 Files Affected:

- (modified) mlir/lib/Conversion/ComplexToLibm/ComplexToLibm.cpp (+4-1) 
- (modified) mlir/test/Conversion/ComplexToLibm/convert-to-libm.mlir (+14) 


``````````diff
diff --git a/mlir/lib/Conversion/ComplexToLibm/ComplexToLibm.cpp b/mlir/lib/Conversion/ComplexToLibm/ComplexToLibm.cpp
index b3762f0293492c..f2b50d109f8f62 100644
--- a/mlir/lib/Conversion/ComplexToLibm/ComplexToLibm.cpp
+++ b/mlir/lib/Conversion/ComplexToLibm/ComplexToLibm.cpp
@@ -117,6 +117,8 @@ void mlir::populateComplexToLibmConversionPatterns(RewritePatternSet &patterns,
       patterns.getContext(), "cabsf", "cabs", benefit);
   patterns.add<ScalarOpToLibmCall<complex::AngleOp, FloatTypeResolver>>(
       patterns.getContext(), "cargf", "carg", benefit);
+  patterns.add<ScalarOpToLibmCall<complex::TanOp>>(patterns.getContext(),
+                                                   "ctanf", "ctan", benefit);
 }
 
 namespace {
@@ -136,7 +138,8 @@ void ConvertComplexToLibmPass::runOnOperation() {
   target.addLegalDialect<func::FuncDialect>();
   target.addIllegalOp<complex::PowOp, complex::SqrtOp, complex::TanhOp,
                       complex::CosOp, complex::SinOp, complex::ConjOp,
-                      complex::LogOp, complex::AbsOp, complex::AngleOp>();
+                      complex::LogOp, complex::AbsOp, complex::AngleOp,
+                      complex::TanOp>();
   if (failed(applyPartialConversion(module, target, std::move(patterns))))
     signalPassFailure();
 }
diff --git a/mlir/test/Conversion/ComplexToLibm/convert-to-libm.mlir b/mlir/test/Conversion/ComplexToLibm/convert-to-libm.mlir
index 0a19751324d8b2..ecf243c53a80cc 100644
--- a/mlir/test/Conversion/ComplexToLibm/convert-to-libm.mlir
+++ b/mlir/test/Conversion/ComplexToLibm/convert-to-libm.mlir
@@ -12,6 +12,8 @@
 // CHECK-DAG: @cabs(complex<f64>) -> f64
 // CHECK-DAG: @carg(complex<f64>) -> f64
 // CHECK-DAG: @clog(complex<f64>) -> complex<f64>
+// CHECK-DAG: @ctanf(complex<f32>) -> complex<f32>
+// CHECK-DAG: @ctan(complex<f64>) -> complex<f64>
 
 // CHECK-LABEL: func @cpow_caller
 // CHECK-SAME: %[[FLOAT:.*]]: complex<f32>
@@ -120,3 +122,15 @@ func.func @clog_caller(%float: complex<f32>, %double: complex<f64>) -> (complex<
   // CHECK: return %[[FLOAT_RESULT]], %[[DOUBLE_RESULT]]
   return %float_result, %double_result : complex<f32>, complex<f64>
 }
+
+// CHECK-LABEL: func @ctan_caller
+// CHECK-SAME: %[[FLOAT:.*]]: complex<f32>
+// CHECK-SAME: %[[DOUBLE:.*]]: complex<f64>
+func.func @ctan_caller(%float: complex<f32>, %double: complex<f64>) -> (complex<f32>, complex<f64>)  {
+  // CHECK: %[[FLOAT_RESULT:.*]] = call @ctanf(%[[FLOAT]])
+  %float_result = complex.tan %float : complex<f32>
+  // CHECK: %[[DOUBLE_RESULT:.*]] = call @ctan(%[[DOUBLE]])
+  %double_result = complex.tan %double : complex<f64>
+  // CHECK: return %[[FLOAT_RESULT]], %[[DOUBLE_RESULT]]
+  return %float_result, %double_result : complex<f32>, complex<f64>
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/78250


More information about the Mlir-commits mailing list