Commit Graph

5607 Commits

Author SHA1 Message Date
Chris Lattner
940ff563f7 Fix incorrect debug code
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11821 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-25 15:15:04 +00:00
Chris Lattner
5f2c7b1975 Teach the instruction selector how to transform 'array' GEP computations into X86
scaled indexes.  This allows us to compile GEP's like this:

int* %test([10 x { int, { int } }]* %X, int %Idx) {
        %Idx = cast int %Idx to long
        %X = getelementptr [10 x { int, { int } }]* %X, long 0, long %Idx, ubyte 1, ubyte 0
        ret int* %X
}

Into a single address computation:

test:
        mov %EAX, DWORD PTR [%ESP + 4]
        mov %ECX, DWORD PTR [%ESP + 8]
        lea %EAX, DWORD PTR [%EAX + 8*%ECX + 4]
        ret

Before it generated:
test:
        mov %EAX, DWORD PTR [%ESP + 4]
        mov %ECX, DWORD PTR [%ESP + 8]
        shl %ECX, 3
        add %EAX, %ECX
        lea %EAX, DWORD PTR [%EAX + 4]
        ret

This is useful for things like int/float/double arrays, as the indexing can be folded into
the loads&stores, reducing register pressure and decreasing the pressure on the decode unit.
With these changes, I expect our performance on 256.bzip2 and gzip to improve a lot.  On
bzip2 for example, we go from this:

10665 asm-printer           - Number of machine instrs printed
   40 ra-local              - Number of loads/stores folded into instructions
 1708 ra-local              - Number of loads added
 1532 ra-local              - Number of stores added
 1354 twoaddressinstruction - Number of instructions added
 1354 twoaddressinstruction - Number of two-address instructions
 2794 x86-peephole          - Number of peephole optimization performed

to this:
9873 asm-printer           - Number of machine instrs printed
  41 ra-local              - Number of loads/stores folded into instructions
1710 ra-local              - Number of loads added
1521 ra-local              - Number of stores added
 789 twoaddressinstruction - Number of instructions added
 789 twoaddressinstruction - Number of two-address instructions
2142 x86-peephole          - Number of peephole optimization performed

... and these types of instructions are often in tight loops.

Linear scan is also helped, but not as much.  It goes from:

8787 asm-printer           - Number of machine instrs printed
2389 liveintervals         - Number of identity moves eliminated after coalescing
2288 liveintervals         - Number of interval joins performed
3522 liveintervals         - Number of intervals after coalescing
5810 liveintervals         - Number of original intervals
 700 spiller               - Number of loads added
 487 spiller               - Number of stores added
 303 spiller               - Number of register spills
1354 twoaddressinstruction - Number of instructions added
1354 twoaddressinstruction - Number of two-address instructions
 363 x86-peephole          - Number of peephole optimization performed

to:

7982 asm-printer           - Number of machine instrs printed
1759 liveintervals         - Number of identity moves eliminated after coalescing
1658 liveintervals         - Number of interval joins performed
3282 liveintervals         - Number of intervals after coalescing
4940 liveintervals         - Number of original intervals
 635 spiller               - Number of loads added
 452 spiller               - Number of stores added
 288 spiller               - Number of register spills
 789 twoaddressinstruction - Number of instructions added
 789 twoaddressinstruction - Number of two-address instructions
 258 x86-peephole          - Number of peephole optimization performed

Though I'm not complaining about the drop in the number of intervals.  :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11820 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-25 07:00:55 +00:00
Chris Lattner
b6bac51351 * Make the previous patch more efficient by not allocating a temporary MachineInstr
to do analysis.

*** FOLD getelementptr instructions into loads and stores when possible,
    making use of some of the crazy X86 addressing modes.

For example, the following C++ program fragment:

struct complex {
    double re, im;
    complex(double r, double i) : re(r), im(i) {}
};
inline complex operator+(const complex& a, const complex& b) {
    return complex(a.re+b.re, a.im+b.im);
}
complex addone(const complex& arg) {
    return arg + complex(1,0);
}

Used to be compiled to:
_Z6addoneRK7complex:
        mov %EAX, DWORD PTR [%ESP + 4]
        mov %ECX, DWORD PTR [%ESP + 8]
***     mov %EDX, %ECX
        fld QWORD PTR [%EDX]
        fld1
        faddp %ST(1)
***     add %ECX, 8
        fld QWORD PTR [%ECX]
        fldz
        faddp %ST(1)
***     mov %ECX, %EAX
        fxch %ST(1)
        fstp QWORD PTR [%ECX]
***     add %EAX, 8
        fstp QWORD PTR [%EAX]
        ret

Now it is compiled to:
_Z6addoneRK7complex:
        mov %EAX, DWORD PTR [%ESP + 4]
        mov %ECX, DWORD PTR [%ESP + 8]
        fld QWORD PTR [%ECX]
        fld1
        faddp %ST(1)
        fld QWORD PTR [%ECX + 8]
        fldz
        faddp %ST(1)
        fxch %ST(1)
        fstp QWORD PTR [%EAX]
        fstp QWORD PTR [%EAX + 8]
        ret

Other programs should see similar improvements, across the board.  Note that
in addition to reducing instruction count, this also reduces register pressure
a lot, always a good thing on X86.  :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11819 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-25 06:13:04 +00:00
Chris Lattner
2e68037187 Add a helper to create an addressing mode given all of the pieces.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11818 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-25 06:01:07 +00:00
Chris Lattner
985fe3df6f add an inefficient way of folding structure and constant array indexes together
into a single LEA instruction.  This should improve the code generated for
things like X->A.B.C[12].D.

The bigger benefit is still coming though.  Note that this uses an LEA instruction
instead of an add, giving the register allocator more freedom.  We should probably
never generate ADDri32's.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11817 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-25 03:45:50 +00:00
Chris Lattner
5a83096d6a Implement special case for storing an immediate into memory so that we don't need
an intermediate register.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11816 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-25 02:56:58 +00:00
Chris Lattner
39bb2dc557 Add support for 'rename'
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11813 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-24 22:17:00 +00:00
Chris Lattner
2a11653fa9 Make the verifier a little more explicit about this problem.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11811 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-24 22:06:07 +00:00
Chris Lattner
d561209a47 Add support for remove, fwrite, and fread
Also fix problem where we didn't check to see if a node pointer was null.
Though fclose(null) doesn't make a lot of sense, 300.twolf does it.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11810 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-24 22:02:48 +00:00
Brian Gaeke
748fba141f FunctionLiveVarInfo.h moved: include/llvm/CodeGen -> lib/Target/Sparc/LiveVar
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11804 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-24 19:46:00 +00:00
Chris Lattner
2bcab1f900 Fix some unexpected fallout from the config.h changes. Because the CBE no
longer was getting this #include, it always fell back on the less precise
floating point initializer values, causing some testsuite failures.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11803 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-24 18:34:10 +00:00
Chris Lattner
d38f208cd9 Fix a faulty optimization on FP values
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11801 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-24 18:10:14 +00:00
Chris Lattner
8e509dd5e8 If a block is made dead, make sure to promptly remove it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11799 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-24 16:09:21 +00:00
Alkis Evlogimenos
0d6c5b6489 Move machine code rewriter and spiller outside the register
allocator.

The implementation is completely rewritten and now employs several
optimizations not exercised before. For example for 164.gzip we have
997 loads and 699 stores vs the 1221 loads and 880 stores we have
before.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11798 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-24 08:58:30 +00:00
Chris Lattner
d52c261cf8 Implement SimplifyCFG/switch_switch_fold.ll
This case occurs many times in various benchmarks, especially when combined
with the previous patch.  This allows it to get stuff like:
  if (X == 4 || X == 3)
    if (X == 5 || X == 8)

and

switch (X) {
case 4: case 5: case 6:
  if (X == 4 || X == 5)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11797 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-24 07:23:58 +00:00
Alkis Evlogimenos
ec8b8bb9ab Add predicates for checking if a virtual register has a physical
register mapping or a stack slot mapping.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11795 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-24 06:30:36 +00:00
Chris Lattner
e14ea0804a Rearrange code a bit
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11793 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-24 05:54:22 +00:00
Chris Lattner
0d56008f53 Implement: test/Regression/Transforms/SimplifyCFG/switch_create.ll
This turns code like this:
  if (X == 4 | X == 7)
and
  if (X != 4 & X != 7)
into switch instructions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11792 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-24 05:38:11 +00:00
Alkis Evlogimenos
e8124b9ddb Make enum private as it is an implementation detail.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11782 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 23:49:40 +00:00
Alkis Evlogimenos
797428719f Remove '4Virt' from member function names as it is obvious.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11781 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 23:47:10 +00:00
Alkis Evlogimenos
34d9bc9f16 Refactor VirtRegMap out of RegAllocLinearScan as the first part of bug
251 (providing a generic machine code rewriter/spiller).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11780 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 23:08:11 +00:00
Alkis Evlogimenos
c38aa6dd79 Include Config/config.h for SHLIBEXT.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11779 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 22:42:51 +00:00
Chris Lattner
d8864ce766 Generate much more efficient code in programs like pifft
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11775 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 21:46:58 +00:00
Chris Lattner
077a373791 Fix a small typeo in my checkin last night that broke vortex and other programs :(
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11774 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 21:46:42 +00:00
Chris Lattner
8adac75298 Fix InstCombine/2004-02-23-ShiftShiftOverflow.ll
Also, turn 'shr int %X, 1234' into 'shr int %X, 31'


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11768 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 20:30:06 +00:00
Alkis Evlogimenos
575649322f Add number of spilled registers statistic.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11759 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 18:45:32 +00:00
Chris Lattner
11d1f21e1d Fix bugs in finegrainification
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11758 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 18:40:08 +00:00
Chris Lattner
0742b59913 Finegrainify namespacification
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11757 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 18:38:20 +00:00
Alkis Evlogimenos
e699b16a76 Use MachineBasicBlock::getParent().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11756 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 18:36:38 +00:00
Alkis Evlogimenos
e6394e2b62 Remove implementation of default constructor as it is useless now.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11755 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 18:28:35 +00:00
Alkis Evlogimenos
743d0a1f83 Refactor rewinding code for finding the first terminator of a basic
block into MachineBasicBlock::getFirstTerminator().

This also fixes a bug in the implementation of the above in both
RegAllocLocal and InstrSched, where instructions where added after the
terminator if the basic block's only instruction was a terminator (it
shouldn't matter for RegAllocLocal since this case never occurs in
practice).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11748 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 18:14:48 +00:00
Chris Lattner
fbc39d5045 Simplify code a bit, don't go off the end of the block, now that the current
block we are in might be empty


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11744 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 07:42:19 +00:00
Chris Lattner
65cf42d32f We were forgetting to add FP_REG_KILL instructions to basic blocks which will
eventually get an assignment due to elimination of PHIs.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11743 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 07:29:45 +00:00
Chris Lattner
c5943fb186 Implement cast.ll::test14/15
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11742 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 07:16:20 +00:00
Chris Lattner
4cb170cc6e Refactor some code. In the mul - setcc folding case, we really care about
whether this is the sign bit or not, so check unsigned comparisons as well.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11740 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 06:38:22 +00:00
Alkis Evlogimenos
12edc7ef3d Improved PhysRegTracker interface. RegAlloc lazily allocates the register tracker using a std::auto_ptr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11738 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 06:10:13 +00:00
Chris Lattner
fed58fd72e Implement mul.ll:test11
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11737 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 06:00:11 +00:00
Chris Lattner
45aaafef49 Implement "strength reduction" of X <= C and X >= C
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11735 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 05:47:48 +00:00
Chris Lattner
fb54b2b744 Implement InstCombine/mul.ll:test10, which is a case that occurs when dealing
with "predication"


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11734 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 05:39:21 +00:00
Alkis Evlogimenos
fc2b449a17 Simplify iterator usage now that we have next(). Also don't pass iterators by reference now that MachineInstr* are in an ilist
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11732 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 04:12:30 +00:00
Chris Lattner
f7b42259e9 Work around a gas bug. Print '-9223372036854775808' as unsigned.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11729 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 03:27:05 +00:00
Chris Lattner
311ca2e51f Implement cast fp -> bool
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11728 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 03:21:41 +00:00
Chris Lattner
baa58a5691 Stop passing iterators around by reference now that we have ilists!
Implement cast Type::ULongTy -> double


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11726 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 03:10:10 +00:00
Alkis Evlogimenos
25d9d5800c Some code cleanups from Chris
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11724 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 01:57:39 +00:00
Alkis Evlogimenos
534f545ef1 Fix comments in PhysRegTracker and rename isPhysRegAvail to isRegAvail to be consistent with the other two
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11723 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 01:25:05 +00:00
Chris Lattner
2d0a82570a Add a new cmove instruction
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11722 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 01:16:05 +00:00
Alkis Evlogimenos
98e17cf543 Move LiveIntervals.h up to be the first included header
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11721 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 01:01:21 +00:00
Alkis Evlogimenos
888b1a6ccd Pull PhysRegTracker out of RegAllocLinearScan as it can be used by other allocators as well
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11720 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 00:53:31 +00:00
Alkis Evlogimenos
a2f6a408dc Move LiveIntervals.h to lib/CodeGen since it shouldn't be exposed to other parts of the compiler
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11719 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-23 00:50:15 +00:00
Chris Lattner
986618ebc7 Only insert FP_REG_KILL instructions in MachineBasicBlocks that actually
use FP instructions.  This reduces the number of instructions inserted in
176.gcc (for example) from 58074 to 101 (it doesn't use much FP, which
is typical).  This reduction speeds up the entire code generator.  In the
case of 176.gcc, llc went from taking 31.38s to 24.78s.  The passes that
sped up the most are the register allocator and the 2 live variable analysis
passes, which sped up 2.3, 1.3, and 1.5s respectively.  The asmprinter
pass also sped up because it doesn't print the instructions in comments :)

Note that this patch is likely to expose latent bugs in machine code passes,
because now basicblock can be empty, where they were never empty before.  I
cleaned out regalloclocal, but who knows about linscan :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11717 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-22 19:47:26 +00:00