[Mlir-commits] [mlir] 2e53e15 - [mlir][complex] Convert complex.abs to arith with fastmath flag

Kai Sasaki llvmlistbot at llvm.org
Mon Aug 28 17:18:29 PDT 2023


Author: Kai Sasaki
Date: 2023-08-29T09:18:01+09:00
New Revision: 2e53e15480746ab83be8f0afd64f7badd0540c91

URL: https://github.com/llvm/llvm-project/commit/2e53e15480746ab83be8f0afd64f7badd0540c91
DIFF: https://github.com/llvm/llvm-project/commit/2e53e15480746ab83be8f0afd64f7badd0540c91.diff

LOG: [mlir][complex] Convert complex.abs to arith with fastmath flag

This reverts commit 8e946fec0441e7a4eb4604c806afed20c6930cc4 after
restoring the test-pbp.exe file.

Reviewed By: kiranchandramohan

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

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 9c05cadc2f07e0..2bcec4ea10f92c 100644
--- a/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
+++ b/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
@@ -35,13 +35,18 @@ struct AbsOpConversion : public OpConversionPattern<complex::AbsOp> {
     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());
-    Value realSqr = rewriter.create<arith::MulFOp>(loc, real, real);
-    Value imagSqr = rewriter.create<arith::MulFOp>(loc, imag, imag);
-    Value sqNorm = rewriter.create<arith::AddFOp>(loc, realSqr, imagSqr);
+    Value realSqr =
+        rewriter.create<arith::MulFOp>(loc, real, real, fmf.getValue());
+    Value imagSqr =
+        rewriter.create<arith::MulFOp>(loc, imag, imag, fmf.getValue());
+    Value sqNorm =
+        rewriter.create<arith::AddFOp>(loc, realSqr, imagSqr, fmf.getValue());
 
     rewriter.replaceOpWithNewOp<math::SqrtOp>(op, sqNorm);
     return success();

diff  --git a/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir b/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
index 5e8986a4a9a464..bc2ea0dd7a5847 100644
--- a/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
+++ b/mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir
@@ -707,3 +707,19 @@ func.func @complex_angle(%arg: complex<f32>) -> f32 {
 // CHECK: %[[IMAG:.*]] = complex.im %[[ARG]] : complex<f32>
 // CHECK: %[[RESULT:.*]] = math.atan2 %[[IMAG]], %[[REAL]] : f32
 // CHECK: return %[[RESULT]] : f32
+
+// -----
+
+// CHECK-LABEL: func @complex_abs_with_fmf
+// CHECK-SAME: %[[ARG:.*]]: complex<f32>
+func.func @complex_abs_with_fmf(%arg: complex<f32>) -> f32 {
+  %abs = complex.abs %arg fastmath<nnan,contract> : complex<f32>
+  return %abs : f32
+}
+// CHECK: %[[REAL:.*]] = complex.re %[[ARG]] : complex<f32>
+// CHECK: %[[IMAG:.*]] = complex.im %[[ARG]] : complex<f32>
+// CHECK-DAG: %[[REAL_SQ:.*]] = arith.mulf %[[REAL]], %[[REAL]] fastmath<nnan,contract> : f32
+// CHECK-DAG: %[[IMAG_SQ:.*]] = arith.mulf %[[IMAG]], %[[IMAG]] fastmath<nnan,contract> : f32
+// CHECK: %[[SQ_NORM:.*]] = arith.addf %[[REAL_SQ]], %[[IMAG_SQ]] fastmath<nnan,contract> : f32
+// CHECK: %[[NORM:.*]] = math.sqrt %[[SQ_NORM]] : f32
+// CHECK: return %[[NORM]] : f32


        


More information about the Mlir-commits mailing list