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

Chris Lattner sabre at nondot.org
Fri Oct 20 22:54:14 PDT 2006



Changes in directory llvm/lib/CodeGen:

BranchFolding.cpp updated: 1.17 -> 1.18
---
Log message:

Use branch reversal to do stuff like this:

        call L_strcmp$stub
        testl %eax, %eax
-       jne LBB26_208   #cond_true6020
-       jmp LBB26_227   #bb7119
+       je LBB26_227    #bb7119
 LBB26_208:     #cond_true6020
        movl $l31_str14, 4(%esp)

        testl %eax, %eax
-       jne LBB26_704   #cond_true13042
-       jmp LBB26_713   #bb13151
+       je LBB26_713    #bb13151
 LBB26_704:     #cond_true13042
        movl $_str52, 4(%esp)

        cmpl 76(%ecx), %eax
-       jge LBB26_1628  #cond_false63.i.i
-       jmp LBB26_1769  #_Z8makeGridP13mrSurfaceListidiidd.exit.i
+       jl LBB26_1769   #_Z8makeGridP13mrSurfaceListidiidd.exit.i
 LBB26_1628:    #cond_false63.i.i
        movl $0, 48964(%esp)




---
Diffs of the changes:  (+14 -0)

 BranchFolding.cpp |   14 ++++++++++++++
 1 files changed, 14 insertions(+)


Index: llvm/lib/CodeGen/BranchFolding.cpp
diff -u llvm/lib/CodeGen/BranchFolding.cpp:1.17 llvm/lib/CodeGen/BranchFolding.cpp:1.18
--- llvm/lib/CodeGen/BranchFolding.cpp:1.17	Sat Oct 21 00:43:30 2006
+++ llvm/lib/CodeGen/BranchFolding.cpp	Sat Oct 21 00:54:00 2006
@@ -472,6 +472,20 @@
       ++NumBranchOpts;
       return OptimizeBlock(MBB);
     }
+    
+    // If the prior block branches here on true and somewhere else on false, and
+    // if the branch condition is reversible, reverse the branch to create a
+    // fall-through.
+    if (PriorTBB == &*MBB) {
+      std::vector<MachineOperand> NewPriorCond(PriorCond);
+      if (!TII->ReverseBranchCondition(NewPriorCond)) {
+        TII->RemoveBranch(PrevBB);
+        TII->InsertBranch(PrevBB, PriorFBB, 0, NewPriorCond);
+        MadeChange = true;
+        ++NumBranchOpts;
+        return OptimizeBlock(MBB);
+      }
+    }
   }
   
   // Analyze the branch in the current block.






More information about the llvm-commits mailing list