[Mlir-commits] [mlir] [mlir] Fix non-termination when a block becomes unreachable during rewriting (PR #221152)

Vijay Kandiah llvmlistbot at llvm.org
Fri Sep 4 08:58:05 PDT 2026


================
@@ -482,6 +482,15 @@ bool GreedyPatternRewriteDriver::processWorklist() {
       }
     });
 
+    // Folding an operation that uses its own result can loop forever, so
+    // skip it. Such operations are legal in unreachable code.
+    if (llvm::any_of(op->getOperands(), [op](Value operand) {
+          return operand.getDefiningOp() == op;
+        })) {
+      LLVM_DEBUG(logResultWithLine("failure", "operation uses its own result"));
+      continue;
+    }
----------------
VijayKandiah wrote:

The cost here does scale with #ops popped from the worklist. Let me think a bit about an approach that detects the CFG change. 

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


More information about the Mlir-commits mailing list