[llvm-branch-commits] [mlir] [mlir][Transforms] Dialect Conversion: Add `replaceOpWithMultiple` (PR #115816)

Markus Böck via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Nov 12 02:46:11 PST 2024


================
@@ -1417,12 +1441,21 @@ void ConversionPatternRewriterImpl::notifyOpReplaced(Operation *op,
     }
 
     // Remap result to replacement value.
-    if (newValue)
-      mapping.map(result, newValue);
+    if (!repl.empty()) {
+      if (repl.size() == 1) {
+        // Single replacement value: replace directly.
+        mapping.map(result, repl.front());
+      } else {
+        // Multiple replacement values: insert N:1 materialization.
+        insertNTo1Materialization(OpBuilder::InsertPoint::after(repl, &domInfo),
+                                  result.getLoc(),
+                                  /*replacements=*/repl, /*outputValue=*/result,
+                                  currentTypeConverter);
+      }
+    }
----------------
zero9178 wrote:

```suggestion
    if (repl.empty())
      continue;
      
    if (repl.size() == 1) {
      // Single replacement value: replace directly.
      mapping.map(result, repl.front());
    } else {
      // Multiple replacement values: insert N:1 materialization.
      insertNTo1Materialization(OpBuilder::InsertPoint::after(repl, &domInfo),
                                result.getLoc(),
                                /*replacements=*/repl, /*outputValue=*/result,
                                currentTypeConverter);
    }
```

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


More information about the llvm-branch-commits mailing list