svn commit: r309722 - head/contrib/llvm/lib/Analysis

Dimitry Andric dim at FreeBSD.org
Thu Dec 8 21:02:35 UTC 2016


Author: dim
Date: Thu Dec  8 21:02:34 2016
New Revision: 309722
URL: https://svnweb.freebsd.org/changeset/base/309722

Log:
  Pull in r281586 from upstream llvm trunk (by Wei Mi):
  
    Add some shortcuts in LazyValueInfo to reduce compile time of
    Correlated Value Propagation.
  
    The patch is to partially fix PR10584. Correlated Value Propagation
    queries LVI to check non-null for pointer params of each callsite. If
    we know the def of param is an alloca instruction, we know it is
    non-null and can return early from LVI. Similarly, CVP queries LVI to
    check whether pointer for each mem access is constant. If the def of
    the pointer is an alloca instruction, we know it is not a constant
    pointer. These shortcuts can reduce the cost of CVP significantly.
  
    Differential Revision: https://reviews.llvm.org/D18066
  
  This significantly reduces memory usage and compilation time when
  compiling a particular C++ source file of the graphics/colmap port.
  
  PR:		215136
  MFC after:	3 days

Modified:
  head/contrib/llvm/lib/Analysis/LazyValueInfo.cpp

Modified: head/contrib/llvm/lib/Analysis/LazyValueInfo.cpp
==============================================================================
--- head/contrib/llvm/lib/Analysis/LazyValueInfo.cpp	Thu Dec  8 20:54:54 2016	(r309721)
+++ head/contrib/llvm/lib/Analysis/LazyValueInfo.cpp	Thu Dec  8 21:02:34 2016	(r309722)
@@ -1479,8 +1479,27 @@ LazyValueInfo LazyValueAnalysis::run(Fun
   return LazyValueInfo(&AC, &TLI, DT);
 }
 
+ 
+/// Returns true if we can statically tell that this value will never be a
+/// "useful" constant.  In practice, this means we've got something like an
+/// alloca or a malloc call for which a comparison against a constant can
+/// only be guarding dead code.  Note that we are potentially giving up some
+/// precision in dead code (a constant result) in favour of avoiding a
+/// expensive search for a easily answered common query.
+static bool isKnownNonConstant(Value *V) {
+  V = V->stripPointerCasts();
+  // The return val of alloc cannot be a Constant.
+  if (isa<AllocaInst>(V))
+    return true;
+  return false;
+}
+
 Constant *LazyValueInfo::getConstant(Value *V, BasicBlock *BB,
                                      Instruction *CxtI) {
+  // Bail out early if V is known not to be a Constant.
+  if (isKnownNonConstant(V))
+    return nullptr;
+
   const DataLayout &DL = BB->getModule()->getDataLayout();
   LVILatticeVal Result =
       getCache(PImpl, AC, &DL, DT).getValueInBlock(V, BB, CxtI);
@@ -1613,6 +1632,17 @@ LazyValueInfo::getPredicateOnEdge(unsign
 LazyValueInfo::Tristate
 LazyValueInfo::getPredicateAt(unsigned Pred, Value *V, Constant *C,
                               Instruction *CxtI) {
+  // Is or is not NonNull are common predicates being queried. If
+  // isKnownNonNull can tell us the result of the predicate, we can
+  // return it quickly. But this is only a fastpath, and falling
+  // through would still be correct.
+  if (V->getType()->isPointerTy() && C->isNullValue() &&
+      isKnownNonNull(V->stripPointerCasts())) {
+    if (Pred == ICmpInst::ICMP_EQ)
+      return LazyValueInfo::False;
+    else if (Pred == ICmpInst::ICMP_NE)
+      return LazyValueInfo::True;
+  }
   const DataLayout &DL = CxtI->getModule()->getDataLayout();
   LVILatticeVal Result = getCache(PImpl, AC, &DL, DT).getValueAt(V, CxtI);
   Tristate Ret = getPredicateResult(Pred, C, Result, DL, TLI);


More information about the svn-src-head mailing list