[Mlir-commits] [mlir] 7769505 - [mlir][complex] Lower complex.log to libm log call

Alexander Belyaev llvmlistbot at llvm.org
Mon Jul 11 12:56:14 PDT 2022


Author: Kai Sasaki
Date: 2022-07-11T21:56:00+02:00
New Revision: 7769505ae98e7766b8a935fbb2808ef5a8ba20ef

URL: https://github.com/llvm/llvm-project/commit/7769505ae98e7766b8a935fbb2808ef5a8ba20ef
DIFF: https://github.com/llvm/llvm-project/commit/7769505ae98e7766b8a935fbb2808ef5a8ba20ef.diff

LOG: [mlir][complex] Lower complex.log to libm log call

Lower complex.log to corresponding function call with libm.

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D129417

Added: 
    

Modified: 
    mlir/lib/Conversion/ComplexToLibm/ComplexToLibm.cpp
    mlir/test/Conversion/ComplexToLibm/convert-to-libm.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/ComplexToLibm/ComplexToLibm.cpp b/mlir/lib/Conversion/ComplexToLibm/ComplexToLibm.cpp
index 716b7a8f50a6f..bfb930bf9b6fe 100644
--- a/mlir/lib/Conversion/ComplexToLibm/ComplexToLibm.cpp
+++ b/mlir/lib/Conversion/ComplexToLibm/ComplexToLibm.cpp
@@ -107,6 +107,8 @@ void mlir::populateComplexToLibmConversionPatterns(RewritePatternSet &patterns,
                                                    "csinf", "csin", benefit);
   patterns.add<ScalarOpToLibmCall<complex::ConjOp>>(patterns.getContext(),
                                                     "conjf", "conj", benefit);
+  patterns.add<ScalarOpToLibmCall<complex::LogOp>>(patterns.getContext(),
+                                                   "clogf", "clog", benefit);
   patterns.add<ScalarOpToLibmCall<complex::AbsOp, FloatTypeResolver>>(
       patterns.getContext(), "cabsf", "cabs", benefit);
   patterns.add<ScalarOpToLibmCall<complex::AngleOp, FloatTypeResolver>>(

diff  --git a/mlir/test/Conversion/ComplexToLibm/convert-to-libm.mlir b/mlir/test/Conversion/ComplexToLibm/convert-to-libm.mlir
index 0b574b2b13fcf..0a19751324d8b 100644
--- a/mlir/test/Conversion/ComplexToLibm/convert-to-libm.mlir
+++ b/mlir/test/Conversion/ComplexToLibm/convert-to-libm.mlir
@@ -10,6 +10,8 @@
 // CHECK-DAG: @csin(complex<f64>) -> complex<f64>
 // CHECK-DAG: @conj(complex<f64>) -> complex<f64>
 // CHECK-DAG: @cabs(complex<f64>) -> f64
+// CHECK-DAG: @carg(complex<f64>) -> f64
+// CHECK-DAG: @clog(complex<f64>) -> complex<f64>
 
 // CHECK-LABEL: func @cpow_caller
 // CHECK-SAME: %[[FLOAT:.*]]: complex<f32>
@@ -105,4 +107,16 @@ func.func @carg_caller(%float: complex<f32>, %double: complex<f64>) -> (f32, f64
   %double_result = complex.angle %double : complex<f64>
   // CHECK: return %[[FLOAT_RESULT]], %[[DOUBLE_RESULT]]
   return %float_result, %double_result : f32, f64
-}
\ No newline at end of file
+}
+
+// CHECK-LABEL: func @clog_caller
+// CHECK-SAME: %[[FLOAT:.*]]: complex<f32>
+// CHECK-SAME: %[[DOUBLE:.*]]: complex<f64>
+func.func @clog_caller(%float: complex<f32>, %double: complex<f64>) -> (complex<f32>, complex<f64>)  {
+  // CHECK: %[[FLOAT_RESULT:.*]] = call @clogf(%[[FLOAT]])
+  %float_result = complex.log %float : complex<f32>
+  // CHECK: %[[DOUBLE_RESULT:.*]] = call @clog(%[[DOUBLE]])
+  %double_result = complex.log %double : complex<f64>
+  // CHECK: return %[[FLOAT_RESULT]], %[[DOUBLE_RESULT]]
+  return %float_result, %double_result : complex<f32>, complex<f64>
+}


        


More information about the Mlir-commits mailing list