ShrinkWrap.cpp: Tweak r244235 for a non-functional member, PredicateFtor. [-Wdocument...
[oota-llvm.git] / lib / CodeGen / ShrinkWrap.cpp
index f8ec1f358c4f4d67e5643ec190fb946d4b54fe7e..43b39e934c4d823ff81c62ada26f6ab2ca82cbee 100644 (file)
@@ -187,8 +187,8 @@ private:
   ///
   /// This function will be run at the beginning of shrink wrapping and
   /// determine whether shrink wrapping should run on the given MachineFunction.
-  /// \param[in] MF The MachineFunction to run shrink wrapping on.
-  /// \return true if shrink wrapping should be run, false otherwise.
+  /// \arg MF The MachineFunction to run shrink wrapping on.
+  /// It returns true if shrink wrapping should be run, false otherwise.
   std::function<bool(const MachineFunction &MF)> PredicateFtor;
 };
 } // End anonymous namespace.
@@ -309,12 +309,30 @@ void ShrinkWrap::updateSaveRestorePoints(MachineBasicBlock &MBB) {
     // Fix (C).
     if (Save && Restore && Save != Restore &&
         MLI->getLoopFor(Save) != MLI->getLoopFor(Restore)) {
-      if (MLI->getLoopDepth(Save) > MLI->getLoopDepth(Restore))
-        // Push Save outside of this loop.
-        Save = FindIDom<>(*Save, Save->predecessors(), *MDT);
-      else
-        // Push Restore outside of this loop.
-        Restore = FindIDom<>(*Restore, Restore->successors(), *MPDT);
+      if (MLI->getLoopDepth(Save) > MLI->getLoopDepth(Restore)) {
+        // Push Save outside of this loop if immediate dominator is different
+        // from save block. If immediate dominator is not different, bail out. 
+        MachineBasicBlock *IDom = FindIDom<>(*Save, Save->predecessors(), *MDT);
+        if (IDom != Save)
+          Save = IDom;
+        else {
+          Save = nullptr;
+          break;
+        }
+      }
+      else {
+        // Push Restore outside of this loop if immediate post-dominator is
+        // different from restore block. If immediate post-dominator is not
+        // different, bail out. 
+        MachineBasicBlock *IPdom =
+          FindIDom<>(*Restore, Restore->successors(), *MPDT);
+        if (IPdom != Restore)
+          Restore = IPdom; 
+        else {
+          Restore = nullptr;
+          break;
+        }
+      }      
     }
   }
 }