[Mlir-commits] [mlir] e72fb69 - [mlir][arith] Convert fastmath to LLVM dialect for some arith ops.

Slava Zakharin llvmlistbot at llvm.org
Mon Nov 7 19:57:23 PST 2022


Author: Slava Zakharin
Date: 2022-11-07T19:39:51-08:00
New Revision: e72fb692104ebab682d1ea5aeec39358b11ad407

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

LOG: [mlir][arith] Convert fastmath to LLVM dialect for some arith ops.

This is a follow-up on D126305 and D136225.
We can now preserve fastmath for arith::MaxFOp,MinFOp,RemFOp during
ArithToLLVM conversion.

Reviewed By: rriddle

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

Added: 
    

Modified: 
    mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
    mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp b/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
index 1409b7fe1bca..3ad01556b2f6 100644
--- a/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
+++ b/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
@@ -52,16 +52,16 @@ using FPToSIOpLowering =
     VectorConvertToLLVMPattern<arith::FPToSIOp, LLVM::FPToSIOp>;
 using FPToUIOpLowering =
     VectorConvertToLLVMPattern<arith::FPToUIOp, LLVM::FPToUIOp>;
-// TODO: Add LLVM intrinsic support for fastmath
-using MaxFOpLowering = VectorConvertToLLVMPattern<arith::MaxFOp, LLVM::MaxNumOp,
-                                                  arith::AttrDropFastMath>;
+using MaxFOpLowering =
+    VectorConvertToLLVMPattern<arith::MaxFOp, LLVM::MaxNumOp,
+                               arith::AttrConvertFastMathToLLVM>;
 using MaxSIOpLowering =
     VectorConvertToLLVMPattern<arith::MaxSIOp, LLVM::SMaxOp>;
 using MaxUIOpLowering =
     VectorConvertToLLVMPattern<arith::MaxUIOp, LLVM::UMaxOp>;
-// TODO: Add LLVM intrinsic support for fastmath
-using MinFOpLowering = VectorConvertToLLVMPattern<arith::MinFOp, LLVM::MinNumOp,
-                                                  arith::AttrDropFastMath>;
+using MinFOpLowering =
+    VectorConvertToLLVMPattern<arith::MinFOp, LLVM::MinNumOp,
+                               arith::AttrConvertFastMathToLLVM>;
 using MinSIOpLowering =
     VectorConvertToLLVMPattern<arith::MinSIOp, LLVM::SMinOp>;
 using MinUIOpLowering =
@@ -74,9 +74,9 @@ using NegFOpLowering =
     VectorConvertToLLVMPattern<arith::NegFOp, LLVM::FNegOp,
                                arith::AttrConvertFastMathToLLVM>;
 using OrIOpLowering = VectorConvertToLLVMPattern<arith::OrIOp, LLVM::OrOp>;
-// TODO: Add LLVM intrinsic support for fastmath
-using RemFOpLowering = VectorConvertToLLVMPattern<arith::RemFOp, LLVM::FRemOp,
-                                                  arith::AttrDropFastMath>;
+using RemFOpLowering =
+    VectorConvertToLLVMPattern<arith::RemFOp, LLVM::FRemOp,
+                               arith::AttrConvertFastMathToLLVM>;
 using RemSIOpLowering =
     VectorConvertToLLVMPattern<arith::RemSIOp, LLVM::SRemOp>;
 using RemUIOpLowering =

diff  --git a/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir b/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir
index eccd8755d7aa..d8e49a55c2ad 100644
--- a/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir
+++ b/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir
@@ -453,11 +453,11 @@ func.func @minmaxf(%arg0 : f32, %arg1 : f32) -> f32 {
 
 // CHECK-LABEL: @fastmath
 func.func @fastmath(%arg0: f32, %arg1: f32, %arg2: i32) {
-// CHECK: {{.*}} = llvm.fadd %arg0, %arg1  {fastmathFlags = #llvm.fastmath<fast>} : f32
-// CHECK: {{.*}} = llvm.fmul %arg0, %arg1  {fastmathFlags = #llvm.fastmath<fast>} : f32
-// CHECK: {{.*}} = llvm.fneg %arg0  {fastmathFlags = #llvm.fastmath<fast>} : f32
-// CHECK: {{.*}} = llvm.fadd %arg0, %arg1  : f32
-// CHECK: {{.*}} = llvm.fadd %arg0, %arg1  {fastmathFlags = #llvm.fastmath<nnan, ninf>} : f32
+// CHECK: llvm.fadd %arg0, %arg1  {fastmathFlags = #llvm.fastmath<fast>} : f32
+// CHECK: llvm.fmul %arg0, %arg1  {fastmathFlags = #llvm.fastmath<fast>} : f32
+// CHECK: llvm.fneg %arg0  {fastmathFlags = #llvm.fastmath<fast>} : f32
+// CHECK: llvm.fadd %arg0, %arg1  : f32
+// CHECK: llvm.fadd %arg0, %arg1  {fastmathFlags = #llvm.fastmath<nnan, ninf>} : f32
   %0 = arith.addf %arg0, %arg1 fastmath<fast> : f32
   %1 = arith.mulf %arg0, %arg1 fastmath<fast> : f32
   %2 = arith.negf %arg0 fastmath<fast> : f32
@@ -465,3 +465,26 @@ func.func @fastmath(%arg0: f32, %arg1: f32, %arg2: i32) {
   %4 = arith.addf %arg0, %arg1 fastmath<nnan,ninf> : f32
   return
 }
+
+// -----
+
+// CHECK-LABEL: @ops_supporting_fastmath
+func.func @ops_supporting_fastmath(%arg0: f32, %arg1: f32, %arg2: i32) {
+// CHECK: llvm.fadd %arg0, %arg1  {fastmathFlags = #llvm.fastmath<fast>} : f32
+  %0 = arith.addf %arg0, %arg1 fastmath<fast> : f32
+// CHECK: llvm.fdiv %arg0, %arg1  {fastmathFlags = #llvm.fastmath<fast>} : f32
+  %1 = arith.divf %arg0, %arg1 fastmath<fast> : f32
+// CHECK: llvm.intr.maxnum(%arg0, %arg1) {fastmathFlags = #llvm.fastmath<fast>} : (f32, f32) -> f32
+  %2 = arith.maxf %arg0, %arg1 fastmath<fast> : f32
+// CHECK: llvm.intr.minnum(%arg0, %arg1) {fastmathFlags = #llvm.fastmath<fast>} : (f32, f32) -> f32
+  %3 = arith.minf %arg0, %arg1 fastmath<fast> : f32
+// CHECK: llvm.fmul %arg0, %arg1  {fastmathFlags = #llvm.fastmath<fast>} : f32
+  %4 = arith.mulf %arg0, %arg1 fastmath<fast> : f32
+// CHECK: llvm.fneg %arg0  {fastmathFlags = #llvm.fastmath<fast>} : f32
+  %5 = arith.negf %arg0 fastmath<fast> : f32
+// CHECK: llvm.frem %arg0, %arg1  {fastmathFlags = #llvm.fastmath<fast>} : f32
+  %6 = arith.remf %arg0, %arg1 fastmath<fast> : f32
+// CHECK: llvm.fsub %arg0, %arg1  {fastmathFlags = #llvm.fastmath<fast>} : f32
+  %7 = arith.subf %arg0, %arg1 fastmath<fast> : f32
+  return
+}


        


More information about the Mlir-commits mailing list