[llvm] [mlir] [MLIR] Generalize expand_shape to take shape as explicit input (PR #90040)

Gaurav Shukla via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 25 22:40:40 PDT 2024


================
@@ -750,6 +750,31 @@ static void updateExpandedGenericOpRegion(PatternRewriter &rewriter,
   }
 }
 
+/// Checks if a single dynamic dimension expanded into multiple dynamic
+/// dimensions.
+static LogicalResult
+validateDynamicDimExpansion(LinalgOp linalgOp,
+                            const ExpansionInfo &expansionInfo,
+                            PatternRewriter &rewriter) {
+  for (unsigned i : llvm::seq<unsigned>(0, expansionInfo.getOrigOpNumDims())) {
+    ArrayRef<int64_t> expandedShape = expansionInfo.getExpandedShapeOfDim(i);
+    if (expandedShape.size() == 1)
+      continue;
+    bool foundDynamic = false;
+    for (int64_t shape : expandedShape) {
+      if (ShapedType::isDynamic(shape)) {
+        if (foundDynamic) {
+          return rewriter.notifyMatchFailure(
+              linalgOp, "cannot infer expanded shape with multiple dynamic "
+                        "dims in the same reassociation group");
----------------
Shukla-Gaurav wrote:

I am not sure how to add a test for this diagnostic message. This utility function puts an early check to detect cases where fusion by expansion is not possible.

https://github.com/llvm/llvm-project/pull/90040


More information about the llvm-commits mailing list