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

Chris Lattner sabre at nondot.org
Tue Nov 7 17:03:42 PST 2006



Changes in directory llvm/lib/CodeGen:

BranchFolding.cpp updated: 1.32 -> 1.33
---
Log message:

optimize single MBB loops better.  In particular, produce:

LBB1_57:        #bb207.i
        movl 72(%esp), %ecx
        movb (%ecx,%eax), %cl
        movl 80(%esp), %edx
        movb %cl, 1(%edx,%eax)
        incl %eax
        cmpl $143, %eax
        jne LBB1_57     #bb207.i
        jmp LBB1_64     #cond_next255.i

intead of:

LBB1_57:        #bb207.i
        movl 72(%esp), %ecx
        movb (%ecx,%eax), %cl
        movl 80(%esp), %edx
        movb %cl, 1(%edx,%eax)
        incl %eax
        cmpl $143, %eax
        je LBB1_64      #cond_next255.i
        jmp LBB1_57     #bb207.i

This eliminates a branch per iteration of the loop.  This hurted PPC 
particularly, because the extra branch meant another dispatch group for each
iteration of the loop.



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

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


Index: llvm/lib/CodeGen/BranchFolding.cpp
diff -u llvm/lib/CodeGen/BranchFolding.cpp:1.32 llvm/lib/CodeGen/BranchFolding.cpp:1.33
--- llvm/lib/CodeGen/BranchFolding.cpp:1.32	Sun Nov  5 13:31:28 2006
+++ llvm/lib/CodeGen/BranchFolding.cpp	Tue Nov  7 19:03:21 2006
@@ -687,6 +687,23 @@
                                        !CurCond.empty(),
                                        ++MachineFunction::iterator(MBB));
 
+    // If this is a two-way branch, and the FBB branches to this block, reverse 
+    // the condition so the single-basic-block loop is faster.  Instead of:
+    //    Loop: xxx; jcc Out; jmp Loop
+    // we want:
+    //    Loop: xxx; jncc Loop; jmp Out
+    if (CurTBB && CurFBB && CurFBB == MBB && CurTBB != MBB) {
+      std::vector<MachineOperand> NewCond(CurCond);
+      if (!TII->ReverseBranchCondition(NewCond)) {
+        TII->RemoveBranch(*MBB);
+        TII->InsertBranch(*MBB, CurFBB, CurTBB, NewCond);
+        MadeChange = true;
+        ++NumBranchOpts;
+        return OptimizeBlock(MBB);
+      }
+    }
+    
+    
     // If this branch is the only thing in its block, see if we can forward
     // other blocks across it.
     if (CurTBB && CurCond.empty() && CurFBB == 0 && 






More information about the llvm-commits mailing list