Skip to content

Commit 331ebb0

Browse files
[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.
1 parent 1feb00a commit 331ebb0

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,19 @@ using FPToUIOpLowering =
5757
using MaximumFOpLowering =
5858
VectorConvertToLLVMPattern<arith::MaximumFOp, LLVM::MaximumOp,
5959
arith::AttrConvertFastMathToLLVM>;
60+
using MaxNumFOpLowering =
61+
VectorConvertToLLVMPattern<arith::MaxNumFOp, LLVM::MaxNumOp,
62+
arith::AttrConvertFastMathToLLVM>;
6063
using MaxSIOpLowering =
6164
VectorConvertToLLVMPattern<arith::MaxSIOp, LLVM::SMaxOp>;
6265
using MaxUIOpLowering =
6366
VectorConvertToLLVMPattern<arith::MaxUIOp, LLVM::UMaxOp>;
6467
using MinimumFOpLowering =
6568
VectorConvertToLLVMPattern<arith::MinimumFOp, LLVM::MinimumOp,
6669
arith::AttrConvertFastMathToLLVM>;
70+
using MinNumFOpLowering =
71+
VectorConvertToLLVMPattern<arith::MinNumFOp, LLVM::MinNumOp,
72+
arith::AttrConvertFastMathToLLVM>;
6773
using MinSIOpLowering =
6874
VectorConvertToLLVMPattern<arith::MinSIOp, LLVM::SMinOp>;
6975
using MinUIOpLowering =
@@ -496,9 +502,11 @@ void mlir::arith::populateArithToLLVMConversionPatterns(
496502
IndexCastOpSILowering,
497503
IndexCastOpUILowering,
498504
MaximumFOpLowering,
505+
MaxNumFOpLowering,
499506
MaxSIOpLowering,
500507
MaxUIOpLowering,
501508
MinimumFOpLowering,
509+
MinNumFOpLowering,
502510
MinSIOpLowering,
503511
MinUIOpLowering,
504512
MulFOpLowering,

mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,10 @@ func.func @minmaxf(%arg0 : f32, %arg1 : f32) -> f32 {
526526
%0 = arith.minimumf %arg0, %arg1 : f32
527527
// CHECK: = llvm.intr.maximum(%arg0, %arg1) : (f32, f32) -> f32
528528
%1 = arith.maximumf %arg0, %arg1 : f32
529+
// CHECK: = llvm.intr.minnum(%arg0, %arg1) : (f32, f32) -> f32
530+
%2 = arith.minnumf %arg0, %arg1 : f32
531+
// CHECK: = llvm.intr.maxnum(%arg0, %arg1) : (f32, f32) -> f32
532+
%3 = arith.maxnumf %arg0, %arg1 : f32
529533
return %0 : f32
530534
}
531535

0 commit comments

Comments
 (0)