[Mlir-commits] [mlir] [mlir][reducer] make opt-reduction pass clone topOp after check (NFC) (PR #189356)

lonely eagle llvmlistbot at llvm.org
Mon Mar 30 04:04:43 PDT 2026


https://github.com/linuxlonelyeagle created https://github.com/llvm/llvm-project/pull/189356

To avoid potential memory leaks, this PR defers the ModuleOp cloning until after the verification check. If the check fails, the moduleVariant might not be properly deallocated(original implementation), leading to a memory leak. Therefore, this PR ensures that the clone operation is only performed after a successful check

>From 2c026a07d6c901395d068cbc12244c5bb25b43e5 Mon Sep 17 00:00:00 2001
From: linuxlonelyeagle <2020382038 at qq.com>
Date: Mon, 30 Mar 2026 10:59:23 +0000
Subject: [PATCH] make opt-reduction pass clone topOp after check.

---
 mlir/lib/Reducer/OptReductionPass.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/mlir/lib/Reducer/OptReductionPass.cpp b/mlir/lib/Reducer/OptReductionPass.cpp
index 4bdc7b17567d9..feb28e1b9beb8 100644
--- a/mlir/lib/Reducer/OptReductionPass.cpp
+++ b/mlir/lib/Reducer/OptReductionPass.cpp
@@ -47,8 +47,6 @@ void OptReductionPass::runOnOperation() {
   Tester test(testerName, testerArgs);
 
   ModuleOp module = this->getOperation();
-  ModuleOp moduleVariant = module.clone();
-
   OpPassManager passManager("builtin.module");
   if (failed(parsePassPipeline(optPass, passManager))) {
     module.emitError() << "\nfailed to parse pass pipeline";
@@ -60,7 +58,7 @@ void OptReductionPass::runOnOperation() {
     module.emitError() << "\nthe original input is not interested";
     return signalPassFailure();
   }
-
+  ModuleOp moduleVariant = module.clone();
   // Temporarily push the variant under the main module and execute the pipeline
   // on it.
   module.getBody()->push_back(moduleVariant);



More information about the Mlir-commits mailing list