<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 22, 2016, at 4:54 PM, Michael Zolotukhin via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="Apple-interchange-newline">On Jun 22, 2016, at 1:25 AM, Mikael Holmén <<a href="mailto:mikael.holmen@ericsson.com" class="">mikael.holmen@ericsson.com</a>> wrote:<br class=""><br class="">Hi Michael,<br class=""><br class="">The checks introduced in this commit fail on:<br class=""><br class="">opt -S -lcssa -loop-unroll red.ll<br class=""><br class="">I don't know if it's the checks or the optimization that is actually wrong.<br class=""></blockquote><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Hi Mikael,</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">The checks are correct, they just exposed a bug that has been there for a long time. It seems that a routine separateNestedLoop in LoopSimplify breaks LCSSA - the test you provided shows exactly that. I’ll look into how we can fix it. Does it block you in any way?</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div>Hi Mikael,</div><div><br class=""></div>I filed <a href="https://llvm.org/bugs/show_bug.cgi?id=28272" class="">PR28272</a> to track this.</div><div><br class=""></div><div>Michael<br class=""><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Michael</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="">Regards,<br class="">Mikael<br class=""><br class="">On 06/09/2016 01:13 AM, Michael Zolotukhin via llvm-commits wrote:<br class=""><blockquote type="cite" class="">Author: mzolotukhin<br class="">Date: Wed Jun  8 18:13:21 2016<br class="">New Revision: 272224<br class=""><br class="">URL: <a href="http://llvm.org/viewvc/llvm-project?rev=272224&view=rev" class="">http://llvm.org/viewvc/llvm-project?rev=272224&view=rev</a><br class="">Log:<br class="">[LoopSimplify] Preserve LCSSA when merging exit blocks.<br class=""><br class="">Summary:<br class="">This fixes PR26682. Also add LCSSA as a preserved pass to LoopSimplify,<br class="">that looks correct to me and allows to write a test for the issue.<br class=""><br class="">Reviewers: chandlerc, bogner, sanjoy<br class=""><br class="">Subscribers: llvm-commits<br class=""><br class="">Differential Revision: <a href="http://reviews.llvm.org/D21112" class="">http://reviews.llvm.org/D21112</a><br class=""><br class="">Added:<br class="">   llvm/trunk/test/Transforms/LoopSimplify/pr26682.ll<br class="">Modified:<br class="">   llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp<br class=""><br class="">Modified: llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp?rev=272224&r1=272223&r2=272224&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp?rev=272224&r1=272223&r2=272224&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp (original)<br class="">+++ llvm/trunk/lib/Transforms/Utils/LoopSimplify.cpp Wed Jun  8 18:13:21 2016<br class="">@@ -686,8 +686,10 @@ ReprocessLoop:<br class="">      }<br class="">      DT->eraseNode(ExitingBlock);<br class=""><br class="">-      BI->getSuccessor(0)->removePredecessor(ExitingBlock);<br class="">-      BI->getSuccessor(1)->removePredecessor(ExitingBlock);<br class="">+      BI->getSuccessor(0)->removePredecessor(<br class="">+          ExitingBlock, /* DontDeleteUselessPHIs */ PreserveLCSSA);<br class="">+      BI->getSuccessor(1)->removePredecessor(<br class="">+          ExitingBlock, /* DontDeleteUselessPHIs */ PreserveLCSSA);<br class="">      ExitingBlock->eraseFromParent();<br class="">    }<br class="">  }<br class="">@@ -748,6 +750,7 @@ namespace {<br class="">      AU.addPreserved<GlobalsAAWrapperPass>();<br class="">      AU.addPreserved<ScalarEvolutionWrapperPass>();<br class="">      AU.addPreserved<SCEVAAWrapperPass>();<br class="">+      AU.addPreservedID(LCSSAID);<br class="">      AU.addPreserved<DependenceAnalysisWrapperPass>();<br class="">      AU.addPreservedID(BreakCriticalEdgesID);  // No critical edges added.<br class="">    }<br class="">@@ -781,11 +784,27 @@ bool LoopSimplify::runOnFunction(Functio<br class="">  SE = SEWP ? &SEWP->getSE() : nullptr;<br class="">  AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);<br class="">  bool PreserveLCSSA = mustPreserveAnalysisID(LCSSAID);<br class="">+#ifndef NDEBUG<br class="">+  if (PreserveLCSSA) {<br class="">+    assert(DT && "DT not available.");<br class="">+    assert(LI && "LI not available.");<br class="">+    bool InLCSSA =<br class="">+        all_of(*LI, [&](Loop *L) { return L->isRecursivelyLCSSAForm(*DT); });<br class="">+    assert(InLCSSA && "Requested to preserve LCSSA, but it's already broken.");<br class="">+  }<br class="">+#endif<br class=""><br class="">  // Simplify each loop nest in the function.<br class="">  for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I)<br class="">    Changed |= simplifyLoop(*I, DT, LI, SE, AC, PreserveLCSSA);<br class=""><br class="">+#ifndef NDEBUG<br class="">+  if (PreserveLCSSA) {<br class="">+    bool InLCSSA =<br class="">+        all_of(*LI, [&](Loop *L) { return L->isRecursivelyLCSSAForm(*DT); });<br class="">+    assert(InLCSSA && "LCSSA is broken after loop-simplify.");<br class="">+  }<br class="">+#endif<br class="">  return Changed;<br class="">}<br class=""><br class=""><br class="">Added: llvm/trunk/test/Transforms/LoopSimplify/pr26682.ll<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopSimplify/pr26682.ll?rev=272224&view=auto" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopSimplify/pr26682.ll?rev=272224&view=auto</a><br class="">==============================================================================<br class="">--- llvm/trunk/test/Transforms/LoopSimplify/pr26682.ll (added)<br class="">+++ llvm/trunk/test/Transforms/LoopSimplify/pr26682.ll Wed Jun  8 18:13:21 2016<br class="">@@ -0,0 +1,32 @@<br class="">+; RUN: opt < %s -lcssa -loop-simplify -indvars -S | FileCheck %s<br class="">+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"<br class="">+target triple = "x86_64-unknown-unknown"<br class="">+<br class="">+@a = external global i32, align 4<br class="">+<br class="">+; Check that loop-simplify merges two loop exits, but preserves LCSSA form.<br class="">+; CHECK-LABEL: @foo<br class="">+; CHECK: for:<br class="">+; CHECK: %or.cond = and i1 %cmp1, %cmp2<br class="">+; CHECK-NOT: for.cond:<br class="">+; CHECK: for.end:<br class="">+; CHECK: %a.lcssa = phi i32 [ %a, %for ]<br class="">+define i32 @foo(i32 %x) {<br class="">+entry:<br class="">+  br label %for<br class="">+<br class="">+for:<br class="">+  %iv = phi i32 [ 0, %entry ], [ %iv.next, %for.cond ]<br class="">+  %cmp1 = icmp eq i32 %x, 0<br class="">+  %iv.next = add nuw nsw i32 %iv, 1<br class="">+  %a = load i32, i32* @a<br class="">+  br i1 %cmp1, label %for.cond, label %for.end<br class="">+<br class="">+for.cond:<br class="">+  %cmp2 = icmp slt i32 %iv.next, 4<br class="">+  br i1 %cmp2, label %for, label %for.end<br class="">+<br class="">+for.end:<br class="">+  %a.lcssa = phi i32 [ %a, %for ], [ %a, %for.cond ]<br class="">+  ret i32 %a.lcssa<br class="">+}<br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits<br class=""><br class=""></blockquote><red.ll><br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">llvm-commits mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:llvm-commits@lists.llvm.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">llvm-commits@lists.llvm.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a></div></blockquote></div><br class=""></body></html>