[Mlir-commits] [mlir] 8c9d814 - [mlir][complex] Fastmath flag for complex angle (#88658)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Apr 16 17:19:19 PDT 2024
Author: Kai Sasaki
Date: 2024-04-17T09:19:15+09:00
New Revision: 8c9d814b66f7df274de41225575817188fbeed4f
URL: https://github.com/llvm/llvm-project/commit/8c9d814b66f7df274de41225575817188fbeed4f
DIFF: https://github.com/llvm/llvm-project/commit/8c9d814b66f7df274de41225575817188fbeed4f.diff
LOG: [mlir][complex] Fastmath flag for complex angle (#88658)
See
https://discourse.llvm.org/t/rfc-fastmath-flags-support-in-complex-dialect/71981
Added:
Modified:
mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp b/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
index 03e578136e5901..4a15976d40c763 100644
--- a/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
+++ b/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
@@ -1289,13 +1289,14 @@ struct AngleOpConversion : public OpConversionPattern<complex::AngleOp> {
ConversionPatternRewriter &rewriter) const override {
auto loc = op.getLoc();
auto type = op.getType();
+ arith::FastMathFlagsAttr fmf = op.getFastMathFlagsAttr();
Value real =
rewriter.create<complex::ReOp>(loc, type, adaptor.getComplex());
Value imag =
rewriter.create<complex::ImOp>(loc, type, adaptor.getComplex());
- rewriter.replaceOpWithNewOp<math::Atan2Op>(op, imag, real);
+ rewriter.replaceOpWithNewOp<math::Atan2Op>(op, imag, real, fmf);
return success();
}
diff --git a/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir b/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
index fa1d564d6ad355..827ae940165c7e 100644
--- a/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
+++ b/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
@@ -2187,3 +2187,16 @@ func.func @complex_tanh_nnan_ninf(%arg: complex<f32>) -> complex<f32> {
// CHECK-COUNT-1: arith.select
// CHECK-NOT: arith.select
+
+// -----
+
+// CHECK-LABEL: func.func @complex_angle_with_fmf
+// CHECK-SAME: %[[ARG:.*]]: complex<f32>
+func.func @complex_angle_with_fmf(%arg: complex<f32>) -> f32 {
+ %angle = complex.angle %arg fastmath<nnan,contract> : complex<f32>
+ return %angle : f32
+}
+// CHECK: %[[REAL:.*]] = complex.re %[[ARG]] : complex<f32>
+// CHECK: %[[IMAG:.*]] = complex.im %[[ARG]] : complex<f32>
+// CHECK: %[[RESULT:.*]] = math.atan2 %[[IMAG]], %[[REAL]] fastmath<nnan,contract> : f32
+// CHECK: return %[[RESULT]] : f32
\ No newline at end of file
More information about the Mlir-commits
mailing list