[llvm-branch-commits] [mlir] [mlir] MlirOptMain: avoid double verification (PR #192661)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Apr 17 07:07:48 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-core

Author: Oleksandr "Alex" Zinenko (ftynse)

<details>
<summary>Changes</summary>

MlirOptMain would run verification twice at the end of the processing:
  1. after the last pass in the pipeline;
  2. prior to printing. Since there is no logic that could mutate, and thus potentially invalidate, the IR between the two, the second verification is redundant. Skip it when possible.

---
Full diff: https://github.com/llvm/llvm-project/pull/192661.diff


2 Files Affected:

- (modified) mlir/lib/Tools/mlir-opt/MlirOptMain.cpp (+7-2) 
- (modified) mlir/test/Dialect/Transform/normal-forms.mlir (+1-3) 


``````````diff
diff --git a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
index f90abda3463ab..56d2eb0f80185 100644
--- a/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
+++ b/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp
@@ -621,8 +621,13 @@ performActions(raw_ostream &os,
   if (config.bytecodeVersionToEmit().has_value())
     return emitError(UnknownLoc::get(pm.getContext()))
            << "bytecode version while not emitting bytecode";
-  AsmState asmState(op.get(), OpPrintingFlags(), /*locationMap=*/nullptr,
-                    &fallbackResourceMap);
+
+  // Don't re-run the verifier if we already ran the verifier at the end of the
+  // pass pipeline.
+  AsmState asmState(op.get(),
+                    OpPrintingFlags().assumeVerified(
+                        config.shouldVerifyPasses() && !pm.empty()),
+                    /*locationMap=*/nullptr, &fallbackResourceMap);
   os << OpWithState(op.get(), asmState) << '\n';
 
   // This is required if the remark policy is final. Otherwise, the remarks are
diff --git a/mlir/test/Dialect/Transform/normal-forms.mlir b/mlir/test/Dialect/Transform/normal-forms.mlir
index e66670e54bc23..0a51a23459310 100644
--- a/mlir/test/Dialect/Transform/normal-forms.mlir
+++ b/mlir/test/Dialect/Transform/normal-forms.mlir
@@ -141,13 +141,11 @@ transform.payload attributes {
 //  1. after the initial parsing (reasonable)
 //  2. also in transform::detail::mergeSymbolsInto (has a TODO to be removed)
 //  3. after the transform interpreter pass (reasonable)
-//  4. before printing (generally reasonable, but would be nice to avoid if
-//     the IR is known-verified after by the pass manager).
 // Notably this doesn't include an extra run from checkPayload, which is
 // what we intend to test here.
 
 // CHECK: transform.payload
-// CHECK-SAME: test.counting_normal_form_count = 4 : i64
+// CHECK: test.counting_normal_form_count = 3
 
 module attributes {transform.with_named_sequence} {
   transform.payload attributes {

``````````

</details>


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


More information about the llvm-branch-commits mailing list