[Mlir-commits] [mlir] 534638e - [mlir][linalg] Fix crash in canonicalization pattern

Matthias Springer llvmlistbot at llvm.org
Wed Nov 2 06:11:29 PDT 2022


Author: Matthias Springer
Date: 2022-11-02T14:05:48+01:00
New Revision: 534638eae31a51eca76de8b829b81e6c1fee083b

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

LOG: [mlir][linalg] Fix crash in canonicalization pattern

This crash was due to incorrect usage of `hasTensorSemantics`, which has changed recently with DestinationStyleOpInterface. An op has tensor semantics if all of its inits and inputs are tensors. Previously, only inits needed to be tensors.

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

Added: 
    

Modified: 
    mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
    mlir/test/Dialect/Linalg/canonicalize.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
index ae2514c3eecd..568b9317ca36 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
@@ -935,10 +935,9 @@ struct DeduplicateAndRemoveDeadOperandsAndResults
     // Create the new op with the body being empty.
     Location loc = genericOp.getLoc();
     SmallVector<Type> newResultTypes;
-    if (genericOp.hasTensorSemantics()) {
-      newResultTypes = llvm::to_vector(llvm::map_range(
-          newOutputOperands, [](Value v) { return v.getType(); }));
-    }
+    for (Value v : newOutputOperands)
+      if (v.getType().isa<TensorType>())
+        newResultTypes.push_back(v.getType());
     auto newOp = rewriter.create<GenericOp>(
         loc, newResultTypes, newInputOperands, newOutputOperands,
         rewriter.getAffineMapArrayAttr(newIndexingMaps),

diff  --git a/mlir/test/Dialect/Linalg/canonicalize.mlir b/mlir/test/Dialect/Linalg/canonicalize.mlir
index 8f8f6000966e..3f1118334ef5 100644
--- a/mlir/test/Dialect/Linalg/canonicalize.mlir
+++ b/mlir/test/Dialect/Linalg/canonicalize.mlir
@@ -846,3 +846,27 @@ func.func @identity_mixed(%arg0 : tensor<?xf32>, %arg1: memref<?xf32>) {
 //  CHECK-SAME:    iterator_types = ["parallel"]
 //  CHECK-SAME:  } ins(%[[ARG1]] : tensor<?xf32>)
 //  CHECK-SAME:    outs(%[[ARG2]] : memref<?xf32>) {
+
+// -----
+
+// Just make sure that we don't crash.
+
+// CHECK-LABEL: func @dedeplicate_regression_test
+func.func @dedeplicate_regression_test(%0: tensor<4xf32>, %1: memref<4xf32>) {
+  %36 = linalg.generic
+    {indexing_maps = [affine_map<(d0) -> (d0)>,
+                      affine_map<(d0) -> (d0)>, affine_map<(d0) -> (d0)>],
+     iterator_types = ["parallel"]}
+    ins(%1, %1 : memref<4xf32>, memref<4xf32>)
+    outs(%0 : tensor<4xf32>) {
+  ^bb0(%in: f32, %in_24: f32, %out: f32):
+    linalg.yield %in : f32
+  } -> tensor<4xf32>
+  %53 = linalg.generic {indexing_maps = [affine_map<(d0) -> (d0)>],
+                        iterator_types = ["parallel"]}
+                        outs(%36 : tensor<4xf32>) {
+  ^bb0(%out: f32):
+    linalg.yield %out : f32
+  } -> tensor<4xf32>
+  return
+}


        


More information about the Mlir-commits mailing list