forked from OSchip/llvm-project
[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
This commit is contained in:
parent
da6ff3aecb
commit
1e12793491
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue