<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">I’ve reverted this change in <span style="color: rgba(0, 0, 0, 0.85098); font-family: "Helvetica Neue";" class="">r369104, as it seems to cause a verifier failure.</span></div><div class=""><span style="color: rgba(0, 0, 0, 0.85098); font-family: "Helvetica Neue";" class=""><br class=""></span></div><div class=""><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">It looks like this commit adds invalid predecessors to MBBs. The example </span></font><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098); font-family: "Helvetica Neue";" class="">below fails the verifier after MachineBlockPlacement (run llc </span><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098); font-family: "Helvetica Neue";" class="">-verify-machineinstrs):</span></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class=""><br class=""></span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">    @global.4 = external constant i8*</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class=""><br class=""></span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">    declare i32 @zot(...)</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class=""><br class=""></span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">    define i16* @snork.67() personality i8* bitcast (i32 (...)* @zot to i8*) {</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">    bb:</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">      invoke void undef()</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">              to label %bb5 unwind label %bb4</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class=""><br class=""></span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">    bb4:                                              ; preds = %bb</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">      %tmp = landingpad { i8*, i32 }</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">              catch i8* null</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">      unreachable</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class=""><br class=""></span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">    bb5:                                              ; preds = %bb</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">      %tmp6 = load i32, i32* null, align 4</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">      %tmp7 = icmp eq i32 %tmp6, 0</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">      br i1 %tmp7, label %bb14, label %bb8</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class=""><br class=""></span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">    bb8:                                              ; preds = %bb11, %bb5</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">      invoke void undef()</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">              to label %bb9 unwind label %bb11</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class=""><br class=""></span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">    bb9:                                              ; preds = %bb8</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">      %tmp10 = invoke i16* undef()</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">              to label %bb14 unwind label %bb11</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class=""><br class=""></span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">    bb11:                                             ; preds = %bb9, %bb8</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">      %tmp12 = landingpad { i8*, i32 }</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">              cleanup</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">              catch i8* bitcast (i8** @global.4 to i8*)</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">      %tmp13 = icmp ult i64 undef, undef</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">      br i1 %tmp13, label %bb8, label %bb14</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class=""><br class=""></span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">    bb14:                                             ; preds = %bb11, %bb9, %bb5</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">      %tmp15 = phi i16* [ null, %bb5 ], [ null, %bb11 ], [ %tmp10, %bb9 ]</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">      ret i16* %tmp15</span></font></div><div class=""><font face="Helvetica Neue" class=""><span style="caret-color: rgba(0, 0, 0, 0.85098); color: rgba(0, 0, 0, 0.85098);" class="">    }</span></font></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Cheers,</div><div class="">Florian</div><div class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Aug 15, 2019, at 14:05, Kang Zhang 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=""><div class="">Author: zhangkang<br class="">Date: Thu Aug 15 06:05:16 2019<br class="">New Revision: 368997<br class=""><br class="">URL: <a href="http://llvm.org/viewvc/llvm-project?rev=368997&view=rev" class="">http://llvm.org/viewvc/llvm-project?rev=368997&view=rev</a><br class="">Log:<br class="">[CodeGen] Do the Simple Early Return in block-placement pass to optimize the blocks<br class=""><br class="">Summary:<br class=""><br class="">This patch has trigger a bug of r368339, and the r368339 has been reverted, So upstream this patch again.<br class=""><br class="">In `block-placement` pass, it will create some patterns for unconditional we can do the simple early retrun.<br class="">But the `early-ret` pass is before `block-placement`, we don't want to run it again.<br class="">This patch is to do the simple early return to optimize the blocks at the last of `block-placement`.<br class=""><br class="">Reviewed By: efriedma<br class=""><br class="">Differential Revision: <a href="https://reviews.llvm.org/D63972" class="">https://reviews.llvm.org/D63972</a><br class=""><br class="">Modified:<br class="">    llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp<br class="">    llvm/trunk/test/CodeGen/PowerPC/block-placement.mir<br class=""><br class="">Modified: llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp?rev=368997&r1=368996&r2=368997&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp?rev=368997&r1=368996&r2=368997&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp (original)<br class="">+++ llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp Thu Aug 15 06:05:16 2019<br class="">@@ -2711,6 +2711,7 @@ void MachineBlockPlacement::optimizeBran<br class="">   // cannot because all branches may not be analyzable.<br class="">   // E.g., the target may be able to remove an unconditional branch to<br class="">   // a fallthrough when it occurs after predicated terminators.<br class="">+  SmallVector<MachineBasicBlock*, 4> EmptyBB;<br class="">   for (MachineBasicBlock *ChainBB : FunctionChain) {<br class="">     Cond.clear();<br class="">     MachineBasicBlock *TBB = nullptr, *FBB = nullptr; // For AnalyzeBranch.<br class="">@@ -2730,9 +2731,42 @@ void MachineBlockPlacement::optimizeBran<br class="">         TII->removeBranch(*ChainBB);<br class="">         TII->insertBranch(*ChainBB, FBB, TBB, Cond, dl);<br class="">         ChainBB->updateTerminator();<br class="">+      } else if (Cond.empty() && TBB && ChainBB != TBB && !TBB->empty() &&<br class="">+                 !TBB->canFallThrough()) {<br class="">+        // When ChainBB is unconditional branch to the TBB, and TBB has no<br class="">+        // fallthrough predecessor and fallthrough successor, try to merge<br class="">+        // ChainBB and TBB. This is legal under the one of following conditions:<br class="">+        // 1. ChainBB is empty except for an unconditional branch.<br class="">+        // 2. TBB has only one predecessor.<br class="">+        MachineFunction::iterator I(TBB);<br class="">+        if (((TBB == &*F->begin()) || !std::prev(I)->canFallThrough()) &&<br class="">+             (TailDup.isSimpleBB(ChainBB) || (TBB->pred_size() == 1))) {<br class="">+          TII->removeBranch(*ChainBB);<br class="">+          ChainBB->removeSuccessor(TBB);<br class="">+<br class="">+          // Update the CFG.<br class="">+          while (!TBB->pred_empty()) {<br class="">+            MachineBasicBlock *Pred = *(TBB->pred_end() - 1);<br class="">+            Pred->ReplaceUsesOfBlockWith(TBB, ChainBB);<br class="">+          }<br class="">+<br class="">+          for (MachineBasicBlock *Succ : TBB->successors())<br class="">+            ChainBB->addSuccessor(Succ, MBPI->getEdgeProbability(TBB, Succ));<br class="">+<br class="">+          // Move all the instructions of TBB to ChainBB.<br class="">+          ChainBB->splice(ChainBB->end(), TBB, TBB->begin(), TBB->end());<br class="">+          EmptyBB.push_back(TBB);<br class="">+        }<br class="">       }<br class="">     }<br class="">   }<br class="">+<br class="">+  for (auto BB: EmptyBB) {<br class="">+    MLI->removeBlock(BB);<br class="">+    FunctionChain.remove(BB);<br class="">+    BlockToChain.erase(BB);<br class="">+    F->erase(BB);<br class="">+  }<br class=""> }<br class=""><br class=""> void MachineBlockPlacement::alignBlocks() {<br class="">@@ -3052,6 +3086,9 @@ bool MachineBlockPlacement::runOnMachine<br class="">     }<br class="">   }<br class=""><br class="">+  // optimizeBranches() may change the blocks, but we haven't updated the<br class="">+  // post-dominator tree. Because the post-dominator tree won't be used after<br class="">+  // this function and this pass don't preserve the post-dominator tree.<br class="">   optimizeBranches();<br class="">   alignBlocks();<br class=""><br class=""><br class="">Modified: llvm/trunk/test/CodeGen/PowerPC/block-placement.mir<br class="">URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/block-placement.mir?rev=368997&r1=368996&r2=368997&view=diff" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/block-placement.mir?rev=368997&r1=368996&r2=368997&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/test/CodeGen/PowerPC/block-placement.mir (original)<br class="">+++ llvm/trunk/test/CodeGen/PowerPC/block-placement.mir Thu Aug 15 06:05:16 2019<br class="">@@ -209,14 +209,10 @@ body:             |<br class="">     BLR8 implicit $lr8, implicit $rm, implicit killed $x3<br class=""><br class="">   ; CHECK:      bb.5.if.else.i:<br class="">-  ; CHECK:        successors: %bb.11(0x80000000)<br class="">-  ; CHECK:        B %bb.11<br class="">+  ; CHECK-NEXT:   renamable $x3 = LI8 1<br class="">+  ; CHECK-NEXT:   BLR8 implicit $lr8, implicit $rm, implicit killed $x3<br class=""><br class="">   ; CHECK:      bb.8.while.body.i (align 4):<br class="">-  ; CHECK:        successors: %bb.11(0x04000000), %bb.9(0x7c000000)<br class="">-  ; CHECK:        BCC 76, killed renamable $cr0, %bb.11<br class="">-<br class="">-  ; CHECK:      bb.11:<br class="">-  ; CHECK:        renamable $x3 = LI8 1<br class="">-  ; CHECK-NEXT:   BLR8 implicit $lr8, implicit $rm, implicit killed $x3<br class="">+  ; CHECK:        successors: %bb.5(0x04000000), %bb.9(0x7c000000)<br class="">+  ; CHECK:        BCC 76, killed renamable $cr0, %bb.5<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="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits<br class=""></div></div></blockquote></div><br class=""></div></body></html>