<div dir="ltr">Hi, Evgeniy, Alexey,<div><br></div><div>do you have an idea what might be going wrong here?</div><div><br></div><div>Cheers,<br>Daniel</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 30, 2015 at 11:33 AM, Daniel Jasper <span dir="ltr"><<a href="mailto:djasper@google.com" target="_blank">djasper@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">This makes builds under msan incredibly slow. The root cause seems to be the repeated recursion:<div><br></div><div>...</div><div><div>llvm::ScalarEvolution::getZeroExtendExpr(llvm::SCEV const*, llvm::Type*) ()</div><div>llvm::ScalarEvolution::isImpliedCond(llvm::CmpInst::Predicate, llvm::SCEV const*, llvm::SCEV const*, llvm::Value*, bool) ()</div><div>llvm::ScalarEvolution::isLoopBackedgeGuardedByCond(llvm::Loop const*, llvm::CmpInst::Predicate, llvm::SCEV const*, llvm::SCEV const*) ()</div></div><div><div>llvm::ScalarEvolution::getZeroExtendExpr(llvm::SCEV const*, llvm::Type*) ()</div><div>llvm::ScalarEvolution::isImpliedCond(llvm::CmpInst::Predicate, llvm::SCEV const*, llvm::SCEV const*, llvm::Value*, bool) ()</div><div>llvm::ScalarEvolution::isLoopBackedgeGuardedByCond(llvm::Loop const*, llvm::CmpInst::Predicate, llvm::SCEV const*, llvm::SCEV const*) ()</div></div><div>...</div><div><br></div><div>I don't understand enough about this or about MSAN to know whether it is only slow under MSAN or whether MSAN somehow triggers a corner case. I for now revert this in r233528 until we can properly investigate.</div><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 28, 2015 at 12:18 AM, Sanjoy Das <span dir="ltr"><<a href="mailto:sanjoy@playingwithpointers.com" target="_blank">sanjoy@playingwithpointers.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: sanjoy<br>
Date: Fri Mar 27 18:18:08 2015<br>
New Revision: 233447<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=233447&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=233447&view=rev</a><br>
Log:<br>
[SCEV] Look at backedge dominating conditions.<br>
<br>
Summary:<br>
This change teaches ScalarEvolution::isLoopBackedgeGuardedByCond to look<br>
at edges within the loop body that dominate the latch.  We don't do an<br>
exhaustive search for all possible edges, but only a quick walk up the<br>
dom tree.<br>
<br>
Reviewers: atrick, hfinkel<br>
<br>
Subscribers: llvm-commits<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D8627" target="_blank">http://reviews.llvm.org/D8627</a><br>
<br>
Added:<br>
    llvm/trunk/test/Analysis/ScalarEvolution/latch-dominating-conditions.ll<br>
Modified:<br>
    llvm/trunk/lib/Analysis/ScalarEvolution.cpp<br>
<br>
Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=233447&r1=233446&r2=233447&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=233447&r1=233446&r2=233447&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)<br>
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Fri Mar 27 18:18:08 2015<br>
@@ -6686,6 +6686,46 @@ ScalarEvolution::isLoopBackedgeGuardedBy<br>
                     LoopContinuePredicate->getSuccessor(0) != L->getHeader()))<br>
     return true;<br>
<br>
+  // If the loop is not reachable from the entry block, we risk running into an<br>
+  // infinite loop as we walk up into the dom tree.  These loops do not matter<br>
+  // anyway, so we just return a conservative answer when we see them.<br>
+  if (!DT->isReachableFromEntry(L->getHeader()))<br>
+    return false;<br>
+<br>
+  for (DomTreeNode *DTN = (*DT)[Latch], *HeaderDTN = (*DT)[L->getHeader()];<br>
+       DTN != HeaderDTN;<br>
+       DTN = DTN->getIDom()) {<br>
+<br>
+    assert(DTN && "should reach the loop header before reaching the root!");<br>
+<br>
+    BasicBlock *BB = DTN->getBlock();<br>
+    BasicBlock *PBB = BB->getSinglePredecessor();<br>
+    if (!PBB)<br>
+      continue;<br>
+<br>
+    BranchInst *ContinuePredicate = dyn_cast<BranchInst>(PBB->getTerminator());<br>
+    if (!ContinuePredicate || !ContinuePredicate->isConditional())<br>
+      continue;<br>
+<br>
+    Value *Condition = ContinuePredicate->getCondition();<br>
+<br>
+    // If we have an edge `E` within the loop body that dominates the only<br>
+    // latch, the condition guarding `E` also guards the backedge.  This<br>
+    // reasoning works only for loops with a single latch.<br>
+<br>
+    BasicBlockEdge DominatingEdge(PBB, BB);<br>
+    if (DominatingEdge.isSingleEdge()) {<br>
+      // We're constructively (and conservatively) enumerating edges within the<br>
+      // loop body that dominate the latch.  The dominator tree better agree<br>
+      // with us on this:<br>
+      assert(DT->dominates(DominatingEdge, Latch) && "should be!");<br>
+<br>
+      if (isImpliedCond(Pred, LHS, RHS, Condition,<br>
+                        BB != ContinuePredicate->getSuccessor(0)))<br>
+        return true;<br>
+    }<br>
+  }<br>
+<br>
   // Check conditions due to any @llvm.assume intrinsics.<br>
   for (auto &AssumeVH : AC->assumptions()) {<br>
     if (!AssumeVH)<br>
<br>
Added: llvm/trunk/test/Analysis/ScalarEvolution/latch-dominating-conditions.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ScalarEvolution/latch-dominating-conditions.ll?rev=233447&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ScalarEvolution/latch-dominating-conditions.ll?rev=233447&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/Analysis/ScalarEvolution/latch-dominating-conditions.ll (added)<br>
+++ llvm/trunk/test/Analysis/ScalarEvolution/latch-dominating-conditions.ll Fri Mar 27 18:18:08 2015<br>
@@ -0,0 +1,55 @@<br>
+; RUN: opt -S -indvars < %s | FileCheck %s<br>
+<br>
+declare void @side_effect(i1)<br>
+<br>
+define void @latch_dominating_0(i8 %start) {<br>
+; CHECK-LABEL: latch_dominating_0<br>
+ entry:<br>
+  %e = icmp slt i8 %start, 42<br>
+  br i1 %e, label %loop, label %exit<br>
+<br>
+ loop:<br>
+; CHECK-LABEL: loop<br>
+  %idx = phi i8 [ %start, %entry ], [ %idx.inc, %be ]<br>
+  %idx.inc = add i8 %idx, 1<br>
+  %folds.to.true = icmp slt i8 %idx, 42<br>
+; CHECK: call void @side_effect(i1 true)<br>
+  call void @side_effect(i1 %folds.to.true)<br>
+  %c0 = icmp slt i8 %idx.inc, 42<br>
+  br i1 %c0, label %be, label %exit<br>
+<br>
+ be:<br>
+; CHECK: call void @side_effect(i1 true)<br>
+  call void @side_effect(i1 %folds.to.true)<br>
+  %c1 = icmp slt i8 %idx.inc, 100<br>
+  br i1 %c1, label %loop, label %exit<br>
+<br>
+ exit:<br>
+  ret void<br>
+}<br>
+<br>
+define void @latch_dominating_1(i8 %start) {<br>
+; CHECK-LABEL: latch_dominating_1<br>
+ entry:<br>
+  %e = icmp slt i8 %start, 42<br>
+  br i1 %e, label %loop, label %exit<br>
+<br>
+ loop:<br>
+; CHECK-LABEL: loop<br>
+  %idx = phi i8 [ %start, %entry ], [ %idx.inc, %be ]<br>
+  %idx.inc = add i8 %idx, 1<br>
+  %does.not.fold.to.true = icmp slt i8 %idx, 42<br>
+; CHECK: call void @side_effect(i1 %does.not.fold.to.true)<br>
+  call void @side_effect(i1 %does.not.fold.to.true)<br>
+  %c0 = icmp slt i8 %idx.inc, 42<br>
+  br i1 %c0, label %be, label %be<br>
+<br>
+ be:<br>
+; CHECK: call void @side_effect(i1 %does.not.fold.to.true)<br>
+  call void @side_effect(i1 %does.not.fold.to.true)<br>
+  %c1 = icmp slt i8 %idx.inc, 100<br>
+  br i1 %c1, label %loop, label %exit<br>
+<br>
+ exit:<br>
+  ret void<br>
+}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>