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

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 15 13:10:10 PST 2017


Author: pcc
Date: Wed Feb 15 15:10:09 2017
New Revision: 295236

URL: http://llvm.org/viewvc/llvm-project?rev=295236&view=rev
Log:
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

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

Modified: llvm/trunk/include/llvm/Analysis/AssumptionCache.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/AssumptionCache.h?rev=295236&r1=295235&r2=295236&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/AssumptionCache.h (original)
+++ llvm/trunk/include/llvm/Analysis/AssumptionCache.h Wed Feb 15 15:10:09 2017
@@ -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 {

Modified: llvm/trunk/lib/Analysis/AssumptionCache.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/AssumptionCache.cpp?rev=295236&r1=295235&r2=295236&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/AssumptionCache.cpp (original)
+++ llvm/trunk/lib/Analysis/AssumptionCache.cpp Wed Feb 15 15:10:09 2017
@@ -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,7 +236,13 @@ AssumptionCache &AssumptionCacheTracker:
 }
 
 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::verifyAnaly
 
     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) {

Modified: llvm/trunk/test/Transforms/SimplifyCFG/critedge-assume.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/critedge-assume.ll?rev=295236&r1=295235&r2=295236&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/critedge-assume.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/critedge-assume.ll Wed Feb 15 15:10:09 2017
@@ -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




More information about the llvm-commits mailing list