[llvm] LoopVectorize: don't verify metadata (PR #91484)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Wed May 8 08:03:06 PDT 2024
https://github.com/artagnon created https://github.com/llvm/llvm-project/pull/91484
The Verifier is called anyway at the beginning and end of the pass pipeline, and some complex transformations like LoopVectorize call the Verifier anyway in order to report errors early. It can be argued that verifying metadata after vectorization is inessential, and not doing this can significantly improve compile-times on debug builds. With this patch, although the Verifier itself verifies metadata, change the calls to the Verifier in LoopVectorize to skip this check.
Fixes #47056.
>From c438a98603396ab77e61405ad406c49e77afb661 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <r at artagnon.com>
Date: Wed, 8 May 2024 15:48:04 +0100
Subject: [PATCH] LoopVectorize: don't verify metadata
The Verifier is called anyway at the beginning and end of the Pass
Pipeline, and some complex transformations like LoopVectorize call the
Verifier anyway in order to report errors early. It can be argued that
verifying metadata after vectorization is inessential, and not doing
this can significantly improve compile-times on debug builds. With this
patch, although the Verifier itself verifies metadata, change the calls
to the Verifier in LoopVectorize to skip this check.
Fixes #47056.
---
llvm/include/llvm/IR/Verifier.h | 5 ++--
llvm/lib/IR/Verifier.cpp | 28 ++++++++++++-------
.../Transforms/Vectorize/LoopVectorize.cpp | 6 ++--
3 files changed, 25 insertions(+), 14 deletions(-)
diff --git a/llvm/include/llvm/IR/Verifier.h b/llvm/include/llvm/IR/Verifier.h
index b25f8eb77ee38..a0a2285a9abf5 100644
--- a/llvm/include/llvm/IR/Verifier.h
+++ b/llvm/include/llvm/IR/Verifier.h
@@ -85,7 +85,8 @@ class TBAAVerifier {
/// If there are no errors, the function returns false. If an error is found,
/// a message describing the error is written to OS (if non-null) and true is
/// returned.
-bool verifyFunction(const Function &F, raw_ostream *OS = nullptr);
+bool verifyFunction(const Function &F, raw_ostream *OS = nullptr,
+ bool ShouldVerifyMD = true);
/// Check a module for errors.
///
@@ -98,7 +99,7 @@ bool verifyFunction(const Function &F, raw_ostream *OS = nullptr);
/// error and instead *BrokenDebugInfo will be set to true. Debug
/// info errors can be "recovered" from by stripping the debug info.
bool verifyModule(const Module &M, raw_ostream *OS = nullptr,
- bool *BrokenDebugInfo = nullptr);
+ bool *BrokenDebugInfo = nullptr, bool ShouldVerifyMD = true);
FunctionPass *createVerifierPass(bool FatalErrors = true);
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index aa8160d18edd4..5ff226e888f10 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -150,6 +150,8 @@ struct VerifierSupport {
bool BrokenDebugInfo = false;
/// Whether to treat broken debug info as an error.
bool TreatBrokenDebugInfoAsError = true;
+ /// Whether to verify metadata, which can be expensive in debug builds.
+ bool VerifyMD = true;
explicit VerifierSupport(raw_ostream *OS, const Module &M)
: OS(OS), M(M), MST(&M), TT(M.getTargetTriple()), DL(M.getDataLayout()),
@@ -399,10 +401,11 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
public:
explicit Verifier(raw_ostream *OS, bool ShouldTreatBrokenDebugInfoAsError,
- const Module &M)
+ bool ShouldVerifyMD, const Module &M)
: VerifierSupport(OS, M), LandingPadResultTy(nullptr),
SawFrameEscape(false), TBAAVerifyHelper(this) {
TreatBrokenDebugInfoAsError = ShouldTreatBrokenDebugInfoAsError;
+ VerifyMD = ShouldVerifyMD;
}
bool hasBrokenDebugInfo() const { return BrokenDebugInfo; }
@@ -478,8 +481,9 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
for (const GlobalIFunc &GI : M.ifuncs())
visitGlobalIFunc(GI);
- for (const NamedMDNode &NMD : M.named_metadata())
- visitNamedMDNode(NMD);
+ if (VerifyMD)
+ for (const NamedMDNode &NMD : M.named_metadata())
+ visitNamedMDNode(NMD);
for (const StringMapEntry<Comdat> &SMEC : M.getComdatSymbolTable())
visitComdat(SMEC.getValue());
@@ -7057,21 +7061,24 @@ void Verifier::verifyNoAliasScopeDecl() {
// Implement the public interfaces to this file...
//===----------------------------------------------------------------------===//
-bool llvm::verifyFunction(const Function &f, raw_ostream *OS) {
+bool llvm::verifyFunction(const Function &f, raw_ostream *OS,
+ bool ShouldVerifyMD) {
Function &F = const_cast<Function &>(f);
// Don't use a raw_null_ostream. Printing IR is expensive.
- Verifier V(OS, /*ShouldTreatBrokenDebugInfoAsError=*/true, *f.getParent());
+ Verifier V(OS, /*ShouldTreatBrokenDebugInfoAsError=*/true, ShouldVerifyMD,
+ *f.getParent());
// Note that this function's return value is inverted from what you would
// expect of a function called "verify".
return !V.verify(F);
}
-bool llvm::verifyModule(const Module &M, raw_ostream *OS,
- bool *BrokenDebugInfo) {
+bool llvm::verifyModule(const Module &M, raw_ostream *OS, bool *BrokenDebugInfo,
+ bool ShouldVerifyMD) {
// Don't use a raw_null_ostream. Printing IR is expensive.
- Verifier V(OS, /*ShouldTreatBrokenDebugInfoAsError=*/!BrokenDebugInfo, M);
+ Verifier V(OS, /*ShouldTreatBrokenDebugInfoAsError=*/!BrokenDebugInfo,
+ ShouldVerifyMD, M);
bool Broken = false;
for (const Function &F : M)
@@ -7103,8 +7110,9 @@ struct VerifierLegacyPass : public FunctionPass {
}
bool doInitialization(Module &M) override {
- V = std::make_unique<Verifier>(
- &dbgs(), /*ShouldTreatBrokenDebugInfoAsError=*/false, M);
+ V = std::make_unique<Verifier>(&dbgs(),
+ /*ShouldTreatBrokenDebugInfoAsError=*/false,
+ /*ShouldVerifyMD=*/true, M);
return false;
}
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 261933966b74b..901dcb90b736e 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -9677,7 +9677,8 @@ static bool processLoopInVPlanNativePath(
// Mark the loop as already vectorized to avoid vectorizing again.
Hints.setAlreadyVectorized();
- assert(!verifyFunction(*L->getHeader()->getParent(), &dbgs()));
+ assert(!verifyFunction(*L->getHeader()->getParent(), &dbgs(),
+ /* ShouldVerifyMD = */ false));
return true;
}
@@ -10286,7 +10287,8 @@ bool LoopVectorizePass::processLoop(Loop *L) {
Hints.setAlreadyVectorized();
}
- assert(!verifyFunction(*L->getHeader()->getParent(), &dbgs()));
+ assert(!verifyFunction(*L->getHeader()->getParent(), &dbgs(),
+ /* ShouldVerifyMD = */ false));
return true;
}
More information about the llvm-commits
mailing list