diff --git a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp --- a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp +++ b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp @@ -577,6 +577,14 @@ struct VectorToScalarMapper { using Type = LLVM::MinimumOp; }; +template <> +struct VectorToScalarMapper { + using Type = LLVM::MaxNumOp; +}; +template <> +struct VectorToScalarMapper { + using Type = LLVM::MinNumOp; +}; } // namespace template @@ -770,6 +778,12 @@ result = createFPReductionComparisonOpLowering( rewriter, loc, llvmType, operand, acc); + } else if (kind == vector::CombiningKind::MINF) { + result = createFPReductionComparisonOpLowering( + rewriter, loc, llvmType, operand, acc); + } else if (kind == vector::CombiningKind::MAXF) { + result = createFPReductionComparisonOpLowering( + rewriter, loc, llvmType, operand, acc); } else return failure(); @@ -880,15 +894,11 @@ rewriter, loc, llvmType, operand, acc, maskOp.getMask()); break; case vector::CombiningKind::MINF: - // FIXME: MLIR's 'minf' and LLVM's 'vector_reduce_fmin' do not handle - // NaNs/-0.0/+0.0 in the same way. result = lowerReductionWithStartValue( rewriter, loc, llvmType, operand, acc, maskOp.getMask()); break; case vector::CombiningKind::MAXF: - // FIXME: MLIR's 'minf' and LLVM's 'vector_reduce_fmin' do not handle - // NaNs/-0.0/+0.0 in the same way. result = lowerReductionWithStartValue( rewriter, loc, llvmType, operand, acc, maskOp.getMask()); diff --git a/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir b/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir --- a/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir +++ b/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir @@ -1341,6 +1341,30 @@ // ----- +func.func @reduce_fmax_f32(%arg0: vector<16xf32>, %arg1: f32) -> f32 { + %0 = vector.reduction , %arg0, %arg1 : vector<16xf32> into f32 + return %0 : f32 +} +// CHECK-LABEL: @reduce_fmax_f32( +// CHECK-SAME: %[[A:.*]]: vector<16xf32>, %[[B:.*]]: f32) +// CHECK: %[[V:.*]] = llvm.intr.vector.reduce.fmax(%[[A]]) : (vector<16xf32>) -> f32 +// CHECK: %[[R:.*]] = llvm.intr.maxnum(%[[V]], %[[B]]) : (f32, f32) -> f32 +// CHECK: return %[[R]] : f32 + +// ----- + +func.func @reduce_fmin_f32(%arg0: vector<16xf32>, %arg1: f32) -> f32 { + %0 = vector.reduction , %arg0, %arg1 : vector<16xf32> into f32 + return %0 : f32 +} +// CHECK-LABEL: @reduce_fmin_f32( +// CHECK-SAME: %[[A:.*]]: vector<16xf32>, %[[B:.*]]: f32) +// CHECK: %[[V:.*]] = llvm.intr.vector.reduce.fmin(%[[A]]) : (vector<16xf32>) -> f32 +// CHECK: %[[R:.*]] = llvm.intr.minnum(%[[V]], %[[B]]) : (f32, f32) -> f32 +// CHECK: return %[[R]] : f32 + +// ----- + func.func @reduce_minui_i32(%arg0: vector<16xi32>) -> i32 { %0 = vector.reduction , %arg0 : vector<16xi32> into i32 return %0 : i32 diff --git a/mlir/test/Integration/Dialect/Vector/CPU/test-reductions-f32-reassoc.mlir b/mlir/test/Integration/Dialect/Vector/CPU/test-reductions-f32-reassoc.mlir --- a/mlir/test/Integration/Dialect/Vector/CPU/test-reductions-f32-reassoc.mlir +++ b/mlir/test/Integration/Dialect/Vector/CPU/test-reductions-f32-reassoc.mlir @@ -33,6 +33,12 @@ %3 = vector.reduction , %v2 : vector<64xf32> into f32 vector.print %3 : f32 // CHECK: 3 + %4 = vector.reduction , %v2 : vector<64xf32> into f32 + vector.print %4 : f32 + // CHECK: 1 + %5 = vector.reduction , %v2 : vector<64xf32> into f32 + vector.print %5 : f32 + // CHECK: 3 return } diff --git a/mlir/test/Integration/Dialect/Vector/CPU/test-reductions-f32.mlir b/mlir/test/Integration/Dialect/Vector/CPU/test-reductions-f32.mlir --- a/mlir/test/Integration/Dialect/Vector/CPU/test-reductions-f32.mlir +++ b/mlir/test/Integration/Dialect/Vector/CPU/test-reductions-f32.mlir @@ -45,6 +45,12 @@ %3 = vector.reduction , %v9 : vector<10xf32> into f32 vector.print %3 : f32 // CHECK: 5 + %4 = vector.reduction , %v9 : vector<10xf32> into f32 + vector.print %4 : f32 + // CHECK: -16 + %5 = vector.reduction , %v9 : vector<10xf32> into f32 + vector.print %5 : f32 + // CHECK: 5 return } diff --git a/mlir/test/Integration/Dialect/Vector/CPU/test-reductions-f64-reassoc.mlir b/mlir/test/Integration/Dialect/Vector/CPU/test-reductions-f64-reassoc.mlir --- a/mlir/test/Integration/Dialect/Vector/CPU/test-reductions-f64-reassoc.mlir +++ b/mlir/test/Integration/Dialect/Vector/CPU/test-reductions-f64-reassoc.mlir @@ -33,6 +33,12 @@ %3 = vector.reduction , %v2 : vector<64xf64> into f64 vector.print %3 : f64 // CHECK: 3 + %4 = vector.reduction , %v2 : vector<64xf64> into f64 + vector.print %4 : f64 + // CHECK: 1 + %5 = vector.reduction , %v2 : vector<64xf64> into f64 + vector.print %5 : f64 + // CHECK: 3 return } diff --git a/mlir/test/Integration/Dialect/Vector/CPU/test-reductions-f64.mlir b/mlir/test/Integration/Dialect/Vector/CPU/test-reductions-f64.mlir --- a/mlir/test/Integration/Dialect/Vector/CPU/test-reductions-f64.mlir +++ b/mlir/test/Integration/Dialect/Vector/CPU/test-reductions-f64.mlir @@ -45,6 +45,12 @@ %3 = vector.reduction , %v9 : vector<10xf64> into f64 vector.print %3 : f64 // CHECK: 5 + %4 = vector.reduction , %v9 : vector<10xf64> into f64 + vector.print %4 : f64 + // CHECK: -16 + %5 = vector.reduction , %v9 : vector<10xf64> into f64 + vector.print %5 : f64 + // CHECK: 5 return }