<div dir="ltr">Hi Dan,<div><br></div><div>I am getting the follow testing failure when running the test cfg-stackify.ll:</div><div><br></div><div><div>cfg-stackify.ll:203:10: error: expected string not found in input</div><div>; CHECK: (loop $BB8_1)</div><div>         ^</div><div><stdin>:177:2: note: scanning from here</div><div> (loop $BB8_2)</div><div> ^</div><div class="gmail_extra"><br></div><div class="gmail_extra">Diff the output from llc run line between revisions:</div><div class="gmail_extra"><div class="gmail_extra">11c11</div><div class="gmail_extra">< <span style="white-space:pre-wrap">     </span>(loop $BB0_3)</div><div class="gmail_extra">---</div><div class="gmail_extra">> <span style="white-space:pre-wrap"> </span>(loop $BB0_2)</div><div class="gmail_extra">32c32</div><div class="gmail_extra">< <span style="white-space:pre-wrap">       </span>(loop $BB1_3)</div><div class="gmail_extra">---</div><div class="gmail_extra">> <span style="white-space:pre-wrap"> </span>(loop $BB1_2)</div><div class="gmail_extra">55c55</div><div class="gmail_extra">< <span style="white-space:pre-wrap">       </span>(loop $BB2_2)</div><div class="gmail_extra">---</div><div class="gmail_extra">> <span style="white-space:pre-wrap"> </span>(loop $BB2_1)</div><div class="gmail_extra">162c162</div><div class="gmail_extra">< <span style="white-space:pre-wrap">     </span>(loop $BB7_2)</div><div class="gmail_extra">---</div><div class="gmail_extra">> <span style="white-space:pre-wrap"> </span>(loop $BB7_1)</div><div class="gmail_extra">177c177</div><div class="gmail_extra">< <span style="white-space:pre-wrap">     </span>(loop $BB8_2)</div><div class="gmail_extra">---</div><div class="gmail_extra">> <span style="white-space:pre-wrap"> </span>(loop $BB8_1)</div><div class="gmail_extra">239,263d238</div><div class="gmail_extra">< </div><div class="gmail_extra">< <span style="white-space:pre-wrap">      </span>;; .globl<span style="white-space:pre-wrap">       </span>test3</div><div class="gmail_extra">< (func $test3</div><div class="gmail_extra"><  (param i32)</div><div class="gmail_extra">< <span style="white-space:pre-wrap">    </span>(block $BB11_1)</div><div class="gmail_extra">< <span style="white-space:pre-wrap">       </span>(setlocal @0 (argument 0))</div><div class="gmail_extra">< <span style="white-space:pre-wrap">    </span>(setlocal @1 (immediate 0))</div><div class="gmail_extra">< <span style="white-space:pre-wrap">   </span>(brif $BB11_1 @1)</div><div class="gmail_extra">< <span style="white-space:pre-wrap">     </span>(br $BB11_2)</div><div class="gmail_extra">< BB11_1:</div><div class="gmail_extra">< <span style="white-space:pre-wrap"> </span>(return)</div><div class="gmail_extra">< BB11_2:</div><div class="gmail_extra">< <span style="white-space:pre-wrap">     </span>(loop $BB11_5)</div><div class="gmail_extra">< <span style="white-space:pre-wrap">        </span>(block $BB11_4)</div><div class="gmail_extra">< <span style="white-space:pre-wrap">       </span>(block $BB11_2)</div><div class="gmail_extra">< <span style="white-space:pre-wrap">       </span>(setlocal @3 (eq @4 @1))</div><div class="gmail_extra">< BB11_3:</div><div class="gmail_extra">< <span style="white-space:pre-wrap">     </span>(loop $BB11_4)</div><div class="gmail_extra">< <span style="white-space:pre-wrap">        </span>(setlocal @5 (eq @6 @0))</div><div class="gmail_extra">< <span style="white-space:pre-wrap">      </span>(brif $BB11_4 @5)</div><div class="gmail_extra">< <span style="white-space:pre-wrap">     </span>(br $BB11_3)</div><div class="gmail_extra">< BB11_4:</div><div class="gmail_extra">< <span style="white-space:pre-wrap"> </span>(call $bar)</div><div class="gmail_extra">< <span style="white-space:pre-wrap">   </span>(br $BB11_2)</div><div class="gmail_extra">< ) ;; end func $test3</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 2, 2015 at 2:11 PM, Dan Gohman via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: djg<br>
Date: Fri Oct  2 16:11:36 2015<br>
New Revision: 249187<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=249187&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=249187&view=rev</a><br>
Log:<br>
[WebAssembly] Fix CFG stackification of nested loops.<br>
<br>
Modified:<br>
    llvm/trunk/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp<br>
    llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll<br>
<br>
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp?rev=249187&r1=249186&r2=249187&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp?rev=249187&r1=249186&r2=249187&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp (original)<br>
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp Fri Oct  2 16:11:36 2015<br>
@@ -194,8 +194,10 @@ static void SortBlocks(MachineFunction &<br>
     if (MachineLoop *Loop = MLI.getLoopFor(&MBB)) {<br>
       // Assert that loops are contiguous.<br>
       assert(Loop->getHeader() == Loop->getTopBlock());<br>
-      assert(Loop->getHeader() == &MBB ||<br>
-             MLI.getLoopFor(prev(MachineFunction::iterator(&MBB))) == Loop);<br>
+      assert((Loop->getHeader() == &MBB ||<br>
+              Loop->contains(<br>
+                  MLI.getLoopFor(prev(MachineFunction::iterator(&MBB))))) &&<br>
+             "Loop isn't contiguous");<br>
     } else {<br>
       // Assert that non-loops have no backedge predecessors.<br>
       for (auto Pred : MBB.predecessors())<br>
@@ -245,9 +247,18 @@ static void PlaceMarkers(MachineFunction<br>
   for (auto &MBB : MF) {<br>
     // Place the LOOP for loops.<br>
     if (MachineLoop *Loop = MLI.getLoopFor(&MBB))<br>
-      if (Loop->getHeader() == &MBB)<br>
+      if (Loop->getHeader() == &MBB) {<br>
+        // The operand of a LOOP is the first block after the loop. If the loop<br>
+        // is the bottom of the function, insert a dummy block at the end.<br>
+        MachineBasicBlock *Bottom = Loop->getBottomBlock();<br>
+        auto Iter = next(MachineFunction::iterator(Bottom));<br>
+        if (Iter == MF.end()) {<br>
+          MF.push_back(MF.CreateMachineBasicBlock());<br>
+          Iter = next(MachineFunction::iterator(Bottom));<br>
+        }<br>
         BuildMI(MBB, MBB.begin(), DebugLoc(), TII.get(WebAssembly::LOOP))<br>
-            .addMBB(Loop->getBottomBlock());<br>
+            .addMBB(Iter);<br>
+      }<br>
<br>
     // Check for forward branches and switches that need BLOCKS placed.<br>
     for (auto &Term : MBB.terminators())<br>
<br>
Modified: llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll?rev=249187&r1=249186&r2=249187&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll?rev=249187&r1=249186&r2=249187&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll (original)<br>
+++ llvm/trunk/test/CodeGen/WebAssembly/cfg-stackify.ll Fri Oct  2 16:11:36 2015<br>
@@ -272,3 +272,33 @@ exit:<br>
   store volatile i32 4, i32* %p<br>
   ret i32 0<br>
 }<br>
+<br>
+; Test that nested loops are handled.<br>
+<br>
+declare void @bar()<br>
+<br>
+define void @test3(i32 %w)  {<br>
+entry:<br>
+  br i1 undef, label %<a href="http://outer.ph" rel="noreferrer" target="_blank">outer.ph</a>, label %exit<br>
+<br>
+<a href="http://outer.ph" rel="noreferrer" target="_blank">outer.ph</a>:<br>
+  br label %outer<br>
+<br>
+outer:<br>
+  %tobool = icmp eq i32 undef, 0<br>
+  br i1 %tobool, label %inner, label %unreachable<br>
+<br>
+unreachable:<br>
+  unreachable<br>
+<br>
+inner:<br>
+  %c = icmp eq i32 undef, %w<br>
+  br i1 %c, label %if.end, label %inner<br>
+<br>
+exit:<br>
+  ret void<br>
+<br>
+if.end:<br>
+  call void @bar()<br>
+  br label %outer<br>
+}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div></div>