1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-22 20:43:44 +02:00
Commit Graph

1519 Commits

Author SHA1 Message Date
Reid Spencer
169865d831 Make this pass simply invoke SymbolTable::strip().
llvm-svn: 13749
2004-05-25 08:51:25 +00:00
Chris Lattner
66f55c8e78 Implement InstCombine:shift.ll:test16, which turns (X >> C1) & C2 != C3
into (X & (C2 << C1)) != (C3 << C1), where the shift may be either left or
right and the compare may be any one.

This triggers 1546 times in 176.gcc alone, as it is a common pattern that
occurs for bitfield accesses.

llvm-svn: 13740
2004-05-25 06:32:08 +00:00
Chris Lattner
b8fb5e789b Implement instcombine/cast.ll:test16:
Canonicalize cast X to bool into a setne instruction

llvm-svn: 13736
2004-05-25 04:29:21 +00:00
Chris Lattner
79409ebc27 Fix a bug in my previous checkin
llvm-svn: 13717
2004-05-24 06:24:46 +00:00
Chris Lattner
52e7345268 Spelling people's names right is kinda important
llvm-svn: 13702
2004-05-23 21:27:29 +00:00
Chris Lattner
fbdf40f86a Fix cases where we missed inlining some more obvious candidates because the
caller was in an SCC.

llvm-svn: 13693
2004-05-23 21:22:17 +00:00
Chris Lattner
bf8b81252f Simplify the interface and remove an unneeded #include
llvm-svn: 13692
2004-05-23 21:21:35 +00:00
Chris Lattner
fee8ce6131 Fairly substantial changes to update the alias analysis we are querying as
we make the transformation.  This allows us to use interprocedural alias
analyses successfully.

llvm-svn: 13691
2004-05-23 21:21:17 +00:00
Chris Lattner
cf81f974b8 Adjust to the changes in the AliasSetTracker interface
llvm-svn: 13690
2004-05-23 21:20:19 +00:00
Chris Lattner
33de90e8c6 Add support for replacement of formal arguments with simpler expressions.
llvm-svn: 13689
2004-05-23 21:19:55 +00:00
Chris Lattner
f113f6a630 Implement the -lowergc pass which is used by code generators (like the CBE)
that do not have builtin support for garbage collection.

llvm-svn: 13688
2004-05-23 21:19:22 +00:00
Brian Gaeke
16bd3c5d34 Add CloneTraceInto(), which is based on (and has mostly the same
effects as) CloneFunctionInto().

llvm-svn: 13601
2004-05-19 09:08:14 +00:00
Brian Gaeke
9adf9d8bfc Move RemapInstruction() to ValueMapper, so that it can be shared with
CloneTrace, and because it is primarily an operation on ValueMaps.  It
is now a global (non-static) function which can be pulled in using
ValueMapper.h.

llvm-svn: 13600
2004-05-19 09:08:12 +00:00
Brian Gaeke
b41b628afd Clean up this pass somewhat:
Add better comments, including a better head-of-file comment.
Prune #includes.
Fix a FIXME that Chris put here by using doInitialization().
Use DEBUG() to print out debug msgs.
Give names to basic blocks inserted by this pass.
Expand tabs.
Use InsertProfilingInitCall() from ProfilingUtils to insert the initialize call.

llvm-svn: 13581
2004-05-14 21:21:52 +00:00
Chris Lattner
729d1ba904 This was not meant to be committed
llvm-svn: 13565
2004-05-13 20:56:34 +00:00
Chris Lattner
b296747100 Fix a nasty bug that caused us to unroll EXTREMELY large loops due to overflow
in the size calculation.

This is not something you want to see:
Loop Unroll: F[main] Loop %no_exit Loop Size = 2 Trip Count = 2147483648 - UNROLLING!

The problem was that 2*2147483648 == 0.

Now we get:
Loop Unroll: F[main] Loop %no_exit Loop Size = 2 Trip Count = 2147483648 - TOO LARGE: 4294967296>100

Thanks to some anonymous person playing with the demo page that repeatedly
caused zion to go into swapping land.  That's one way to ensure you'll get
a quick bugfix.  :)

Testcase here: Transforms/LoopUnroll/2004-05-13-DontUnrollTooMuch.ll

llvm-svn: 13564
2004-05-13 20:43:31 +00:00
Chris Lattner
f97ef5191a Do not pass in the same argument to the extracted function more than once, and
give the extracted function a more useful name than just foo_code.

llvm-svn: 13493
2004-05-12 16:26:18 +00:00
Chris Lattner
645130ed0e Implement support for code extracting basic blocks that have a return
instruction in them.

llvm-svn: 13490
2004-05-12 16:07:41 +00:00
Chris Lattner
ed40ce44d6 Implement splitting of PHI nodes, allowing block extraction of BB's that have
PHI node entries from multiple outside-the-region blocks.  This also fixes
extraction of the entry block in a function.  Yaay.

This has successfully block extracted all (but one) block from the score_move
function in obsequi (out of 33).  Hrm, I wonder which block the bug is in.  :)

llvm-svn: 13489
2004-05-12 15:29:13 +00:00
Chris Lattner
3ee79b93d7 * Pull some code out into the definedInRegion/definedInCaller methods
* Add a stub for the severSplitPHINodes which will allow us to bbextract
  bb's with PHI nodes in them soon.
* Remove unused arguments from findInputsOutputs
* Dramatically simplify the code in findInputsOutputs.  In particular,
  nothing really cares whether or not a PHI node is using something.
* Move moveCodeToFunction to after emitCallAndSwitchStatement as that's the
  order they get called.
* Fix a bug where we would code extract a region that included a call to
  vastart.  Like 'alloca', calls to vastart must stay in the function that
  they are defined in.
* Add some comments.

llvm-svn: 13482
2004-05-12 06:01:40 +00:00
Chris Lattner
67e58adb41 Generate substantially better code when there are a limited number of exits
from the extracted region.  If the return has 0 or 1 exit blocks, the new
function returns void.  If it has 2 exits, it returns bool, otherwise it
returns a ushort as before.

This allows us to use a conditional branch instruction when there are two
exit blocks, as often happens during block extraction.

llvm-svn: 13481
2004-05-12 04:14:24 +00:00
Chris Lattner
7f4cd3b0be Two minor improvements:
1. Get rid of the silly abort block.  When doing bb extraction, we get one
     abort block for every block extracted, which is kinda annoying.
  2. If the switch ends up having a single destination, turn it into an
     unconditional branch.

I would like to add support for conditional branches, but to do this we will
want to have the function return a bool instead of a ushort.

llvm-svn: 13478
2004-05-12 03:22:33 +00:00
Chris Lattner
0efd1cb264 Fix stupid bug in my checkin yesterday
llvm-svn: 13429
2004-05-08 22:41:42 +00:00
Chris Lattner
e3b3e333b0 Implement folding of GEP's like:
%tmp.0 = getelementptr [50 x sbyte]* %ar, uint 0, int 5         ; <sbyte*> [#uses=2]
        %tmp.7 = getelementptr sbyte* %tmp.0, int 8             ; <sbyte*> [#uses=1]

together.  This patch actually allows us to simplify and generalize the code.

llvm-svn: 13415
2004-05-07 22:09:22 +00:00
Chris Lattner
6340390476 Fix PR336: The instcombine pass asserts when visiting load instruction
llvm-svn: 13400
2004-05-07 15:35:56 +00:00
Chris Lattner
05f657f5c2 Do not mark instructions in unreachable sections of the function as live.
This fixes PR332 and ADCE/2004-05-04-UnreachableBlock.llx

llvm-svn: 13349
2004-05-04 17:00:46 +00:00
Chris Lattner
7896144611 Minor efficiency tweak, suggested by Patrick Meredith
llvm-svn: 13341
2004-05-04 15:19:33 +00:00
Brian Gaeke
a5b32230db Fix typo
llvm-svn: 13340
2004-05-03 23:52:07 +00:00
Brian Gaeke
dcfc3c580e In InsertProfilingInitCall(), make it legal to pass in a null array, in
which case you'll get a null array and zero passed to the profiling function.

llvm-svn: 13336
2004-05-03 22:06:33 +00:00
Brian Gaeke
c8cd0e9092 Add initial implementation of basic-block tracing instrumentation pass.
llvm-svn: 13335
2004-05-03 22:06:32 +00:00
Chris Lattner
d8345001fa Do not clone arbitrary condition instructions.
llvm-svn: 13316
2004-05-02 05:19:36 +00:00
Chris Lattner
da2d746a3b Do not infinitely "unroll" single BB loops.
llvm-svn: 13315
2004-05-02 05:02:03 +00:00
Chris Lattner
5f393764c8 Dont' merge terminators that are needed to select PHI node values.
llvm-svn: 13312
2004-05-02 01:00:44 +00:00
Chris Lattner
bd705d7776 Implement SimplifyCFG/branch-cond-merge.ll
Turning "if (A < B && B < C)" into "if (A < B & B < C)"

llvm-svn: 13311
2004-05-01 23:35:43 +00:00
Chris Lattner
eb59aec632 Make sure to reprocess instructions used by deleted instructions to avoid
missing opportunities for combination.

llvm-svn: 13309
2004-05-01 23:27:23 +00:00
Chris Lattner
f5a5668cf6 Make sure the instruction combiner doesn't lose track of instructions
when replacing them, missing the opportunity to do simplifications

llvm-svn: 13308
2004-05-01 23:19:52 +00:00
Chris Lattner
911e21e8ca Fix my missing parens
llvm-svn: 13307
2004-05-01 22:41:51 +00:00
Chris Lattner
82278b599b Implement SimplifyCFG/branch-cond-prop.ll
llvm-svn: 13306
2004-05-01 22:36:37 +00:00
Chris Lattner
9b53c7c797 Fix a major pessimization in the instcombiner. If an allocation instruction
is only used by a cast, and the casted type is the same size as the original
allocation, it would eliminate the cast by folding it into the allocation.

Unfortunately, it was placing the new allocation instruction right before
the cast, which could pull (for example) alloca instructions into the body
of a function.  This turns statically allocatable allocas into expensive
dynamically allocated allocas, which is bad bad bad.

This fixes the problem by placing the new allocation instruction at the same
place the old one was, duh. :)

llvm-svn: 13289
2004-04-30 04:37:52 +00:00
Chris Lattner
02c65b5395 Changes to fix up the inst_iterator to pass to boost iterator checks. This
patch was graciously contributed by Vladimir Prus.

llvm-svn: 13185
2004-04-27 15:13:33 +00:00
Chris Lattner
5bad19bde7 Instcombine X/-1 --> 0-X
llvm-svn: 13172
2004-04-26 14:01:59 +00:00
Misha Brukman
144b5572e1 * Allow aggregating extracted function arguments (controlled by flag)
* Commandline option (for now) controls that flag that is passed in

llvm-svn: 13141
2004-04-23 23:54:17 +00:00
Chris Lattner
b72fa5f541 Move the scev expansion code into this pass, where it belongs. There is
still room for cleanup, but at least the code modification is out of the
analysis now.

llvm-svn: 13135
2004-04-23 21:29:48 +00:00
Misha Brukman
1dc8e19185 Clarify the logic: the flag is renamed to `deleteFn' to signify it will delete
the function instead of isolating it. This also means the condition is reversed.

llvm-svn: 13112
2004-04-22 23:00:51 +00:00
Misha Brukman
ddace6ecbe Add a flag to choose between isolating a function or deleting the function from
the Module. The default behavior keeps functionality as before: the chosen
function is the one that remains.

llvm-svn: 13111
2004-04-22 22:52:22 +00:00
Chris Lattner
6716bcd0cc Disable a previous patch that was causing indvars to loop infinitely :(
llvm-svn: 13108
2004-04-22 15:12:36 +00:00
Chris Lattner
507ba1c3c3 Fix an extremely serious thinko I made in revision 1.60 of this file.
llvm-svn: 13106
2004-04-22 14:59:40 +00:00
Chris Lattner
d1906e2ace Implement a todo, rewriting all possible scev expressions inside of the
loop.  This eliminates the extra add from the previous case, but it's
not clear that this will be a performance win overall.  Tommorows test
results will tell. :)

llvm-svn: 13103
2004-04-21 23:36:08 +00:00
Chris Lattner
96752d27f4 This code really wants to iterate over the OPERANDS of an instruction, not
over its USES.  If it's dead it doesn't have any uses!  :)

Thanks to the fabulous and mysterious Bill Wendling for pointing this out.  :)

llvm-svn: 13102
2004-04-21 22:29:37 +00:00
Chris Lattner
a3e2004609 Implement a fixme. The helps loops that have induction variables of different
types in them.  Instead of creating an induction variable for all types, it
creates a single induction variable and casts to the other sizes.  This generates
this code:

no_exit:                ; preds = %entry, %no_exit
        %indvar = phi uint [ %indvar.next, %no_exit ], [ 0, %entry ]            ; <uint> [#uses=4]
***     %j.0.0 = cast uint %indvar to short             ; <short> [#uses=1]
        %indvar = cast uint %indvar to int              ; <int> [#uses=1]
        %tmp.7 = getelementptr short* %P, uint %indvar          ; <short*> [#uses=1]
        store short %j.0.0, short* %tmp.7
        %inc.0 = add int %indvar, 1             ; <int> [#uses=2]
        %tmp.2 = setlt int %inc.0, %N           ; <bool> [#uses=1]
        %indvar.next = add uint %indvar, 1              ; <uint> [#uses=1]
        br bool %tmp.2, label %no_exit, label %loopexit

instead of:

no_exit:                ; preds = %entry, %no_exit
        %indvar = phi ushort [ %indvar.next, %no_exit ], [ 0, %entry ]          ; <ushort> [#uses=2]
***     %indvar = phi uint [ %indvar.next, %no_exit ], [ 0, %entry ]            ; <uint> [#uses=3]
        %indvar = cast uint %indvar to int              ; <int> [#uses=1]
        %indvar = cast ushort %indvar to short          ; <short> [#uses=1]
        %tmp.7 = getelementptr short* %P, uint %indvar          ; <short*> [#uses=1]
        store short %indvar, short* %tmp.7
        %inc.0 = add int %indvar, 1             ; <int> [#uses=2]
        %tmp.2 = setlt int %inc.0, %N           ; <bool> [#uses=1]
        %indvar.next = add uint %indvar, 1
***     %indvar.next = add ushort %indvar, 1
        br bool %tmp.2, label %no_exit, label %loopexit

This is an improvement in register pressure, but probably doesn't happen that
often.

The more important fix will be to get rid of the redundant add.

llvm-svn: 13101
2004-04-21 22:22:01 +00:00
Chris Lattner
7d02bae5d8 Fix an incredibly nasty iterator invalidation problem. I am too spoiled by ilists :)
Eventually it would be nice if CallGraph maintained an ilist of CallGraphNode's instead
of a vector of pointers to them, but today is not that day.

llvm-svn: 13100
2004-04-21 20:44:33 +00:00
Alkis Evlogimenos
904f4f9a21 Include cerrno (gcc-3.4 fix)
llvm-svn: 13091
2004-04-21 16:11:40 +00:00
Chris Lattner
ade6ddc694 Fix typeo
llvm-svn: 13089
2004-04-21 14:23:18 +00:00
Chris Lattner
15eb3c1f39 REALLY fix PR324: don't delete linkonce functions until after the SCC traversal
is done, which avoids invalidating iterators in the SCC traversal routines

llvm-svn: 13088
2004-04-20 22:06:53 +00:00
Chris Lattner
602146eea1 Fix PR325
llvm-svn: 13081
2004-04-20 20:26:03 +00:00
Chris Lattner
5a1e3f099f Fix PR324 and testcase: Inline/2004-04-20-InlineLinkOnce.llx
llvm-svn: 13080
2004-04-20 20:20:59 +00:00
Chris Lattner
29f69938e7 Initial checkin of a simple loop unswitching pass. It still needs work,
but it's a start, and seems to do it's basic job.

llvm-svn: 13068
2004-04-19 18:07:02 +00:00
Chris Lattner
1849aa8b1f Add #include
llvm-svn: 13057
2004-04-19 03:01:23 +00:00
Chris Lattner
ab6502f058 Move isLoopInvariant to the Loop class
llvm-svn: 13051
2004-04-18 22:46:08 +00:00
Chris Lattner
5a0ed18724 Correct rewriting of exit blocks after my last patch
llvm-svn: 13048
2004-04-18 22:27:10 +00:00
Chris Lattner
8e42c6f409 Loop exit sets are no longer explicitly held, they are dynamically computed on demand.
llvm-svn: 13046
2004-04-18 22:15:13 +00:00
Chris Lattner
7174acca00 Change the ExitBlocks list from being explicitly contained in the Loop
structure to being dynamically computed on demand.  This makes updating
loop information MUCH easier.

llvm-svn: 13045
2004-04-18 22:14:10 +00:00
Chris Lattner
13140766df Reduce the unrolling limit
llvm-svn: 13040
2004-04-18 18:06:14 +00:00
Chris Lattner
430968ac2f If the preheader of the loop was the entry block of the function, make sure
that the exit block of the loop becomes the new entry block of the function.

This was causing a verifier assertion on 252.eon.

llvm-svn: 13039
2004-04-18 17:38:42 +00:00
Chris Lattner
199b58db3f Be much more careful about how we update instructions outside of the loop
using instructions inside of the loop.  This should fix the MishaTest failure
from last night.

llvm-svn: 13038
2004-04-18 17:32:39 +00:00
Chris Lattner
33ec7f2f9f After unrolling our single basic block loop, fold it into the preheader and exit
block.  The primary motivation for doing this is that we can now unroll nested loops.

This makes a pretty big difference in some cases.  For example, in 183.equake,
we are now beating the native compiler with the CBE, and we are a lot closer
with LLC.

I'm now going to play around a bit with the unroll factor and see what effect
it really has.

llvm-svn: 13034
2004-04-18 06:27:43 +00:00
Chris Lattner
f2045a8c05 Fix a bug: this does not preserve the CFG!
While we're at it, add support for updating loop information correctly.

llvm-svn: 13033
2004-04-18 05:38:37 +00:00
Chris Lattner
b0d23bf99d Initial checkin of a simple loop unroller. This pass is extremely basic and
limited.  Even in it's extremely simple state (it can only *fully* unroll single
basic block loops that execute a constant number of times), it already helps improve
performance a LOT on some benchmarks, particularly with the native code generators.

llvm-svn: 13028
2004-04-18 05:20:17 +00:00
Chris Lattner
e0f56972f0 Make the tail duplication threshold accessible from the command line instead of hardcoded
llvm-svn: 13025
2004-04-18 00:52:43 +00:00
Chris Lattner
740ae78ae6 If the loop executes a constant number of times, try a bit harder to replace
exit values.

llvm-svn: 13018
2004-04-17 18:44:09 +00:00
Chris Lattner
bcb690dc9b Fix a HUGE pessimization on X86. The indvars pass was taking this
(familiar) function:

int _strlen(const char *str) {
    int len = 0;
    while (*str++) len++;
    return len;
}

And transforming it to use a ulong induction variable, because the type of
the pointer index was left as a constant long.  This is obviously very bad.

The fix is to shrink long constants in getelementptr instructions to intptr_t,
making the indvars pass insert a uint induction variable, which is much more
efficient.

Here's the before code for this function:

int %_strlen(sbyte* %str) {
entry:
        %tmp.13 = load sbyte* %str              ; <sbyte> [#uses=1]
        %tmp.24 = seteq sbyte %tmp.13, 0                ; <bool> [#uses=1]
        br bool %tmp.24, label %loopexit, label %no_exit

no_exit:                ; preds = %entry, %no_exit
***     %indvar = phi uint [ %indvar.next, %no_exit ], [ 0, %entry ]            ; <uint> [#uses=2]
***     %indvar = phi ulong [ %indvar.next, %no_exit ], [ 0, %entry ]           ; <ulong> [#uses=2]
        %indvar1 = cast ulong %indvar to uint           ; <uint> [#uses=1]
        %inc.02.sum = add uint %indvar1, 1              ; <uint> [#uses=1]
        %inc.0.0 = getelementptr sbyte* %str, uint %inc.02.sum          ; <sbyte*> [#uses=1]
        %tmp.1 = load sbyte* %inc.0.0           ; <sbyte> [#uses=1]
        %tmp.2 = seteq sbyte %tmp.1, 0          ; <bool> [#uses=1]
        %indvar.next = add ulong %indvar, 1             ; <ulong> [#uses=1]
        %indvar.next = add uint %indvar, 1              ; <uint> [#uses=1]
        br bool %tmp.2, label %loopexit.loopexit, label %no_exit

loopexit.loopexit:              ; preds = %no_exit
        %indvar = cast uint %indvar to int              ; <int> [#uses=1]
        %inc.1 = add int %indvar, 1             ; <int> [#uses=1]
        ret int %inc.1

loopexit:               ; preds = %entry
        ret int 0
}


Here's the after code:

int %_strlen(sbyte* %str) {
entry:
        %inc.02 = getelementptr sbyte* %str, uint 1             ; <sbyte*> [#uses=1]
        %tmp.13 = load sbyte* %str              ; <sbyte> [#uses=1]
        %tmp.24 = seteq sbyte %tmp.13, 0                ; <bool> [#uses=1]
        br bool %tmp.24, label %loopexit, label %no_exit

no_exit:                ; preds = %entry, %no_exit
***     %indvar = phi uint [ %indvar.next, %no_exit ], [ 0, %entry ]            ; <uint> [#uses=3]
        %indvar = cast uint %indvar to int              ; <int> [#uses=1]
        %inc.0.0 = getelementptr sbyte* %inc.02, uint %indvar           ; <sbyte*> [#uses=1]
        %inc.1 = add int %indvar, 1             ; <int> [#uses=1]
        %tmp.1 = load sbyte* %inc.0.0           ; <sbyte> [#uses=1]
        %tmp.2 = seteq sbyte %tmp.1, 0          ; <bool> [#uses=1]
        %indvar.next = add uint %indvar, 1              ; <uint> [#uses=1]
        br bool %tmp.2, label %loopexit, label %no_exit

loopexit:               ; preds = %entry, %no_exit
        %len.0.1 = phi int [ 0, %entry ], [ %inc.1, %no_exit ]          ; <int> [#uses=1]
        ret int %len.0.1
}

llvm-svn: 13016
2004-04-17 18:16:10 +00:00
Chris Lattner
5c85946417 Even if there are not any induction variables in the loop, if we can compute
the trip count for the loop, insert one so that we can canonicalize the exit
condition.

llvm-svn: 13015
2004-04-17 18:08:33 +00:00
Chris Lattner
6d5decd7d4 Add support for evaluation of exp/log/log10/pow
llvm-svn: 13011
2004-04-16 22:35:33 +00:00
Chris Lattner
ed423cc09d Fix some really nasty dominance bugs that were exposed by my patch to
make the verifier more strict.  This fixes building zlib

llvm-svn: 13002
2004-04-16 18:08:07 +00:00
Brian Gaeke
4b9f67c638 Include <cmath> for compatibility with gcc 3.0.x (the system compiler on
Debian.)

llvm-svn: 12986
2004-04-16 15:57:32 +00:00
Chris Lattner
bc458be5f9 Fix some of the strange CBE-only failures that happened last night.
llvm-svn: 12980
2004-04-16 06:03:17 +00:00
Chris Lattner
06eda01d1b Fix Inline/2004-04-15-InlineDeletesCall.ll
Basically we were using SimplifyCFG as a huge sledgehammer for a simple
optimization.  Because simplifycfg does so many things, we can't use it
for this purpose.

llvm-svn: 12977
2004-04-16 05:17:59 +00:00
Chris Lattner
ac2b465cb4 Fix a bug in the previous checkin: if the exit block is not the same as
the back-edge block, we must check the preincremented value.

llvm-svn: 12968
2004-04-15 20:26:22 +00:00
Chris Lattner
dcf2ca93e6 Change the canonical induction variable that we insert.
Instead of producing code like this:

Loop:
  X = phi 0, X2
  ...

  X2 = X + 1
  if (X != N-1) goto Loop

We now generate code that looks like this:

Loop:
  X = phi 0, X2
  ...

  X2 = X + 1
  if (X2 != N) goto Loop

This has two big advantages:
  1. The trip count of the loop is now explicit in the code, allowing
     the direct implementation of Loop::getTripCount()
  2. This reduces register pressure in the loop, and allows X and X2 to be
     put into the same register.

As a consequence of the second point, the code we generate for loops went
from:

.LBB2:  # no_exit.1
	...
        mov %EDI, %ESI
        inc %EDI
        cmp %ESI, 2
        mov %ESI, %EDI
        jne .LBB2 # PC rel: no_exit.1

To:

.LBB2:  # no_exit.1
	...
        inc %ESI
        cmp %ESI, 3
        jne .LBB2 # PC rel: no_exit.1

... which has two fewer moves, and uses one less register.

llvm-svn: 12961
2004-04-15 15:21:43 +00:00
Chris Lattner
6fcf8c7402 ADd a trivial instcombine: load null -> null
llvm-svn: 12940
2004-04-14 03:28:36 +00:00
Chris Lattner
545e77c9d5 Add SCCP support for constant folding calls, implementing:
test/Regression/Transforms/SCCP/calltest.ll

llvm-svn: 12921
2004-04-13 19:43:54 +00:00
Chris Lattner
778f09027f Add a simple call constant propagation interface.
llvm-svn: 12919
2004-04-13 19:28:52 +00:00
Chris Lattner
8c0e9c95e9 Constant propagation should remove the dead instructions
llvm-svn: 12917
2004-04-13 19:28:20 +00:00
Chris Lattner
70f6a0ddcf Fix LoopSimplify/2004-04-13-LoopSimplifyUpdateDomFrontier.ll
LoopSimplify was not updating dominator frontiers correctly in some cases.

llvm-svn: 12890
2004-04-13 16:23:25 +00:00
Chris Lattner
ae63c235f9 Refactor code a bit to make it simpler and eliminate the goto
llvm-svn: 12888
2004-04-13 15:21:18 +00:00
Chris Lattner
faf377df58 This patch addresses PR35: Loop simplify should reconstruct nested loops.
This is fairly straight-forward, but was a real nightmare to get just
perfect.  aarg.  :)

llvm-svn: 12884
2004-04-13 05:05:33 +00:00
Chris Lattner
a3d3872a88 Actually update the call graph as the inliner changes it. This allows us to
execute other CallGraphSCCPasses after the inliner without crashing.

llvm-svn: 12861
2004-04-12 05:37:29 +00:00
Chris Lattner
603d821596 Add support for removing invoke instructions
llvm-svn: 12858
2004-04-12 05:15:13 +00:00
Chris Lattner
af22e5f826 Stop printing Function*
llvm-svn: 12857
2004-04-12 04:06:56 +00:00
Chris Lattner
1c83ee0436 Simplify code a bit, and be sure to mark the external node as potentially throwing
llvm-svn: 12856
2004-04-12 04:06:38 +00:00
Chris Lattner
ca1428e01c Fix a bug in my select transformation
llvm-svn: 12826
2004-04-11 01:39:19 +00:00
Chris Lattner
777977bf2e Update the value numbering interface.
llvm-svn: 12824
2004-04-10 22:33:34 +00:00
Chris Lattner
96fca8de3d Implement InstCombine/select.ll:test13*
llvm-svn: 12821
2004-04-10 22:21:27 +00:00
Chris Lattner
618c89d5eb Implement InstCombine/add.ll:test20
Canonicalize add of sign bit constant into a xor

llvm-svn: 12819
2004-04-10 22:01:55 +00:00
Chris Lattner
6d569b52ed Rewrite the GCSE pass to be *substantially* simpler, a bit more efficient,
and a bit more powerful

llvm-svn: 12817
2004-04-10 21:11:11 +00:00
Chris Lattner
22c22de2f0 Fix spurious warning in release mode
llvm-svn: 12816
2004-04-10 19:15:56 +00:00
Chris Lattner
924b6c173c Simplify code a bit, and fix a bug that was breaking perlbmk
llvm-svn: 12814
2004-04-10 18:06:21 +00:00
Chris Lattner
f126f03878 Fix a bug in my checkin last night that was breaking programs using invoke.
llvm-svn: 12813
2004-04-10 16:53:29 +00:00
Chris Lattner
d4979e2904 Fix previous patch
llvm-svn: 12811
2004-04-10 07:27:48 +00:00
Chris Lattner
3b211f0432 Correctly update counters
llvm-svn: 12810
2004-04-10 07:02:02 +00:00
Chris Lattner
1676188024 Simplify code a bit, and use alias analysis to allow us to delete unused
call and invoke instructions that are known to not write to memory.

llvm-svn: 12807
2004-04-10 06:53:09 +00:00
Chris Lattner
306540a2f4 Implement select.ll:test12*
This transforms code like this:

   %C = or %A, %B
   %D = select %cond, %C, %A
into:
   %C = select %cond, %B, 0
   %D = or %A, %C

Since B is often a constant, the select can often be eliminated.  In any case,
this reduces the usage count of A, allowing subsequent optimizations to happen.

This xform applies when the operator is any of:
  add, sub, mul, or, xor, and, shl, shr

llvm-svn: 12800
2004-04-09 23:46:01 +00:00
Chris Lattner
8ccddbd123 Fold code like:
if (C)
    V1 |= V2;

into:
  Vx = V1 | V2;
  V1 = select C, V1, Vx

when the expression can be evaluated unconditionally and is *cheap* to
execute.  This limited form of if conversion is quite handy in lots of cases.
For example, it turns this testcase into straight-line code:

int in0 ; int in1 ; int in2 ; int in3 ;
int in4 ; int in5 ; int in6 ; int in7 ;
int in8 ; int in9 ; int in10; int in11;
int in12; int in13; int in14; int in15;
long output;

void mux(void) {
  output =
      (in0   ?  0x00000001 : 0) | (in1   ?  0x00000002 : 0) |
      (in2   ?  0x00000004 : 0) | (in3   ?  0x00000008 : 0) |
      (in4   ?  0x00000010 : 0) | (in5   ?  0x00000020 : 0) |
      (in6   ?  0x00000040 : 0) | (in7   ?  0x00000080 : 0) |
      (in8   ?  0x00000100 : 0) | (in9   ?  0x00000200 : 0) |
      (in10  ?  0x00000400 : 0) | (in11  ?  0x00000800 : 0) |
      (in12  ?  0x00001000 : 0) | (in13  ?  0x00002000 : 0) |
      (in14  ?  0x00004000 : 0) | (in15  ?  0x00008000 : 0) ;
}

llvm-svn: 12798
2004-04-09 22:50:22 +00:00
Chris Lattner
3a6e4b9a35 Fold binary operators with a constant operand into select instructions
that have a constant operand.  This implements
add.ll:test19, shift.ll:test15*, and others that are not tested

llvm-svn: 12794
2004-04-09 19:05:30 +00:00
Chris Lattner
0e1f5553df Implement select.ll:test11
llvm-svn: 12793
2004-04-09 18:19:44 +00:00
Chris Lattner
0ca3cbfa5e Implement InstCombine/cast-propagate.ll
llvm-svn: 12784
2004-04-08 20:39:49 +00:00
Chris Lattner
d8efae05fe Implement ScalarRepl/select_promote.ll
llvm-svn: 12779
2004-04-08 19:59:34 +00:00
Chris Lattner
77beb73ce2 Remove the "really gross hacks" that are there to deal with recursive functions.
Now we collect all of the call sites we are interested in inlining, then inline
them.  This entirely avoids issues with trying to inline a call site we got by
inlining another call site.  This also eliminates iterator invalidation issues.

llvm-svn: 12770
2004-04-08 06:34:31 +00:00
Chris Lattner
cf8117ccbd Implement InstCombine/select.ll:test[7-10]
llvm-svn: 12769
2004-04-08 04:43:23 +00:00
Chris Lattner
2e89e48999 Implement test/Regression/Transforms/InstCombine/getelementptr_index.ll
llvm-svn: 12762
2004-04-07 18:38:20 +00:00
Chris Lattner
c92af54ed5 Fix a bug in yesterdays checkins which broke siod. siod is a great testcase! :)
llvm-svn: 12659
2004-04-05 16:02:41 +00:00
Chris Lattner
6c961339a3 Fix InstCombine/2004-04-04-InstCombineReplaceAllUsesWith.ll
llvm-svn: 12658
2004-04-05 02:10:19 +00:00
Chris Lattner
9236135e8f Support getelementptr instructions which use uint's to index into structure
types and can have arbitrary 32- and 64-bit integer types indexing into
sequential types.

llvm-svn: 12653
2004-04-05 01:30:19 +00:00
Chris Lattner
cf5bd8a9ab Rewrite the indvars pass to use the ScalarEvolution analysis.
This also implements some new features for the indvars pass, including
linear function test replacement, exit value substitution, and it works with
a much more general class of induction variables and loops.

llvm-svn: 12620
2004-04-02 20:24:31 +00:00
Chris Lattner
3f202e3a54 Fix the obvious bug in my previous checkin
llvm-svn: 12618
2004-04-02 18:15:10 +00:00
Chris Lattner
bca948c99d Implement Transforms/SimplifyCFG/return-merge.ll
This actually causes us to turn code like:

  return C ? A : B;

into a select instruction.

llvm-svn: 12617
2004-04-02 18:13:43 +00:00
Chris Lattner
973cb73b4f Fix PR310 and TailDup/2004-04-01-DemoteRegToStack.llx
llvm-svn: 12597
2004-04-01 20:28:45 +00:00
Chris Lattner
441ab4b903 Remove some assertions that are now bogus with the last patch I put in
llvm-svn: 12595
2004-04-01 19:21:46 +00:00
Chris Lattner
eda638b0be Fix PR306: Loop simplify incorrectly updates dominator information
Testcase: LoopSimplify/2004-04-01-IncorrectDomUpdate.ll

llvm-svn: 12592
2004-04-01 19:06:07 +00:00
Chris Lattner
6aaea5f86b Add warning
llvm-svn: 12573
2004-03-31 22:00:30 +00:00
Chris Lattner
1c0ddbfb7d Fix linking of constant expr casts due to type resolution changes. With
this and the other patches 253.perlbmk links again.

llvm-svn: 12565
2004-03-31 02:58:28 +00:00
Brian Gaeke
59c80cfd05 Start cleaning up this pass so that I can debug it.
llvm-svn: 12548
2004-03-30 19:53:46 +00:00
Chris Lattner
145aea5c4c Now that all the code generators support the select instruction, and the instcombine
pass can eliminate many nasty cases of them, start generating them in the optimizers

llvm-svn: 12545
2004-03-30 19:44:05 +00:00
Chris Lattner
b6612acb18 Implement select.ll:test[3-6]
llvm-svn: 12544
2004-03-30 19:37:13 +00:00
Chris Lattner
58a6a4d57a Add a simple select instruction lowering pass
llvm-svn: 12540
2004-03-30 18:41:10 +00:00
Chris Lattner
d191e5625c X % -1 == X % 1 == 0
llvm-svn: 12520
2004-03-26 16:11:24 +00:00
Chris Lattner
e15fb6ac61 Two changes:
#1 is to unconditionally strip constantpointerrefs out of
instruction operands where they are absolutely pointless and inhibit
optimization.  GRRR!

#2 is to implement InstCombine/getelementptr_const.ll

llvm-svn: 12519
2004-03-25 22:59:29 +00:00
Chris Lattner
078f97b50d Teach the optimizer to delete zero sized alloca's (but not mallocs!)
llvm-svn: 12507
2004-03-19 06:08:10 +00:00
Chris Lattner
0f0a253571 Fix bug: CodeExtractor/2004-03-17-MissedLiveIns.ll
With this fix we now successfully extract all 149 loops from 256.bzip2 without
crashing or miscompiling the program!

llvm-svn: 12493
2004-03-18 05:56:32 +00:00
Chris Lattner
521d687d11 Add statistics to the loop extractor. The loop extractor has successfully
extracted all 63 loops for Olden/bh without crashing and without
miscompiling the program!!!

llvm-svn: 12491
2004-03-18 05:46:10 +00:00
Chris Lattner
c835211d82 Fix problem with PHI nodes having multiple predecessors from different
exit nodes

llvm-svn: 12490
2004-03-18 05:43:18 +00:00
Chris Lattner
b1bc514730 Fix CodeExtractor/2004-03-17-UpdatePHIsOutsideRegion.ll
llvm-svn: 12489
2004-03-18 05:38:31 +00:00
Chris Lattner
69fdd9f14a Seriously simplify and correct the PHI node handling code.
llvm-svn: 12487
2004-03-18 05:28:49 +00:00
Chris Lattner
345cf6f177 Fix CodeExtractor/2004-03-17-OutputMismatch.ll
llvm-svn: 12486
2004-03-18 04:12:05 +00:00
Chris Lattner
0d233c03fc Fix several bugs in the extractor:
1. Names were not put on the new arguments created (ok, this just helps sanity :)
2. Fix outgoing pointer values
3. Do not insert stores for values that had not been computed
4. Fix some wierd problems with the outset calculation

This fixes CodeExtractor/2004-03-14-DominanceProblem.ll, making the extractor
work on at least one simple case!

llvm-svn: 12484
2004-03-18 03:49:40 +00:00
Chris Lattner
55114016ea The code extractor needs dominator info. Provide it
llvm-svn: 12483
2004-03-18 03:48:06 +00:00
Chris Lattner
7c0d39dcd6 Prune #includes, moving the module interface to the front. Note that this
exposed the fact that the header was not self-contained.  There is a reason
we do things :)

llvm-svn: 12481
2004-03-18 03:15:29 +00:00
Chris Lattner
849234af99 Fix compilation of mesa, which I broke earlier today
llvm-svn: 12465
2004-03-17 02:02:47 +00:00
Chris Lattner
eccc0e01b2 Be more accurate
llvm-svn: 12464
2004-03-17 01:59:27 +00:00
Chris Lattner
6fdcd7174b Fix bug in previous checkin
llvm-svn: 12458
2004-03-16 23:36:49 +00:00
Chris Lattner
59342a757e Okay, so there is no reasonable way for tail duplication to update SSA form,
as it is making effectively arbitrary modifications to the CFG and we don't
have a domset/domfrontier implementations that can handle the dynamic updates.
Instead of having a bunch of code that doesn't actually work in practice,
just demote any potentially tricky values to the stack (causing the problem
to go away entirely).  Later invocations of mem2reg will rebuild SSA for us.

This fixes all of the major performance regressions with tail duplication
from LLVM 1.1.  For example, this loop:

---
int popcount(int x) {
  int result = 0;
  while (x != 0) {
    result = result + (x & 0x1);
    x = x >> 1;
  }
  return result;
}
---
Used to be compiled into:

int %popcount(int %X) {
entry:
	br label %loopentry

loopentry:		; preds = %entry, %no_exit
	%x.0 = phi int [ %X, %entry ], [ %tmp.9, %no_exit ]		; <int> [#uses=3]
	%result.1.0 = phi int [ 0, %entry ], [ %tmp.6, %no_exit ]		; <int> [#uses=2]
	%tmp.1 = seteq int %x.0, 0		; <bool> [#uses=1]
	br bool %tmp.1, label %loopexit, label %no_exit

no_exit:		; preds = %loopentry
	%tmp.4 = and int %x.0, 1		; <int> [#uses=1]
	%tmp.6 = add int %tmp.4, %result.1.0		; <int> [#uses=1]
	%tmp.9 = shr int %x.0, ubyte 1		; <int> [#uses=1]
	br label %loopentry

loopexit:		; preds = %loopentry
	ret int %result.1.0
}

And is now compiled into:

int %popcount(int %X) {
entry:
        br label %no_exit

no_exit:                ; preds = %entry, %no_exit
        %x.0.0 = phi int [ %X, %entry ], [ %tmp.9, %no_exit ]          ; <int> [#uses=2]
        %result.1.0.0 = phi int [ 0, %entry ], [ %tmp.6, %no_exit ]             ; <int> [#uses=1]
        %tmp.4 = and int %x.0.0, 1              ; <int> [#uses=1]
        %tmp.6 = add int %tmp.4, %result.1.0.0          ; <int> [#uses=2]
        %tmp.9 = shr int %x.0.0, ubyte 1                ; <int> [#uses=2]
        %tmp.1 = seteq int %tmp.9, 0            ; <bool> [#uses=1]
        br bool %tmp.1, label %loopexit, label %no_exit

loopexit:               ; preds = %no_exit
        ret int %tmp.6
}

llvm-svn: 12457
2004-03-16 23:29:09 +00:00
Chris Lattner
e04883605a This code was both incredibly complex and incredibly broken. Fix it.
llvm-svn: 12456
2004-03-16 23:23:11 +00:00
Chris Lattner
c260cfab09 Punt if we see gigantic PHI nodes. This improves a huge interpreter loop
testcase from 32.5s in -raise to take .3s

llvm-svn: 12443
2004-03-16 19:52:53 +00:00
Chris Lattner
dc22f37eb5 Do not try to optimize PHI nodes with incredibly high degree. This reduces SCCP
time from 615s to 1.49s on a large testcase that has a gigantic switch statement
that all of the blocks in the function go to (an intepreter).

llvm-svn: 12442
2004-03-16 19:49:59 +00:00
Chris Lattner
2175b35b46 Do not copy gigantic switch instructions
llvm-svn: 12441
2004-03-16 19:45:22 +00:00
Chris Lattner
9ae2b6acd7 Fix a regression from this patch:
http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20040308/013095.html

Basically, this patch only updated the immediate dominatees of the header node
to tell them that the preheader also dominated them.  In practice, ALL
dominatees of the header node are also dominated by the preheader.

This fixes: LoopSimplify/2004-03-15-IncorrectDomUpdate.
and PR293

llvm-svn: 12434
2004-03-16 06:00:15 +00:00
Chris Lattner
b9c53cdb65 Restore old inlining heuristic. As the comment indicates, this is a nasty
horrible hack.

llvm-svn: 12423
2004-03-15 06:38:14 +00:00
Chris Lattner
d8905ad834 Add counters for the number of calls elimianted
llvm-svn: 12420
2004-03-15 05:46:59 +00:00
Chris Lattner
8a82176edc Implement LICM of calls in simple cases. This is sufficient to move around
sin/cos/strlen calls and stuff.  This implements:
  LICM/call_sink_pure_function.ll
  LICM/call_sink_const_function.ll

llvm-svn: 12415
2004-03-15 04:11:30 +00:00
Chris Lattner
781ede7382 Mostly cosmetic improvements. Do fix the bug where a global value was considered an input.
llvm-svn: 12406
2004-03-15 01:26:44 +00:00