diff --git a/mlir/lib/Conversion/ComplexToLibm/ComplexToLibm.cpp b/mlir/lib/Conversion/ComplexToLibm/ComplexToLibm.cpp --- a/mlir/lib/Conversion/ComplexToLibm/ComplexToLibm.cpp +++ b/mlir/lib/Conversion/ComplexToLibm/ComplexToLibm.cpp @@ -109,6 +109,8 @@ "conjf", "conj", benefit); patterns.add>( patterns.getContext(), "cabsf", "cabs", benefit); + patterns.add>( + patterns.getContext(), "cargf", "carg", benefit); } namespace { @@ -127,7 +129,7 @@ ConversionTarget target(getContext()); target.addLegalDialect(); target.addIllegalOp(); + complex::AbsOp, complex::AngleOp>(); 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 --- a/mlir/test/Conversion/ComplexToLibm/convert-to-libm.mlir +++ b/mlir/test/Conversion/ComplexToLibm/convert-to-libm.mlir @@ -93,4 +93,16 @@ %double_result = complex.abs %double : complex // CHECK: return %[[FLOAT_RESULT]], %[[DOUBLE_RESULT]] return %float_result, %double_result : f32, f64 +} + +// CHECK-LABEL: func @carg_caller +// CHECK-SAME: %[[FLOAT:.*]]: complex +// CHECK-SAME: %[[DOUBLE:.*]]: complex +func.func @carg_caller(%float: complex, %double: complex) -> (f32, f64) { + // CHECK: %[[FLOAT_RESULT:.*]] = call @cargf(%[[FLOAT]]) + %float_result = complex.angle %float : complex + // CHECK: %[[DOUBLE_RESULT:.*]] = call @carg(%[[DOUBLE]]) + %double_result = complex.angle %double : complex + // CHECK: return %[[FLOAT_RESULT]], %[[DOUBLE_RESULT]] + return %float_result, %double_result : f32, f64 } \ No newline at end of file