]> granicus.if.org Git - llvm/commitdiff
AssumptionCache: Disable the verifier by default, move it behind a hidden cl::opt...
authorPeter Collingbourne <peter@pcc.me.uk>
Wed, 15 Feb 2017 21:10:09 +0000 (21:10 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Wed, 15 Feb 2017 21:10:09 +0000 (21:10 +0000)
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

include/llvm/Analysis/AssumptionCache.h
lib/Analysis/AssumptionCache.cpp
test/Transforms/SimplifyCFG/critedge-assume.ll

index bd29292c4c66a8cedbd5288267874128c0fb2043..f833f417c7dd2e6e9ad473a316c6932fe56ceda6 100644 (file)
@@ -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 {
index 4e287e5f6bc11a987d5a72d52b56629ce2703307..1fae947244878daed5da51cf799f2144c2d601df 100644 (file)
 using namespace llvm;
 using namespace llvm::PatternMatch;
 
+static cl::opt<bool>
+    VerifyAssumptionCache("verify-assumption-cache", cl::Hidden,
+                          cl::desc("Enable verification of assumption cache"),
+                          cl::init(false));
+
 SmallVector<WeakVH, 1> &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<const CallInst *, 4> 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<Function>(*I.first))
       for (const Instruction &II : B)
-        if (match(&II, m_Intrinsic<Intrinsic::assume>()))
-          assert(AssumptionSet.count(cast<CallInst>(&II)) &&
-                 "Assumption in scanned function not in cache");
+        if (match(&II, m_Intrinsic<Intrinsic::assume>()) &&
+            !AssumptionSet.count(cast<CallInst>(&II)))
+          report_fatal_error("Assumption in scanned function not in cache");
   }
-#endif
 }
 
 AssumptionCacheTracker::AssumptionCacheTracker() : ImmutablePass(ID) {
index cba4a487d9ee8e3052f20487e560ca86ab7c50e9..db24685a37bee9e45c5df70c15a8289e176fe3a2 100644 (file)
@@ -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