[Mlir-commits] [mlir] a032b47 - [mlir][linalg] Fix neutral element value for minf/maxf
Thomas Raoux
llvmlistbot at llvm.org
Fri Nov 4 09:35:51 PDT 2022
Author: Thomas Raoux
Date: 2022-11-04T16:35:40Z
New Revision: a032b47e7e7792d57a26c0dcb38ecd12c28a0248
URL: https://github.com/llvm/llvm-project/commit/a032b47e7e7792d57a26c0dcb38ecd12c28a0248
DIFF: https://github.com/llvm/llvm-project/commit/a032b47e7e7792d57a26c0dcb38ecd12c28a0248.diff
LOG: [mlir][linalg] Fix neutral element value for minf/maxf
The neutral element got minf/maxf should be respectively +inf and -inf.
Bug reported by @Hardcode84.
Differential Revision: https://reviews.llvm.org/D137385
Added:
Modified:
mlir/lib/Dialect/Linalg/Utils/Utils.cpp
mlir/test/Dialect/Linalg/transform-op-split-reduction.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Linalg/Utils/Utils.cpp b/mlir/lib/Dialect/Linalg/Utils/Utils.cpp
index 04cbed0c4e13..ccf7cdc4aadb 100644
--- a/mlir/lib/Dialect/Linalg/Utils/Utils.cpp
+++ b/mlir/lib/Dialect/Linalg/Utils/Utils.cpp
@@ -1073,10 +1073,10 @@ Optional<Attribute> getNeutralElement(Operation *op) {
return b.getFloatAttr(resultType, llvm::APFloat(semantic, 1));
if (isa<arith::MaxFOp>(op))
return b.getFloatAttr(resultType,
- llvm::APFloat::getLargest(semantic, true));
+ llvm::APFloat::getInf(semantic, /*Negative=*/true));
if (isa<arith::MinFOp>(op))
- return b.getFloatAttr(resultType,
- llvm::APFloat::getLargest(semantic, true));
+ return b.getFloatAttr(
+ resultType, llvm::APFloat::getInf(semantic, /*Negative=*/false));
return Attribute();
}
if (isa<arith::AddIOp, arith::OrIOp, arith::XOrIOp>(op))
diff --git a/mlir/test/Dialect/Linalg/transform-op-split-reduction.mlir b/mlir/test/Dialect/Linalg/transform-op-split-reduction.mlir
index ee5f98bc2ce0..cb7a92198c04 100644
--- a/mlir/test/Dialect/Linalg/transform-op-split-reduction.mlir
+++ b/mlir/test/Dialect/Linalg/transform-op-split-reduction.mlir
@@ -112,7 +112,7 @@ func.func @generic_split_3d(%input: tensor<32x2xf32>, %input_2: tensor<5x32xf32>
// CHECK-DAG: #[[$MAP3:.*]] = affine_map<(d0, d1, d2) -> (d0, d1, d2)>
// CHECK-DAG: #[[$MAP4:.*]] = affine_map<(d0, d1, d2) -> (d0, d1)>
// CHECK-LABEL: func @generic_split_3d
-// CHECK-DAG: %[[ID:.*]] = arith.constant -3.40282347E+38 : f32
+// CHECK-DAG: %[[ID:.*]] = arith.constant 0xFF800000 : f32
// CHECK-DAG: %[[I1:.*]] = tensor.expand_shape %{{.*}}[0, 1], [2]] : tensor<32x2xf32> into tensor<4x8x2xf32>
// CHECK-DAG: %[[I2:.*]] = tensor.expand_shape %{{.*}}[0], [1, 2]] : tensor<5x32xf32> into tensor<5x4x8xf32>
// CHECK-DAG: %[[INI:.*]] = tensor.empty() : tensor<5x2x4xf32>
@@ -238,7 +238,7 @@ func.func @generic_split_3d(%input: tensor<32x2xf32>, %input_2: tensor<5x32xf32>
} ins(%input, %input_2 : tensor<32x2xf32>, tensor<5x32xf32>) outs(%output : tensor<5x2xf32>) {
^bb0(%arg0: f32, %arg1: f32, %arg2: f32):
%3 = arith.addf %arg0, %arg1 : f32
- %4 = arith.maxf %3, %arg2 : f32
+ %4 = arith.minf %3, %arg2 : f32
linalg.yield %4 : f32
} -> tensor<5x2xf32>
return %0 : tensor<5x2xf32>
@@ -250,7 +250,7 @@ func.func @generic_split_3d(%input: tensor<32x2xf32>, %input_2: tensor<5x32xf32>
// CHECK-DAG: #[[$MAP3:.*]] = affine_map<(d0, d1, d2) -> (d0, d1, d2)>
// CHECK-DAG: #[[$MAP4:.*]] = affine_map<(d0, d1, d2) -> (d0, d1)>
// CHECK-LABEL: func @generic_split_3d
-// CHECK-DAG: %[[ID:.*]] = arith.constant -3.40282347E+38 : f32
+// CHECK-DAG: %[[ID:.*]] = arith.constant 0x7F800000 : f32
// CHECK-DAG: %[[I1:.*]] = tensor.expand_shape %{{.*}}[0, 1], [2]] : tensor<32x2xf32> into tensor<8x4x2xf32>
// CHECK-DAG: %[[I2:.*]] = tensor.expand_shape %{{.*}}[0], [1, 2]] : tensor<5x32xf32> into tensor<5x8x4xf32>
// CHECK-DAG: %[[INI:.*]] = tensor.empty() : tensor<5x2x4xf32>
@@ -258,12 +258,12 @@ func.func @generic_split_3d(%input: tensor<32x2xf32>, %input_2: tensor<5x32xf32>
// CHECK: %[[G:.*]] = linalg.generic {indexing_maps = [#[[$MAP0]], #[[$MAP1]], #[[$MAP2]]], iterator_types = ["parallel", "reduction", "parallel", "parallel"]}
// CHECK-SAME: ins(%[[I1]], %[[I2]] : tensor<8x4x2xf32>, tensor<5x8x4xf32>) outs(%[[F]] : tensor<5x2x4xf32>) {
// CHECK: arith.addf
-// CHECK: arith.maxf
+// CHECK: arith.minf
// CHECK: linalg.yield
// CHECK: } -> tensor<5x2x4xf32>
// CHECK: %[[R:.*]] = linalg.generic {indexing_maps = [#[[$MAP3]], #[[$MAP4]]], iterator_types = ["parallel", "parallel", "reduction"]}
// CHECK-SAME: ins(%[[G]] : tensor<5x2x4xf32>) outs(%{{.*}} : tensor<5x2xf32>) {
-// CHECK: arith.maxf
+// CHECK: arith.minf
// CHECK: linalg.yield
// CHECK: } -> tensor<5x2xf32>
// CHECK: return %[[R]] : tensor<5x2xf32>
More information about the Mlir-commits
mailing list