Add a late optimization to BranchFolding that hoist common instruction sequences
authorEvan Cheng <evan.cheng@apple.com>
Wed, 11 May 2011 01:03:01 +0000 (01:03 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Wed, 11 May 2011 01:03:01 +0000 (01:03 +0000)
commit7e20a574eb3f4fc3840a0490c814443d756e2e0e
tree7e148f185b14e932bf5f84bb0e8e6714aa5f53e1
parentb38fe4b52de05a35c0693f4fd117f908a2abadb7
Add a late optimization to BranchFolding that hoist common instruction sequences
at the start of basic blocks to their common predecessor. It's actually quite
common (e.g. about 50 times in JM/lencod) and has shown to be a nice code size
benefit. e.g.

        pushq   %rax
        testl   %edi, %edi
        jne     LBB0_2
## BB#1:
        xorb    %al, %al
        popq    %rdx
        ret
LBB0_2:
        xorb    %al, %al
        callq   _foo
        popq    %rdx
        ret

=>

        pushq   %rax
        xorb    %al, %al
        testl   %edi, %edi
        je      LBB0_2
## BB#1:
        callq   _foo
LBB0_2:
        popq    %rdx
        ret

rdar://9145558

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131172 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/BranchFolding.cpp
lib/CodeGen/BranchFolding.h
lib/CodeGen/IfConversion.cpp
test/CodeGen/X86/hoist-common.ll [new file with mode: 0644]