[llvm-commits] CVS: llvm/lib/CodeGen/BranchFolding.cpp

Chris Lattner sabre at nondot.org
Sat Oct 28 10:33:02 PDT 2006



Changes in directory llvm/lib/CodeGen:

BranchFolding.cpp updated: 1.24 -> 1.25
---
Log message:

improve deletion of blocks that just contain branches by knowing that
the pred block doesn't fall through into them if it's a jumptable.


---
Diffs of the changes:  (+38 -33)

 BranchFolding.cpp |   71 ++++++++++++++++++++++++++++--------------------------
 1 files changed, 38 insertions(+), 33 deletions(-)


Index: llvm/lib/CodeGen/BranchFolding.cpp
diff -u llvm/lib/CodeGen/BranchFolding.cpp:1.24 llvm/lib/CodeGen/BranchFolding.cpp:1.25
--- llvm/lib/CodeGen/BranchFolding.cpp:1.24	Wed Oct 25 17:21:37 2006
+++ llvm/lib/CodeGen/BranchFolding.cpp	Sat Oct 28 12:32:47 2006
@@ -534,43 +534,48 @@
       // completely eliminate the block is when the block before this one
       // falls through into MBB and we can't understand the prior block's branch
       // condition.
-      if (MBB->empty() && (!PriorUnAnalyzable || !PrevBB.isSuccessor(MBB))) {
-        // If the prior block falls through into us, turn it into an
-        // explicit branch to us to make updates simpler.
-        if (PrevBB.isSuccessor(MBB) && PriorTBB != MBB && PriorFBB != MBB) {
-          if (PriorTBB == 0) {
-            assert(PriorCond.empty() && PriorFBB == 0 && "Bad branch analysis");
-            PriorTBB = MBB;
-          } else {
-            assert(PriorFBB == 0 && "Machine CFG out of date!");
-            PriorFBB = MBB;
+      if (MBB->empty()) {
+        bool PredHasNoFallThrough = TII->BlockHasNoFallThrough(PrevBB);
+        if (PredHasNoFallThrough || !PriorUnAnalyzable ||
+            !PrevBB.isSuccessor(MBB)) {
+          // If the prior block falls through into us, turn it into an
+          // explicit branch to us to make updates simpler.
+          if (!PredHasNoFallThrough && PrevBB.isSuccessor(MBB) && 
+              PriorTBB != MBB && PriorFBB != MBB) {
+            if (PriorTBB == 0) {
+              assert(PriorCond.empty() && PriorFBB == 0 && "Bad branch analysis");
+              PriorTBB = MBB;
+            } else {
+              assert(PriorFBB == 0 && "Machine CFG out of date!");
+              PriorFBB = MBB;
+            }
+            TII->RemoveBranch(PrevBB);
+            TII->InsertBranch(PrevBB, PriorTBB, PriorFBB, PriorCond);
           }
-          TII->RemoveBranch(PrevBB);
-          TII->InsertBranch(PrevBB, PriorTBB, PriorFBB, PriorCond);
-        }
 
-        // Iterate through all the predecessors, revectoring each in-turn.
-        MachineBasicBlock::pred_iterator PI = MBB->pred_begin();
-        bool DidChange = false;
-        bool HasBranchToSelf = false;
-        while (PI != MBB->pred_end()) {
-          if (*PI == MBB) {
-            // If this block has an uncond branch to itself, leave it.
-            ++PI;
-            HasBranchToSelf = true;
-          } else {
-            DidChange = true;
-            ReplaceUsesOfBlockWith(*PI, MBB, CurTBB, TII);
+          // Iterate through all the predecessors, revectoring each in-turn.
+          MachineBasicBlock::pred_iterator PI = MBB->pred_begin();
+          bool DidChange = false;
+          bool HasBranchToSelf = false;
+          while (PI != MBB->pred_end()) {
+            if (*PI == MBB) {
+              // If this block has an uncond branch to itself, leave it.
+              ++PI;
+              HasBranchToSelf = true;
+            } else {
+              DidChange = true;
+              ReplaceUsesOfBlockWith(*PI, MBB, CurTBB, TII);
+            }
           }
-        }
 
-        // Change any jumptables to go to the new MBB.
-        MBB->getParent()->getJumpTableInfo()->ReplaceMBBInJumpTables(MBB,
-                                                                     CurTBB);
-        if (DidChange) {
-          ++NumBranchOpts;
-          MadeChange = true;
-          if (!HasBranchToSelf) return;
+          // Change any jumptables to go to the new MBB.
+          MBB->getParent()->getJumpTableInfo()->ReplaceMBBInJumpTables(MBB,
+                                                                       CurTBB);
+          if (DidChange) {
+            ++NumBranchOpts;
+            MadeChange = true;
+            if (!HasBranchToSelf) return;
+          }
         }
       }
       






More information about the llvm-commits mailing list