From: Peter Collingbourne Date: Wed, 15 Feb 2017 21:10:09 +0000 (+0000) Subject: AssumptionCache: Disable the verifier by default, move it behind a hidden cl::opt... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=103b5f7d01c3a40673d8f34c9402da644fd0c5ed;p=llvm AssumptionCache: Disable the verifier by default, move it behind a hidden cl::opt and verify from releaseMemory(). This is a short term solution to the problem that many passes currently fail to update the assumption cache. In the long term the verifier should not be controllable with a flag. We should either fix all passes to correctly update the assumption cache and enable the verifier unconditionally or somehow arrange for the assumption list to be updated automatically by passes. Differential Revision: https://reviews.llvm.org/D30003 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@295236 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/AssumptionCache.h b/include/llvm/Analysis/AssumptionCache.h index bd29292c4c6..f833f417c7d 100644 --- a/include/llvm/Analysis/AssumptionCache.h +++ b/include/llvm/Analysis/AssumptionCache.h @@ -202,7 +202,10 @@ public: AssumptionCacheTracker(); ~AssumptionCacheTracker() override; - void releaseMemory() override { AssumptionCaches.shrink_and_clear(); } + void releaseMemory() override { + verifyAnalysis(); + AssumptionCaches.shrink_and_clear(); + } void verifyAnalysis() const override; bool doFinalization(Module &) override { diff --git a/lib/Analysis/AssumptionCache.cpp b/lib/Analysis/AssumptionCache.cpp index 4e287e5f6bc..1fae9472448 100644 --- a/lib/Analysis/AssumptionCache.cpp +++ b/lib/Analysis/AssumptionCache.cpp @@ -24,6 +24,11 @@ using namespace llvm; using namespace llvm::PatternMatch; +static cl::opt + VerifyAssumptionCache("verify-assumption-cache", cl::Hidden, + cl::desc("Enable verification of assumption cache"), + cl::init(false)); + SmallVector &AssumptionCache::getOrInsertAffectedValues(Value *V) { // Try using find_as first to avoid creating extra value handles just for the // purpose of doing the lookup. @@ -231,7 +236,13 @@ AssumptionCache &AssumptionCacheTracker::getAssumptionCache(Function &F) { } void AssumptionCacheTracker::verifyAnalysis() const { -#ifndef NDEBUG + // FIXME: In the long term the verifier should not be controllable with a + // flag. We should either fix all passes to correctly update the assumption + // cache and enable the verifier unconditionally or somehow arrange for the + // assumption list to be updated automatically by passes. + if (!VerifyAssumptionCache) + return; + SmallPtrSet AssumptionSet; for (const auto &I : AssumptionCaches) { for (auto &VH : I.second->assumptions()) @@ -240,11 +251,10 @@ void AssumptionCacheTracker::verifyAnalysis() const { for (const BasicBlock &B : cast(*I.first)) for (const Instruction &II : B) - if (match(&II, m_Intrinsic())) - assert(AssumptionSet.count(cast(&II)) && - "Assumption in scanned function not in cache"); + if (match(&II, m_Intrinsic()) && + !AssumptionSet.count(cast(&II))) + report_fatal_error("Assumption in scanned function not in cache"); } -#endif } AssumptionCacheTracker::AssumptionCacheTracker() : ImmutablePass(ID) { diff --git a/test/Transforms/SimplifyCFG/critedge-assume.ll b/test/Transforms/SimplifyCFG/critedge-assume.ll index cba4a487d9e..db24685a37b 100644 --- a/test/Transforms/SimplifyCFG/critedge-assume.ll +++ b/test/Transforms/SimplifyCFG/critedge-assume.ll @@ -1,4 +1,4 @@ -; RUN: opt -o %t %s -instcombine -simplifycfg -thinlto-bc +; RUN: opt -o %t %s -instcombine -simplifycfg -thinlto-bc -verify-assumption-cache ; RUN: llvm-dis -o - %t | FileCheck %s ; Test that the simplifycfg pass correctly updates the assumption cache