Add a really quick hack at a machine code sinking pass, enabled with --enable-sinking.
authorChris Lattner <sabre@nondot.org>
Fri, 4 Jan 2008 07:36:53 +0000 (07:36 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 4 Jan 2008 07:36:53 +0000 (07:36 +0000)
commitc4ce73f666e7ab9a270982a575101df8aa6160d3
treeb05a1285877e96f4bc81bdd9e76e7913b522dd40
parentac69582664714c2656a28ed6cb70627bb85ee673
Add a really quick hack at a machine code sinking pass, enabled with --enable-sinking.
It is missing validity checks, so it is known broken.  However, it is powerful enough
to compile this contrived code:

void test1(int C, double A, double B, double *P) {
  double Tmp = A*A+B*B;
  *P = C ? Tmp : A;
}

into:

_test1:
movsd 8(%esp), %xmm0
cmpl $0, 4(%esp)
je LBB1_2 # entry
LBB1_1: # entry
movsd 16(%esp), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
LBB1_2: # entry
movl 24(%esp), %eax
movsd %xmm0, (%eax)
ret

instead of:

_test1:
movsd 16(%esp), %xmm0
mulsd %xmm0, %xmm0
movsd 8(%esp), %xmm1
movapd %xmm1, %xmm2
mulsd %xmm2, %xmm2
addsd %xmm0, %xmm2
cmpl $0, 4(%esp)
je LBB1_2 # entry
LBB1_1: # entry
movapd %xmm2, %xmm1
LBB1_2: # entry
movl 24(%esp), %eax
movsd %xmm1, (%eax)
ret

woo.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45570 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/CodeGen/Passes.h
lib/CodeGen/LLVMTargetMachine.cpp
lib/CodeGen/MachineSink.cpp [new file with mode: 0644]