Index: lib/Analysis/LazyValueInfo.cpp =================================================================== --- lib/Analysis/LazyValueInfo.cpp +++ lib/Analysis/LazyValueInfo.cpp @@ -27,6 +27,7 @@ #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/PatternMatch.h" #include "llvm/IR/ValueHandle.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetLibraryInfo.h" @@ -37,6 +38,12 @@ #define DEBUG_TYPE "lazy-value-info" +// This threshold is purticularly tuned with some special cases exposing +// regression of compile time and memory consumption. +static cl::opt +OverdefinedThreshold("lvi-overdefined-threshold", cl::init(1500), cl::Hidden, + cl::desc("Threshold of lowering lattice value 'overdefined'.")); + char LazyValueInfo::ID = 0; INITIALIZE_PASS_BEGIN(LazyValueInfo, "lazy-value-info", "Lazy Value Information Analysis", false, true) @@ -348,6 +355,9 @@ const DataLayout *DL; /// An optional DT pointer. DominatorTree *DT; + /// A counter to record how many times Overdefined has been tried to be + /// lowered. + unsigned LoweringOverdefinedTimes; friend struct LVIValueHandle; @@ -480,6 +490,7 @@ } void LazyValueInfoCache::solve() { + LoweringOverdefinedTimes = 0; while (!BlockValueStack.empty()) { std::pair &e = BlockValueStack.top(); if (solveBlockValue(e.second, e.first)) { @@ -539,8 +550,14 @@ // BB2. So we should have to follow data flow propagation algorithm to get the // value on edge BB1->BB2 propagated to BB2, and finally %v on BB2 has a // constant range describing a negative value. + // + // However, this further computing could increase both time and space + // complexity. Therefore, we introduce OverdefinedThreshold to control + // the maximum times of further lowering lattice value 'overdefined'. - if (!BBLV.isUndefined() && !BBLV.isOverdefined()) { + if ((!BBLV.isUndefined() && !BBLV.isOverdefined()) || + (BBLV.isOverdefined() && + (LoweringOverdefinedTimes > OverdefinedThreshold))) { DEBUG(dbgs() << " reuse BB '" << BB->getName() << "' val=" << BBLV <<'\n'); // Since we're reusing a cached value here, we don't need to update the @@ -554,6 +571,7 @@ // lattice value to overdefined, so that cycles will terminate and be // conservatively correct. BBLV.markOverdefined(); + LoweringOverdefinedTimes++; Instruction *BBI = dyn_cast(Val); if (!BBI || BBI->getParent() != BB) {