]> granicus.if.org Git - llvm/commitdiff
[MachineBlockPlacement] Make sure PreferredLoopExit is cleared everytime new loop...
authorXin Tong <trent.xin.tong@gmail.com>
Wed, 4 Oct 2017 21:39:25 +0000 (21:39 +0000)
committerXin Tong <trent.xin.tong@gmail.com>
Wed, 4 Oct 2017 21:39:25 +0000 (21:39 +0000)
Summary: Rotate on exit that actually exits the current loop.

Reviewers: davidxl, danielcdh, iteratee, chandlerc

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D38563

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314937 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/MachineBlockPlacement.cpp

index f135cf715936be3114565c7535235b74fd4ae3c0..12d8a9a0217a2c46b2cca20cc3d5604ed7a90fb5 100644 (file)
@@ -2233,9 +2233,19 @@ void MachineBlockPlacement::buildLoopChains(const MachineLoop &L) {
   // If we selected just the header for the loop top, look for a potentially
   // profitable exit block in the event that rotating the loop can eliminate
   // branches by placing an exit edge at the bottom.
+  //
+  // Loops are processed innermost to uttermost, make sure we clear
+  // PreferredLoopExit before processing a new loop.
+  PreferredLoopExit = nullptr;
   if (!RotateLoopWithProfile && LoopTop == L.getHeader())
     PreferredLoopExit = findBestLoopExit(L, LoopBlockSet);
 
+  // Make sure PreferredLoopExit actually exits the current loop.
+  if (PreferredLoopExit) {
+    assert(L.isLoopExiting(PreferredLoopExit) &&
+           "not an exiting block of current loop");
+  }
+
   BlockChain &LoopChain = *BlockToChain[LoopTop];
 
   // FIXME: This is a really lame way of walking the chains in the loop: we