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

Oleksandr Alex Zinenko via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Apr 17 06:55:56 PDT 2026


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

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.

>From e7e01e151eea546d8ba20d4c8b5a1a1f5bba0ba8 Mon Sep 17 00:00:00 2001
From: Alex Zinenko <git at ozinenko.com>
Date: Fri, 17 Apr 2026 15:50:57 +0200
Subject: [PATCH] [mlir] MlirOptMain: avoid double verification

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.
---
 mlir/lib/Tools/mlir-opt/MlirOptMain.cpp       | 9 +++++++--
 mlir/test/Dialect/Transform/normal-forms.mlir | 4 +---
 2 files changed, 8 insertions(+), 5 deletions(-)

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 {



More information about the llvm-branch-commits mailing list