[Mlir-commits] [mlir] [mlir][arith] Add LLVM lowering for `maxnumf`, `minnumf` ops (PR #66431)
Daniil Dudkin
llvmlistbot at llvm.org
Thu Sep 14 14:51:01 PDT 2023
https://github.com/unterumarmung updated https://github.com/llvm/llvm-project/pull/66431:
>From 1f1c922ead0a8b756045ddc2302b8cd6bb710b82 Mon Sep 17 00:00:00 2001
From: Daniil Dudkin <unterumarmung at yandex.ru>
Date: Fri, 15 Sep 2023 00:01:30 +0300
Subject: [PATCH] [mlir][arith] Add LLVM lowering to `maxnum`, `minnum` ops
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.
---
mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp | 8 ++++++++
mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir | 4 ++++
2 files changed, 12 insertions(+)
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