[Lldb-commits] [lldb] 653f776 - [mlir][complex] Convert complex.abs to arith with fastmath flag

Kai Sasaki via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 24 20:11:58 PDT 2023


Author: Kai Sasaki
Date: 2023-08-25T12:10:43+09:00
New Revision: 653f77690bb2473ff405ccc681c73217fae8b748

URL: https://github.com/llvm/llvm-project/commit/653f77690bb2473ff405ccc681c73217fae8b748
DIFF: https://github.com/llvm/llvm-project/commit/653f77690bb2473ff405ccc681c73217fae8b748.diff

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

Added: 
    

Modified: 
    mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
    mlir/test/Conversion/ComplexToStandard/convert-to-standard.mlir

Removed: 
    lldb/unittests/SymbolFile/PDB/Inputs/test-pdb.exe


################################################################################
diff  --git a/lldb/unittests/SymbolFile/PDB/Inputs/test-pdb.exe b/lldb/unittests/SymbolFile/PDB/Inputs/test-pdb.exe
deleted file mode 100644
index 3a2c64504ed93ca..000000000000000
Binary files a/lldb/unittests/SymbolFile/PDB/Inputs/test-pdb.exe and /dev/null 
diff er

diff  --git a/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp b/mlir/lib/Conversion/ComplexToStandard/ComplexToStandard.cpp
index 9c05cadc2f07e05..2bcec4ea10f92c5 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 5e8986a4a9a464c..bc2ea0dd7a5847a 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 lldb-commits mailing list