diff --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp --- a/mlir/lib/Pass/Pass.cpp +++ b/mlir/lib/Pass/Pass.cpp @@ -387,9 +387,28 @@ // Invalidate any non preserved analyses. am.invalidate(pass->passState->preservedAnalyses); + // When verifyPasses is specified, we run the verifier (unless the pass + // failed). + // + // Run the verifier if this pass didn't fail already. - if (!passFailed && verifyPasses) - passFailed = failed(verify(op)); + if (!passFailed && verifyPasses) { + bool runVerifierNow = true; + // If the pass said that it preserved all analyses then it can't have + // permuted the IR, and we don't want to burn compile time running the + // verifier. Similarly, if we just ran an OpToOpPassAdaptor (e.g. to run + // function passes within a module) then each subunit will have been + // verified on the subunit so there is little benefit in rerunning the + // verifier on the whole larger unit again. + // + // We run these checks in EXPENSIVE_CHECKS mode out of caution. +#ifndef EXPENSIVE_CHECKS + runVerifierNow = !isa(pass) && + !pass->passState->preservedAnalyses.isAll(); +#endif + if (runVerifierNow) + passFailed = failed(verify(op)); + } // Instrument after the pass has run. if (pi) {