[Mlir-commits] [mlir] e1af755 - [mlir] return nullopt for getNeutralElement

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Jan 31 22:47:17 PST 2023


Author: Xiang
Date: 2023-02-01T00:47:01-05:00
New Revision: e1af75572d3a0789cf91bf06869cec69a2741b85

URL: https://github.com/llvm/llvm-project/commit/e1af75572d3a0789cf91bf06869cec69a2741b85
DIFF: https://github.com/llvm/llvm-project/commit/e1af75572d3a0789cf91bf06869cec69a2741b85.diff

LOG: [mlir] return nullopt for getNeutralElement

Fixes 60210  https://github.com/llvm/llvm-project/issues/60210

Crash for return Attribute instead of nullopt.

Differential Revision: https://reviews.llvm.org/D142945

Added: 
    

Modified: 
    mlir/lib/Dialect/Linalg/Utils/Utils.cpp
    mlir/test/Dialect/Linalg/transform-tile-reduction.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Linalg/Utils/Utils.cpp b/mlir/lib/Dialect/Linalg/Utils/Utils.cpp
index c45c34c65d09e..7ea36248c96f7 100644
--- a/mlir/lib/Dialect/Linalg/Utils/Utils.cpp
+++ b/mlir/lib/Dialect/Linalg/Utils/Utils.cpp
@@ -1077,7 +1077,7 @@ std::optional<Attribute> getNeutralElement(Operation *op) {
     if (isa<arith::MinFOp>(op))
       return b.getFloatAttr(
           resultType, llvm::APFloat::getInf(semantic, /*Negative=*/false));
-    return Attribute();
+    return std::nullopt;
   }
   if (isa<arith::AddIOp, arith::OrIOp, arith::XOrIOp>(op))
     return b.getIntegerAttr(resultType, 0);

diff  --git a/mlir/test/Dialect/Linalg/transform-tile-reduction.mlir b/mlir/test/Dialect/Linalg/transform-tile-reduction.mlir
index ec8956cf716cc..4525527bd7777 100644
--- a/mlir/test/Dialect/Linalg/transform-tile-reduction.mlir
+++ b/mlir/test/Dialect/Linalg/transform-tile-reduction.mlir
@@ -330,3 +330,28 @@ transform.sequence failures(propagate) {
     by num_threads = [5], tile_sizes = [3], mapping = [#gpu.thread<x>]
 
 }
+
+// -----
+
+#map = affine_map<(d0, d1) -> (d0, d1)>
+#map1 = affine_map<(d0, d1) -> (d0)>
+
+module {
+  func.func @fail_for_float_neutral(%arg0: tensor<?x?xf32>, %arg1: tensor<?xf32>) -> tensor<?xf32> {
+    // expected-error @below {{'linalg.generic' op Failed to get an identity value for the reduction operation.}}
+    // expected-note @below {{when applied to this op}}
+    %0 = linalg.generic {indexing_maps = [#map, #map1], iterator_types = ["parallel", "reduction"]} ins(%arg0 : tensor<?x?xf32>) outs(%arg1 : tensor<?xf32>) {
+    ^bb0(%in: f32, %out: f32):
+      %1 = llvm.fmul %in, %in  : f32
+      %2 = llvm.fadd %1, %out  : f32
+      linalg.yield %2 : f32
+    } -> tensor<?xf32>
+    return %0 : tensor<?xf32>
+  }
+  transform.sequence failures(propagate) {
+  ^bb0(%arg0: !pdl.operation):
+    %0 = transform.structured.match ops{["linalg.generic"]} in %arg0 : (!pdl.operation) -> !pdl.operation
+    // expected-error @below {{transform.structured.tile_reduction_using_scf failed to apply}}
+    %for_op, %fill_op, %split_linalg_op, %combining_linalg_op = transform.structured.tile_reduction_using_scf %0 by tile_sizes = [0, 5]
+  }
+}


        


More information about the Mlir-commits mailing list