[Mlir-commits] [mlir] Adding to execute_region_op some missing support (PR #164159)

Mehdi Amini llvmlistbot at llvm.org
Sun Oct 19 13:09:37 PDT 2025


================
@@ -291,9 +291,94 @@ struct MultiBlockExecuteInliner : public OpRewritePattern<ExecuteRegionOp> {
   }
 };
 
+// Pattern to eliminate ExecuteRegionOp results when it only forwards external
+// values. It operates only on execute regions with single terminator yield
+// operation.
+struct ExecuteRegionForwardingEliminator
+    : public OpRewritePattern<ExecuteRegionOp> {
+  using OpRewritePattern<ExecuteRegionOp>::OpRewritePattern;
+
+  LogicalResult matchAndRewrite(ExecuteRegionOp op,
+                                PatternRewriter &rewriter) const override {
+    if (op.getNumResults() == 0)
+      return failure();
+
+    SmallVector<Operation *> yieldOps;
+    for (Block &block : op.getRegion()) {
+      if (auto yield = dyn_cast<scf::YieldOp>(block.getTerminator())) {
+        if (yield.getResults().empty())
+          continue;
+        yieldOps.push_back(yield.getOperation());
+      }
+    }
+
+    if (yieldOps.size() != 1)
+      return failure();
+
+    auto yieldOp = dyn_cast<scf::YieldOp>(yieldOps.front());
----------------
joker-eph wrote:

```suggestion
    auto yieldOp = cast<scf::YieldOp>(yieldOps.front());
```

Can we make it a `SmallVector<YieldOp> yieldOps;` in the first place?

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


More information about the Mlir-commits mailing list