[Mlir-commits] [mlir] 1e12793 - [MLIR]Add support for Arith MAX & MIN operations
Mats Petersson
llvmlistbot at llvm.org
Wed Aug 17 09:01:51 PDT 2022
Author: Mats Petersson
Date: 2022-08-17T17:00:53+01:00
New Revision: 1e12793491ecd4abec7c0533f52a3ff1c2e11dc4
URL: https://github.com/llvm/llvm-project/commit/1e12793491ecd4abec7c0533f52a3ff1c2e11dc4
DIFF: https://github.com/llvm/llvm-project/commit/1e12793491ecd4abec7c0533f52a3ff1c2e11dc4.diff
LOG: [MLIR]Add support for Arith MAX & MIN operations
There are some of this supported in various places, but the
basic conversion of single operations to LLVM was not supported.
Adding this to allow Flang to use these.
Reviewed By: bondhugula
Differential Revision: https://reviews.llvm.org/D131912
Added:
Modified:
mlir/lib/Conversion/ArithmeticToLLVM/ArithmeticToLLVM.cpp
mlir/test/Conversion/ArithmeticToLLVM/arith-to-llvm.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/ArithmeticToLLVM/ArithmeticToLLVM.cpp b/mlir/lib/Conversion/ArithmeticToLLVM/ArithmeticToLLVM.cpp
index 5d378342b11a2..52c922b5afbd0 100644
--- a/mlir/lib/Conversion/ArithmeticToLLVM/ArithmeticToLLVM.cpp
+++ b/mlir/lib/Conversion/ArithmeticToLLVM/ArithmeticToLLVM.cpp
@@ -68,6 +68,18 @@ using BitcastOpLowering =
VectorConvertToLLVMPattern<arith::BitcastOp, LLVM::BitcastOp>;
using SelectOpLowering =
VectorConvertToLLVMPattern<arith::SelectOp, LLVM::SelectOp>;
+using MaxFOpLowering =
+ VectorConvertToLLVMPattern<arith::MaxFOp, LLVM::MaxNumOp>;
+using MaxSIOpLowering =
+ VectorConvertToLLVMPattern<arith::MaxSIOp, LLVM::SMaxOp>;
+using MaxUIOpLowering =
+ VectorConvertToLLVMPattern<arith::MaxUIOp, LLVM::UMaxOp>;
+using MinFOpLowering =
+ VectorConvertToLLVMPattern<arith::MinFOp, LLVM::MinNumOp>;
+using MinSIOpLowering =
+ VectorConvertToLLVMPattern<arith::MinSIOp, LLVM::SMinOp>;
+using MinUIOpLowering =
+ VectorConvertToLLVMPattern<arith::MinUIOp, LLVM::UMinOp>;
//===----------------------------------------------------------------------===//
// Op Lowering Patterns
@@ -321,7 +333,13 @@ void mlir::arith::populateArithmeticToLLVMConversionPatterns(
BitcastOpLowering,
CmpIOpLowering,
CmpFOpLowering,
- SelectOpLowering
+ SelectOpLowering,
+ MaxFOpLowering,
+ MaxUIOpLowering,
+ MaxSIOpLowering,
+ MinFOpLowering,
+ MinUIOpLowering,
+ MinSIOpLowering
>(converter);
// clang-format on
}
diff --git a/mlir/test/Conversion/ArithmeticToLLVM/arith-to-llvm.mlir b/mlir/test/Conversion/ArithmeticToLLVM/arith-to-llvm.mlir
index db56d5f405f9e..24664cfddb7a6 100644
--- a/mlir/test/Conversion/ArithmeticToLLVM/arith-to-llvm.mlir
+++ b/mlir/test/Conversion/ArithmeticToLLVM/arith-to-llvm.mlir
@@ -383,3 +383,27 @@ func.func @select(%arg0 : i1, %arg1 : i32, %arg2 : i32) -> i32 {
%0 = arith.select %arg0, %arg1, %arg2 : i32
return %0 : i32
}
+
+// -----
+
+// CHECK-LABEL: @minmaxi
+func.func @minmaxi(%arg0 : i32, %arg1 : i32) -> i32 {
+ // CHECK: = "llvm.intr.smin"(%arg0, %arg1) : (i32, i32) -> i32
+ %0 = arith.minsi %arg0, %arg1 : i32
+ // CHECK: = "llvm.intr.smax"(%arg0, %arg1) : (i32, i32) -> i32
+ %1 = arith.maxsi %arg0, %arg1 : i32
+ // CHECK: = "llvm.intr.umin"(%arg0, %arg1) : (i32, i32) -> i32
+ %2 = arith.minui %arg0, %arg1 : i32
+ // CHECK: = "llvm.intr.umax"(%arg0, %arg1) : (i32, i32) -> i32
+ %3 = arith.maxui %arg0, %arg1 : i32
+ return %0 : i32
+}
+
+// CHECK-LABEL: @minmaxf
+func.func @minmaxf(%arg0 : f32, %arg1 : f32) -> f32 {
+ // CHECK: = "llvm.intr.minnum"(%arg0, %arg1) : (f32, f32) -> f32
+ %0 = arith.minf %arg0, %arg1 : f32
+ // CHECK: = "llvm.intr.maxnum"(%arg0, %arg1) : (f32, f32) -> f32
+ %1 = arith.maxf %arg0, %arg1 : f32
+ return %0 : f32
+}
More information about the Mlir-commits
mailing list