Filter "sink to" candidate blocks sooner. This avoids unnecessary computation to...
authorDevang Patel <dpatel@apple.com>
Thu, 8 Dec 2011 21:33:23 +0000 (21:33 +0000)
committerDevang Patel <dpatel@apple.com>
Thu, 8 Dec 2011 21:33:23 +0000 (21:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146184 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/MachineSink.cpp

index 8a342377890401e766367709fa9122e33f4532ea..0d14b63b632e0cd2e08c1385327530d7a213ee4c 100644 (file)
@@ -499,10 +499,21 @@ bool MachineSinking::SinkInstruction(MachineInstr *MI, bool &SawStore) {
       // we should sink to.
       for (MachineBasicBlock::succ_iterator SI = ParentBlock->succ_begin(),
            E = ParentBlock->succ_end(); SI != E; ++SI) {
+       MachineBasicBlock *SuccBlock = *SI;
+       // It is not possible to sink an instruction into its own block.  This can
+       // happen with loops.
+       if (ParentBlock == SuccBlock)
+         continue;
+
+       // It's not safe to sink instructions to EH landing pad. Control flow into
+       // landing pad is implicitly defined.
+       if (SuccBlock->isLandingPad())
+         continue;
+
         bool LocalUse = false;
-        if (AllUsesDominatedByBlock(Reg, *SI, ParentBlock,
+        if (AllUsesDominatedByBlock(Reg, SuccBlock, ParentBlock,
                                     BreakPHIEdge, LocalUse)) {
-          SuccToSinkTo = *SI;
+          SuccToSinkTo = SuccBlock;
           break;
         }
         if (LocalUse)
@@ -520,15 +531,6 @@ bool MachineSinking::SinkInstruction(MachineInstr *MI, bool &SawStore) {
   if (SuccToSinkTo == 0)
     return false;
 
-  // It's not safe to sink instructions to EH landing pad. Control flow into
-  // landing pad is implicitly defined.
-  if (SuccToSinkTo->isLandingPad())
-    return false;
-
-  // It is not possible to sink an instruction into its own block.  This can
-  // happen with loops.
-  if (MI->getParent() == SuccToSinkTo)
-    return false;
 
   // If the instruction to move defines a dead physical register which is live
   // when leaving the basic block, don't move it because it could turn into a