Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Jul 2017 20:13:25 +0000 (UTC)
From:      Dimitry Andric <dim@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r321664 - in head/contrib/llvm/lib: CodeGen Target/X86
Message-ID:  <201707282013.v6SKDPpg051279@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dim
Date: Fri Jul 28 20:13:25 2017
New Revision: 321664
URL: https://svnweb.freebsd.org/changeset/base/321664

Log:
  Pull in r308891 from upstream llvm trunk (by Benjamin Kramer):
  
    [CodeGenPrepare] Cut off FindAllMemoryUses if there are too many uses.
  
    This avoids excessive compile time. The case I'm looking at is
    Function.cpp from an old version of LLVM that still had the giant
    memcmp string matcher in it. Before r308322 this compiled in about 2
    minutes, after it, clang takes infinite* time to compile it. With
    this patch we're at 5 min, which is still bad but this is a
    pathological case.
  
    The cut off at 20 uses was chosen by looking at other cut-offs in LLVM
    for user scanning. It's probably too high, but does the job and is
    very unlikely to regress anything.
  
    Fixes PR33900.
  
    * I'm impatient and aborted after 15 minutes, on the bug report it was
      killed after 2h.
  
  Pull in r308986 from upstream llvm trunk (by Simon Pilgrim):
  
    [X86][CGP] Reduce memcmp() expansion to 2 load pairs (PR33914)
  
    D35067/rL308322 attempted to support up to 4 load pairs for memcmp
    inlining which resulted in regressions for some optimized libc memcmp
    implementations (PR33914).
  
    Until we can match these more optimal cases, this patch reduces the
    memcmp expansion to a maximum of 2 load pairs (which matches what we
    do for -Os).
  
    This patch should be considered for the 5.0.0 release branch as well
  
    Differential Revision: https://reviews.llvm.org/D35830
  
  These fix a hang (or extremely long compile time) when building older
  LLVM ports.
  
  Reported by:    antoine
  PR:             219139

Modified:
  head/contrib/llvm/lib/CodeGen/CodeGenPrepare.cpp
  head/contrib/llvm/lib/Target/X86/X86ISelLowering.cpp

Modified: head/contrib/llvm/lib/CodeGen/CodeGenPrepare.cpp
==============================================================================
--- head/contrib/llvm/lib/CodeGen/CodeGenPrepare.cpp	Fri Jul 28 19:10:34 2017	(r321663)
+++ head/contrib/llvm/lib/CodeGen/CodeGenPrepare.cpp	Fri Jul 28 20:13:25 2017	(r321664)
@@ -4016,14 +4016,18 @@ static bool IsOperandAMemoryOperand(CallInst *CI, Inli
   return true;
 }
 
+// Max number of memory uses to look at before aborting the search to conserve
+// compile time.
+static constexpr int MaxMemoryUsesToScan = 20;
+
 /// Recursively walk all the uses of I until we find a memory use.
 /// If we find an obviously non-foldable instruction, return true.
 /// Add the ultimately found memory instructions to MemoryUses.
 static bool FindAllMemoryUses(
     Instruction *I,
     SmallVectorImpl<std::pair<Instruction *, unsigned>> &MemoryUses,
-    SmallPtrSetImpl<Instruction *> &ConsideredInsts,
-    const TargetLowering &TLI, const TargetRegisterInfo &TRI) {
+    SmallPtrSetImpl<Instruction *> &ConsideredInsts, const TargetLowering &TLI,
+    const TargetRegisterInfo &TRI, int SeenInsts = 0) {
   // If we already considered this instruction, we're done.
   if (!ConsideredInsts.insert(I).second)
     return false;
@@ -4036,8 +4040,12 @@ static bool FindAllMemoryUses(
 
   // Loop over all the uses, recursively processing them.
   for (Use &U : I->uses()) {
-    Instruction *UserI = cast<Instruction>(U.getUser());
+    // Conservatively return true if we're seeing a large number or a deep chain
+    // of users. This avoids excessive compilation times in pathological cases.
+    if (SeenInsts++ >= MaxMemoryUsesToScan)
+      return true;
 
+    Instruction *UserI = cast<Instruction>(U.getUser());
     if (LoadInst *LI = dyn_cast<LoadInst>(UserI)) {
       MemoryUses.push_back(std::make_pair(LI, U.getOperandNo()));
       continue;
@@ -4082,7 +4090,8 @@ static bool FindAllMemoryUses(
       continue;
     }
 
-    if (FindAllMemoryUses(UserI, MemoryUses, ConsideredInsts, TLI, TRI))
+    if (FindAllMemoryUses(UserI, MemoryUses, ConsideredInsts, TLI, TRI,
+                          SeenInsts))
       return true;
   }
 

Modified: head/contrib/llvm/lib/Target/X86/X86ISelLowering.cpp
==============================================================================
--- head/contrib/llvm/lib/Target/X86/X86ISelLowering.cpp	Fri Jul 28 19:10:34 2017	(r321663)
+++ head/contrib/llvm/lib/Target/X86/X86ISelLowering.cpp	Fri Jul 28 20:13:25 2017	(r321664)
@@ -1672,8 +1672,8 @@ X86TargetLowering::X86TargetLowering(const X86TargetMa
 
   // TODO: These control memcmp expansion in CGP and could be raised higher, but
   // that needs to benchmarked and balanced with the potential use of vector
-  // load/store types (PR33329).
-  MaxLoadsPerMemcmp = 4;
+  // load/store types (PR33329, PR33914).
+  MaxLoadsPerMemcmp = 2;
   MaxLoadsPerMemcmpOptSize = 2;
 
   // Set loop alignment to 2^ExperimentalPrefLoopAlignment bytes (default: 2^4).



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201707282013.v6SKDPpg051279>