[Mlir-commits] [flang] [mlir] [mlir][CSE] Add pruneDeadOps to CSE pass (PR #193778)
lonely eagle
llvmlistbot at llvm.org
Sat May 9 01:58:52 PDT 2026
================
@@ -294,15 +297,38 @@ LogicalResult CSEDriver::simplifyOperation(ScopedMapTy &knownValues,
return failure();
}
+void CSEDriver::pruneDeadOps(Operation *root, ScopedMapTy &knownValues) {
+ // We use `SetVector` to prevent already inserted ops from being added to the
+ // `worklist` repeatedly, avoiding secondary access to erased operations.
+ llvm::SetVector<Operation *> worklist;
+ worklist.insert(root);
+ while (!worklist.empty()) {
+ Operation *op = worklist.front();
+ worklist.erase(worklist.begin());
+ if (!isOpTriviallyDead(op))
+ continue;
+
+ for (Value arg : op->getOperands())
+ if (Operation *argOp = arg.getDefiningOp())
+ worklist.insert(argOp);
+
+ // Since the root op is not inserted into the ScopedHashMap, do not undo
+ // its previous insertion.
----------------
linuxlonelyeagle wrote:
> I don't quite see why the issue you're describing for the root op can't happen for other ops transitively dead?
To put it simply, other dead ops are exiting ops, while the root op is not.
https://github.com/llvm/llvm-project/pull/193778
More information about the Mlir-commits
mailing list