[mlir][complex] Lower complex.angle to libm

complex.angle corresponds to arg function in libm. We can lower complex.angle to arg and argf.

Reviewed By: pifon2a

Differential Revision: https://reviews.llvm.org/D129341
This commit is contained in:
lewuathe 2022-07-08 04:30:26 +02:00 committed by Alexander Belyaev
parent 18a1085e02
commit f27deeee79
2 changed files with 15 additions and 1 deletions

View File

@ -109,6 +109,8 @@ void mlir::populateComplexToLibmConversionPatterns(RewritePatternSet &patterns,
"conjf", "conj", benefit);
patterns.add<ScalarOpToLibmCall<complex::AbsOp, FloatTypeResolver>>(
patterns.getContext(), "cabsf", "cabs", benefit);
patterns.add<ScalarOpToLibmCall<complex::AngleOp, FloatTypeResolver>>(
patterns.getContext(), "cargf", "carg", benefit);
}
namespace {
@ -127,7 +129,7 @@ void ConvertComplexToLibmPass::runOnOperation() {
ConversionTarget target(getContext());
target.addLegalDialect<func::FuncDialect>();
target.addIllegalOp<complex::PowOp, complex::SqrtOp, complex::TanhOp,
complex::AbsOp>();
complex::AbsOp, complex::AngleOp>();
if (failed(applyPartialConversion(module, target, std::move(patterns))))
signalPassFailure();
}

View File

@ -93,4 +93,16 @@ func.func @cabs_caller(%float: complex<f32>, %double: complex<f64>) -> (f32, f64
%double_result = complex.abs %double : complex<f64>
// CHECK: return %[[FLOAT_RESULT]], %[[DOUBLE_RESULT]]
return %float_result, %double_result : f32, f64
}
// CHECK-LABEL: func @carg_caller
// CHECK-SAME: %[[FLOAT:.*]]: complex<f32>
// CHECK-SAME: %[[DOUBLE:.*]]: complex<f64>
func.func @carg_caller(%float: complex<f32>, %double: complex<f64>) -> (f32, f64) {
// CHECK: %[[FLOAT_RESULT:.*]] = call @cargf(%[[FLOAT]])
%float_result = complex.angle %float : complex<f32>
// CHECK: %[[DOUBLE_RESULT:.*]] = call @carg(%[[DOUBLE]])
%double_result = complex.angle %double : complex<f64>
// CHECK: return %[[FLOAT_RESULT]], %[[DOUBLE_RESULT]]
return %float_result, %double_result : f32, f64
}