[Mlir-commits] [mlir] 9f0869a - [mlir][complex] Lower complex.sin/cos to libm
Alexander Belyaev
llvmlistbot at llvm.org
Thu Jun 2 01:48:41 PDT 2022
Author: lewuathe
Date: 2022-06-02T10:39:00+02:00
New Revision: 9f0869a61dc8d8227956b56cdb0c5c877bb8718a
URL: https://github.com/llvm/llvm-project/commit/9f0869a61dc8d8227956b56cdb0c5c877bb8718a
DIFF: https://github.com/llvm/llvm-project/commit/9f0869a61dc8d8227956b56cdb0c5c877bb8718a.diff
LOG: [mlir][complex] Lower complex.sin/cos to libm
Lower sin/cos operation in complex dialect to libm as a baseline. This follows up to https://reviews.llvm.org/D125550.
Reviewed By: pifon2a
Differential Revision: https://reviews.llvm.org/D126755
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 456c74d0c311c..739603a245551 100644
--- a/mlir/lib/Conversion/ComplexToLibm/ComplexToLibm.cpp
+++ b/mlir/lib/Conversion/ComplexToLibm/ComplexToLibm.cpp
@@ -73,6 +73,10 @@ void mlir::populateComplexToLibmConversionPatterns(RewritePatternSet &patterns,
"csqrtf", "csqrt", benefit);
patterns.add<ScalarOpToLibmCall<complex::TanhOp>>(patterns.getContext(),
"ctanhf", "ctanh", benefit);
+ patterns.add<ScalarOpToLibmCall<complex::CosOp>>(patterns.getContext(),
+ "ccosf", "ccos", benefit);
+ patterns.add<ScalarOpToLibmCall<complex::SinOp>>(patterns.getContext(),
+ "csinf", "csin", benefit);
}
namespace {
diff --git a/mlir/test/Conversion/ComplexToLibm/convert-to-libm.mlir b/mlir/test/Conversion/ComplexToLibm/convert-to-libm.mlir
index ca21f502bd8ee..48655bb1ce8e7 100644
--- a/mlir/test/Conversion/ComplexToLibm/convert-to-libm.mlir
+++ b/mlir/test/Conversion/ComplexToLibm/convert-to-libm.mlir
@@ -6,6 +6,8 @@
// CHECK-DAG: @csqrt(complex<f64>) -> complex<f64>
// CHECK-DAG: @ctanhf(complex<f32>) -> complex<f32>
// CHECK-DAG: @ctanh(complex<f64>) -> complex<f64>
+// CHECK-DAG: @ccos(complex<f64>) -> complex<f64>
+// CHECK-DAG: @csin(complex<f64>) -> complex<f64>
// CHECK-LABEL: func @cpow_caller
// CHECK-SAME: %[[FLOAT:.*]]: complex<f32>
@@ -42,3 +44,27 @@ func.func @ctanh_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 @ccos_caller
+// CHECK-SAME: %[[FLOAT:.*]]: complex<f32>
+// CHECK-SAME: %[[DOUBLE:.*]]: complex<f64>
+func.func @ccos_caller(%float: complex<f32>, %double: complex<f64>) -> (complex<f32>, complex<f64>) {
+ // CHECK: %[[FLOAT_RESULT:.*]] = call @ccosf(%[[FLOAT]])
+ %float_result = complex.cos %float : complex<f32>
+ // CHECK: %[[DOUBLE_RESULT:.*]] = call @ccos(%[[DOUBLE]])
+ %double_result = complex.cos %double : complex<f64>
+ // CHECK: return %[[FLOAT_RESULT]], %[[DOUBLE_RESULT]]
+ return %float_result, %double_result : complex<f32>, complex<f64>
+}
+
+// CHECK-LABEL: func @csin_caller
+// CHECK-SAME: %[[FLOAT:.*]]: complex<f32>
+// CHECK-SAME: %[[DOUBLE:.*]]: complex<f64>
+func.func @csin_caller(%float: complex<f32>, %double: complex<f64>) -> (complex<f32>, complex<f64>) {
+ // CHECK: %[[FLOAT_RESULT:.*]] = call @csinf(%[[FLOAT]])
+ %float_result = complex.sin %float : complex<f32>
+ // CHECK: %[[DOUBLE_RESULT:.*]] = call @csin(%[[DOUBLE]])
+ %double_result = complex.sin %double : complex<f64>
+ // CHECK: return %[[FLOAT_RESULT]], %[[DOUBLE_RESULT]]
+ return %float_result, %double_result : complex<f32>, complex<f64>
+}
\ No newline at end of file
More information about the Mlir-commits
mailing list