[Mlir-commits] [mlir] 331ebb0 - [mlir][arith] Add LLVM lowering for `maxnumf`, `minnumf` ops (#66431)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Sep 14 15:17:10 PDT 2023


Author: Daniil Dudkin
Date: 2023-09-15T01:17:05+03:00
New Revision: 331ebb0783aee8fefb86e55a073c876993914df9

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

LOG: [mlir][arith] Add LLVM lowering for `maxnumf`, `minnumf` ops (#66431)

This patch is part of a larger initiative aimed at fixing floating-point
`max` and `min` operations in MLIR:
https://discourse.llvm.org/t/rfc-fix-floating-point-max-and-min-operations-in-mlir/72671.
    
The commit addresses the task 1.4 of the RFC by adding LLVM lowering to
the corresponding LLVM intrinsics.
    
Please **note**: this PR is part of a stack of patches and depends on
#66429.

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 a695441fd8dd750..337f2dbcbe4edf5 100644
--- a/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
+++ b/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
@@ -57,6 +57,9 @@ using FPToUIOpLowering =
 using MaximumFOpLowering =
     VectorConvertToLLVMPattern<arith::MaximumFOp, LLVM::MaximumOp,
                                arith::AttrConvertFastMathToLLVM>;
+using MaxNumFOpLowering =
+    VectorConvertToLLVMPattern<arith::MaxNumFOp, LLVM::MaxNumOp,
+                               arith::AttrConvertFastMathToLLVM>;
 using MaxSIOpLowering =
     VectorConvertToLLVMPattern<arith::MaxSIOp, LLVM::SMaxOp>;
 using MaxUIOpLowering =
@@ -64,6 +67,9 @@ using MaxUIOpLowering =
 using MinimumFOpLowering =
     VectorConvertToLLVMPattern<arith::MinimumFOp, LLVM::MinimumOp,
                                arith::AttrConvertFastMathToLLVM>;
+using MinNumFOpLowering =
+    VectorConvertToLLVMPattern<arith::MinNumFOp, LLVM::MinNumOp,
+                               arith::AttrConvertFastMathToLLVM>;
 using MinSIOpLowering =
     VectorConvertToLLVMPattern<arith::MinSIOp, LLVM::SMinOp>;
 using MinUIOpLowering =
@@ -496,9 +502,11 @@ void mlir::arith::populateArithToLLVMConversionPatterns(
     IndexCastOpSILowering,
     IndexCastOpUILowering,
     MaximumFOpLowering,
+    MaxNumFOpLowering,
     MaxSIOpLowering,
     MaxUIOpLowering,
     MinimumFOpLowering,
+    MinNumFOpLowering,
     MinSIOpLowering,
     MinUIOpLowering,
     MulFOpLowering,

diff  --git a/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir b/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir
index 5855f7b3b9904fd..6f614b113788c7e 100644
--- a/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir
+++ b/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir
@@ -526,6 +526,10 @@ func.func @minmaxf(%arg0 : f32, %arg1 : f32) -> f32 {
   %0 = arith.minimumf %arg0, %arg1 : f32
   // CHECK: = llvm.intr.maximum(%arg0, %arg1) : (f32, f32) -> f32
   %1 = arith.maximumf %arg0, %arg1 : f32
+  // CHECK: = llvm.intr.minnum(%arg0, %arg1) : (f32, f32) -> f32
+  %2 = arith.minnumf %arg0, %arg1 : f32
+  // CHECK: = llvm.intr.maxnum(%arg0, %arg1) : (f32, f32) -> f32
+  %3 = arith.maxnumf %arg0, %arg1 : f32
   return %0 : f32
 }
 


        


More information about the Mlir-commits mailing list