[PATCH] D30003: AssumptionCache: Disable the verifier by default, move it behind a hidden cl::opt and verify from releaseMemory().

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 15 12:04:47 PST 2017


pcc updated this revision to Diff 88587.
pcc added a comment.

- Tweaks


https://reviews.llvm.org/D30003

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


Index: llvm/test/Transforms/SimplifyCFG/critedge-assume.ll
===================================================================
--- llvm/test/Transforms/SimplifyCFG/critedge-assume.ll
+++ llvm/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
Index: llvm/lib/Analysis/AssumptionCache.cpp
===================================================================
--- llvm/lib/Analysis/AssumptionCache.cpp
+++ llvm/lib/Analysis/AssumptionCache.cpp
@@ -24,6 +24,11 @@
 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,20 +236,25 @@
 }
 
 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())
       if (VH)
         AssumptionSet.insert(cast<CallInst>(VH));
 
     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: llvm/include/llvm/Analysis/AssumptionCache.h
===================================================================
--- llvm/include/llvm/Analysis/AssumptionCache.h
+++ llvm/include/llvm/Analysis/AssumptionCache.h
@@ -203,7 +203,10 @@
   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 {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30003.88587.patch
Type: text/x-patch
Size: 2995 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170215/70a85364/attachment.bin>


More information about the llvm-commits mailing list