Commit Graph

1749 Commits

Author SHA1 Message Date
Chris Lattner
eb6f18fe7c Add value mapper support for select constant exprs. This should fix a bug
Nate ran into when bugpointing siod.  This fix should go into LLVM 1.3


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15712 91177308-0d34-0410-b5e6-96231b3b80d8
2004-08-13 02:43:19 +00:00
Chris Lattner
ee45f4cbe4 This patch makes the inliner refuse to inline functions that have alloca
instructions in the body of the function (not the entry block).  This fixes
test/Programs/SingleSource/Regression/C/2004-08-12-InlinerAndAllocas.c
and test/Programs/External/SPEC/CINT2000/176.gcc on zion.

This should obviously be pulled into 1.3.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15684 91177308-0d34-0410-b5e6-96231b3b80d8
2004-08-12 05:45:09 +00:00
Chris Lattner
b519efbafe Fix code extraction of unwind blocks. This fixed bugs that bugpoint can
run into.  This should go into 1.3


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15679 91177308-0d34-0410-b5e6-96231b3b80d8
2004-08-12 03:17:02 +00:00
Chris Lattner
a5de823844 Hrm, this pass didn't compile. This bugfix should go into 1.3!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15676 91177308-0d34-0410-b5e6-96231b3b80d8
2004-08-12 02:44:23 +00:00
Chris Lattner
5dbef2207e Fix InstCombine/2004-08-10-BoolSetCC.ll, a bug that is miscompiling
176.gcc.  Note that this is apparently not the only bug miscompiling gcc
though. :(


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15639 91177308-0d34-0410-b5e6-96231b3b80d8
2004-08-11 00:50:51 +00:00
Chris Lattner
b49f306bdf Fix InstCombine/2004-08-09-RemInfLoop.llx
This should go into the 1.3 branch


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15593 91177308-0d34-0410-b5e6-96231b3b80d8
2004-08-09 21:05:48 +00:00
Chris Lattner
54970c0328 Fix another really nasty regression that Anshu pointed out. In cases where
dangling constant users were removed from a function, causing it to be dead,
we never removed the call graph edge from the external node to the function.

In most cases, this didn't cause a problem (by luck).  This should definitely
go into 1.3


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15570 91177308-0d34-0410-b5e6-96231b3b80d8
2004-08-08 03:29:50 +00:00
Chris Lattner
68392422e6 Two fixes:
1. Fix a REALLY nasty cyclic replacement issue that Anshu discovered, causing
   nondeterminstic crashes and memory corruption.
2. For performance, don't go inserting constantexpr casts of GV pointers.

This should definitely go into 1.3


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15568 91177308-0d34-0410-b5e6-96231b3b80d8
2004-08-08 01:30:07 +00:00
Chris Lattner
5e2e27284b This DEBUG is buggy. comment it out because it's not worth fixing. This
should go into 1.3


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15567 91177308-0d34-0410-b5e6-96231b3b80d8
2004-08-08 01:27:56 +00:00
Alkis Evlogimenos
15876bb28c Stop using getValues().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15487 91177308-0d34-0410-b5e6-96231b3b80d8
2004-08-04 08:44:43 +00:00
Chris Lattner
1484089bbf Fix a regression in InstCombine/xor.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15410 91177308-0d34-0410-b5e6-96231b3b80d8
2004-08-01 19:42:59 +00:00
Chris Lattner
1e5fdf8ba0 Expose this as a functionpass
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15369 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-31 10:01:58 +00:00
Misha Brukman
cb6267bc60 Fix De Morgan's name.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15343 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-30 12:50:08 +00:00
Chris Lattner
acd1f0fcb3 Start using the PatternMatcher a bit.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15342 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-30 07:50:03 +00:00
Misha Brukman
78c038d0cc Fix #includes of i*.h => Instructions.h as per PR403.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15337 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-29 17:30:57 +00:00
Misha Brukman
47b14a4a6a Fix #includes of i*.h => Instructions.h as per PR403.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15334 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-29 17:30:56 +00:00
Misha Brukman
d8e1eea678 Fix #includes of i*.h => Instructions.h as per PR403.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15328 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-29 17:05:13 +00:00
Alkis Evlogimenos
eb62bc77b6 Merge i*.h headers into Instructions.h as part of bug403.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15325 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-29 12:17:34 +00:00
Robert Bocchino
71698285e8 This change fixed a bug in the function visitMul. The prior version
assumed that a constant on the RHS of a multiplication was either an
IntConstant or an FPConstant.  It checked for an IntConstant and then,
if it did not find one, did a hard cast to an FPConstant.  That code
would crash if the RHS were a ConstantExpr that was neither an
IntConstant nor an FPConstant.  This version replaces the hard cast
with a dyn_cast.  It performs the same way for IntConstants and
FPConstants but does nothing, instead of crashing, for constant
expressions.

The regression test for this change is 2004-07-27-ConstantExprMul.ll.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15291 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-27 21:02:21 +00:00
Brian Gaeke
96d4bf7aee Make the create...() functions for some of these passes return a FunctionPass *.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15276 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-27 17:43:21 +00:00
Chris Lattner
eaa243039b Fix hoisting of void typed values, e.g. calls
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15263 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-27 07:38:32 +00:00
Chris Lattner
a000279a7d Implement DeadStoreElim/alloca.llx by observing that allocas are dead at the
end of the function (either return or unwind)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15232 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-26 06:14:11 +00:00
Chris Lattner
595ee7ec26 Throttle back indvar substitution from creating multiplies in loops. This is bad bad bad.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15227 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-26 02:47:12 +00:00
Chris Lattner
70e9b59b0e * Substantially simplify how free instructions are handled (potentially fixing
a bug in DSE).
* Delete dead operand uses iteratively instead of recursively, using a
  SetVector.
* Defer deletion of dead operand uses until the end of processing, which means
  we don't have to bother with updating the AliasSetTracker.  This speeds up
  DSE substantially.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15204 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-25 11:09:56 +00:00
Chris Lattner
a9e2f3d0ab Free instructions kill values too. This implements DeadStoreElim/free.llx
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15199 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-25 07:58:38 +00:00
Chris Lattner
c47b6677ae obvious fix
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15162 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-24 07:51:27 +00:00
Chris Lattner
0fb56afab1 This is a trivial dead store elimination pass. It very very simple and
can be improved in many ways.  But: stop laughing, even with -basicaa it
deletes 15% of the stores in 252.eon :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15101 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-22 08:00:28 +00:00
Chris Lattner
93c9587fbb Update GC intrinsics to take a pointer to the object as well as a pointer
to the field being updated.  Patch contributed by Tobias Nurmiranta


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15097 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-22 05:51:13 +00:00
Brian Gaeke
7848e68c16 These files don't need to include <iostream> since they include "Support/Debug.h".
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15089 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-21 20:50:33 +00:00
Chris Lattner
f0cacc0ae7 * Further cleanup.
* Test for whether bits are shifted out during the optzn.

If so, the fold is illegal, though it can be handled explicitly for setne/seteq

This fixes the miscompilation of 254.gap last night, which was a latent bug
exposed by other optimizer improvements.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15085 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-21 20:14:10 +00:00
Chris Lattner
5eb919405c Make cast-cast code a bit more defensive
"simplify" a bit of code for comparison/and folding


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15082 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-21 19:50:44 +00:00
Chris Lattner
e8a7e593e6 Remove special casing of pointers and treat them generically as integers of
the appopriate size.  This gives us the ability to eliminate int -> ptr -> int


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15063 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-21 04:27:24 +00:00
Chris Lattner
adfd32f8ee Fix a serious code pessimization problem. If an inlined function has a single
return, clone the 'ret' BB code into the block AFTER the inlined call, not the
other way around.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15030 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-20 05:45:24 +00:00
Chris Lattner
59a20773f8 Implement Transforms/InstCombine/IntPtrCast.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15029 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-20 05:21:00 +00:00
Chris Lattner
9ce300013d Ignore instructions that are in trivially dead functions. This allows us
to constify 14 globals instead of 4 in a trivial C++ testcase.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15027 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-20 03:58:07 +00:00
Chris Lattner
67769e5efa Implement InstCombine/GEPIdxCanon.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15024 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-20 01:48:15 +00:00
Chris Lattner
af17b1df84 Implement SimplifyCFG/BrUnwind.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15022 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-20 01:17:38 +00:00
Chris Lattner
bee7e7644b Rewrite cast->cast elimination code completely based on the information we
actually care about.  Someday when the cast instruction is gone, we can do
better here, but this will do for now.  This implements
instcombine/cast.ll:test17/18 as well.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15018 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-20 00:59:32 +00:00
Chris Lattner
8919cccc3d Fix a performance regression from the CPR patch, simplify code
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14974 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 21:34:16 +00:00
Chris Lattner
96940cb522 Strip out and simplify some code. This also fixes the regression last
night compiling cfrac.  It did not realize that code like this:

int G; int *H = &G;

takes the address of G.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14973 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 19:56:20 +00:00
Chris Lattner
9db07b9307 Minor cleanup, no functionality change
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14972 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 18:59:44 +00:00
Reid Spencer
e95ff9afa0 Remove an if statement that would never be reached.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14968 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 08:41:47 +00:00
Reid Spencer
c88920df66 Delete a redundant if branch.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14967 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 08:34:52 +00:00
Reid Spencer
c3c2fdf5a8 Expand the coercion of constants to include the newly constant Globals.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14966 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 08:34:19 +00:00
Reid Spencer
5f0eb64079 Delete a no-op loop.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14965 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 08:32:43 +00:00
Reid Spencer
c3c92d834a Expand the scope to include global values because they are now constants
too.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14964 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 08:32:10 +00:00
Reid Spencer
3188cab989 Avoid an unnecessary isa<Constant>.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14963 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 08:31:18 +00:00
Chris Lattner
25c6d68029 Remove useless statistic, fix some slightly broken logic
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14958 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 07:22:58 +00:00
Chris Lattner
5827aebe64 Fix a rather serious bug in previous checkin
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14957 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 06:56:58 +00:00
Reid Spencer
518310cb0d bug 122:
- Replace ConstantPointerRef usage with GlobalValue usage


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14953 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 00:44:37 +00:00
Reid Spencer
8863f1814b bug 122:
- Replace ConstantPointerRef usage with GlobalValue usage
- Minimize redundant isa<GlobalValue> usage
- Correct isa<Constant> for GlobalValue subclass


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14950 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 00:38:32 +00:00
Reid Spencer
460f16c625 bug 122:
- Minimize redundant isa<GlobalValue> usage


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14948 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 00:32:14 +00:00
Reid Spencer
21cb67e16a bug 122:
- Replace ConstantPointerRef usage with GlobalValue usage
- Correct isa<Constant> for GlobalValue subclass


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14947 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 00:31:05 +00:00
Reid Spencer
48dc46a512 bug 122:
- Minimize redundant isa<GlobalValue> usage
- Correct isa<Constant> for GlobalValue subclass


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14946 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 00:29:57 +00:00
Reid Spencer
0c4a0418d3 bug 122:
- Replace ConstantPointerRef usage with GlobalValue usage
- Rename methods to get ride of ConstantPointerRef usage


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14945 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 00:25:04 +00:00
Reid Spencer
3178158918 bug 122:
- Excise dead CPR procesing.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14944 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 00:23:51 +00:00
Reid Spencer
d02fccfdb8 bug 122:
- Replace ConstantPointerRef usage with GlobalValue usage
- Correct test ordering for GlobalValue subclass


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14943 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-18 00:19:45 +00:00
Chris Lattner
80b2d6c8c4 This patch was contributed by Daniel Berlin!
Speed up SCCP substantially by processing overdefined values quickly.  This
patch speeds up SCCP by about 30-40% on large testcases.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14861 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-15 23:36:43 +00:00
Chris Lattner
fed22aac43 Fix PR404 try #2
This version takes about 1s longer than the previous one (down to 2.35s),
but on the positive side, it actually works :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14856 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-15 08:20:22 +00:00
Chris Lattner
de7aee760e Revert previous patch until I get a bug fixed
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14853 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-15 05:36:31 +00:00
Chris Lattner
507e3d6dc3 Fix PR404: Loop simplify is really slow on 252.eon
This eliminates an N*N*logN algorithm from the loop simplify pass, replacing
it with a much simpler and faster alternative.  In a debug build, this reduces
gccas time on eon from 85s to 42s.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14851 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-15 04:27:04 +00:00
Chris Lattner
30b4344767 Progress on PR341
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14840 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-15 02:06:12 +00:00
Chris Lattner
2fc1230dd6 Fixes working towards PR341
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14839 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-15 01:50:47 +00:00
Chris Lattner
8bfc2f11a4 Now that we codegen the portable "sizeof" efficiently, we can use it for
malloc lowering.  This means that lowerallocations doesn't need targetdata
anymore.  yaay.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14835 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-15 01:08:08 +00:00
Chris Lattner
b89e071aea Factor some code to handle "load (constantexpr cast foo)" just like
"load (cast foo)".  This allows us to compile C++ code like this:

class Bclass {
  public: virtual int operator()() { return 666; }
};

class Dclass: public Bclass {
  public: virtual int operator()() { return 667; }
} ;

int main(int argc, char** argv) {
  Dclass x;
  return x();
}

Into this:

int %main(int %argc, sbyte** %argv) {
entry:
        call void %__main( )
        ret int 667
}

Instead of this:

int %main(int %argc, sbyte** %argv) {
entry:
        %x = alloca "struct.std::bad_typeid"            ; <"struct.std::bad_typeid"*> [#uses=3]
        call void %__main( )
        %tmp.1.i.i = getelementptr "struct.std::bad_typeid"* %x, uint 0, uint 0, uint 0         ; <int (...)***> [#uses=1]
        store int (...)** getelementptr ([3 x int (...)*]*  %vtable for Bclass, int 0, long 2), int (...)*** %tmp.1.i.i
        %tmp.3.i = getelementptr "struct.std::bad_typeid"* %x, int 0, uint 0, uint 0            ; <int (...)***> [#uses=1]
        store int (...)** getelementptr ([3 x int (...)*]*  %vtable for Dclass, int 0, long 2), int (...)*** %tmp.3.i
        %tmp.5 = load int ("struct.std::bad_typeid"*)** cast (int (...)** getelementptr ([3 x int (...)*]*  %vtable for Dclass, int 0, long 2) to int
("struct.std::bad_typeid"*)**)          ; <int ("struct.std::bad_typeid"*)*> [#uses=1]
        %tmp.6 = call int %tmp.5( "struct.std::bad_typeid"* %x )                ; <int> [#uses=1]
	ret int %tmp.6
        ret int 0
}

In order words, we now resolve the virtual function call.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14783 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-13 01:49:43 +00:00
Chris Lattner
fae1010218 Check to make sure types are sized before calling getTypeSize on them.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14649 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-06 19:28:42 +00:00
Brian Gaeke
08cc64ebfe It doesn't matter what the 2nd operand is; if the GEP has 2 operands and
the first is a zero, we should leave it alone.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14648 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-06 19:24:47 +00:00
Brian Gaeke
10585d92da Add helper function.
Don't touch GEPs for which DecomposeArrayRef is not going to do anything
special (e.g., < 2 indices, or 2 indices and the last one is a constant.)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14647 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-06 18:15:39 +00:00
Chris Lattner
3571b72606 Implement rem.ll:test3
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14640 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-06 07:38:18 +00:00
Chris Lattner
1e3564ef05 Fix a minor bug where we would go into infinite loops on some constants
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14638 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-06 07:11:42 +00:00
Chris Lattner
5b73c08896 Implement InstCombine/sub.ll:test15: X % -Y === X % Y
Also, remove X % -1 = 0, because it's not true for unsigneds, and the
signed case is superceeded by this new handling.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14637 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-06 07:01:22 +00:00
Reid Spencer
954da37bb4 Add #include <iostream> since Value.h does not #include it any more.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14622 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-04 12:19:56 +00:00
Chris Lattner
46238a6150 Implement add.ll:test22, a common case in MSIL files
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14587 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-03 00:26:11 +00:00
Chris Lattner
cf27afb64e Do not call getTypeSize on a type that has no size
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14584 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-02 22:55:47 +00:00
Brian Gaeke
1c4b6de4e7 Get rid of a dead variable, and fix a typo in a comment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14560 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-02 05:30:01 +00:00
Brian Gaeke
a9160a064f Make this pass use a more specific debug message than "Processing:".
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14541 91177308-0d34-0410-b5e6-96231b3b80d8
2004-07-01 19:27:10 +00:00
Vikram S. Adve
39c2a8ead5 Restoring this file.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14478 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-29 14:20:27 +00:00
Chris Lattner
fdd9f1facc Remove unused file
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14460 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-28 00:46:58 +00:00
Chris Lattner
65f437ce7b These passes are long dead/obsolete. They never worked in the first place
and are a maintenence burden.  Nuke nuke nuke


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14457 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-28 00:44:18 +00:00
Chris Lattner
15d58b638a Implement InstCombine/add.ll:test21
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14443 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-27 22:51:36 +00:00
Chris Lattner
9dc1b2ae9b New constant expression lowering pass to simplify your instruction selection needs.
Contributed by Vladimir Prus!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14399 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-25 07:48:09 +00:00
Vikram S. Adve
e0e12ac377 This file is unused, and duplicates functionality in TraceValues.cpp.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14369 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-24 20:16:22 +00:00
Chris Lattner
a25502acd7 Two fixes. First, stop using the ugly shouldSubstituteIndVar method.
Second, disable substitution of quadratic addrec expressions to avoid putting
multiplies in loops!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14358 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-24 06:49:18 +00:00
Misha Brukman
909db65e67 Moved to lib/VMCore
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14348 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-23 17:21:17 +00:00
Brian Gaeke
1f2b892b4b Use new IsNAN() wrapper.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14340 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-23 00:25:35 +00:00
Misha Brukman
e5d6dab09e File depends on DSA, moved to lib/Analysis/DataStructure
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14325 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-22 18:11:38 +00:00
Chris Lattner
2636c1be17 *FINALLY* Fix a really nasty nondeterministic bug that has been haunting us
since May 1st.  In this code, the pred iterator was being invalidated sometimes
causing the wrong entries to be added to PHI nodes.

The fix for this is to defererence and safe the *PI value before we hack on
branch instructions, which changes use/def chains, which SOMETIMES invalidates
the iterator.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14278 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-21 07:19:01 +00:00
Chris Lattner
30c02f7eff Comment out the isnan stuff until we get a proper autoconf test for it
breaking the build on sparc is not acceptable.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14277 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-21 06:17:21 +00:00
Chris Lattner
beabf45a69 Make order of argument addition deterministic. In particular, the layout
of ConstantInt objects in memory used to determine which order arguments
were added in in some cases.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14276 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-21 00:07:58 +00:00
Chris Lattner
c5c5e6afe5 Make use of BinaryOperator::create* methods to shrinkify code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14262 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-20 05:04:01 +00:00
Chris Lattner
cf5933a716 Fix the inliner to be deterministic, not letting its output depend on the
relative location of Function objects in memory.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14260 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-20 04:11:48 +00:00
Chris Lattner
218a8223e6 Add some DEBUG output to the simplifycfg routines
Fix another non-deterministic behavior, this one should actually speed up the
code though as it was doing silly things.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14258 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-20 01:13:18 +00:00
Chris Lattner
56b7ee20da Now that dominator tree children are built in determinstic order, this horrible code
can go away


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14254 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-19 20:23:35 +00:00
Chris Lattner
aee7940d53 This will hopefully fix a heisenbug that Vladimir Merzliakov is running
into valiantly trying to compile stuff on freebsd.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14251 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-19 19:01:26 +00:00
Chris Lattner
2b994c7206 Fix a nasty bug, noticed by Reid
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14249 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-19 18:15:50 +00:00
Chris Lattner
edb8433c91 Fix one source of nondeterminism in the -licm pass: the hoist pass
was processing blocks in whatever order they happened to end up in the
dominator tree data structure.  Force an ordering.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14248 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-19 08:56:43 +00:00
Chris Lattner
abc35bcad3 Change to use the StableBasicBlockNumbering class
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14247 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-19 08:42:40 +00:00
Chris Lattner
63168d2244 Do not let the numbering of PHI nodes placed in the function depend on
non-deterministic things like the ordering of blocks in the dominance
frontier of a BB.  Unfortunately, I don't know of a better way to solve
this problem than to explicitly sort the BB's in function-order before
processing them.  This is guaranteed to slow the pass down a bit, but
is absolutely necessary to get usable diffs between two different tools
executing the mem2reg or scalarrepl pass.

Before this, bazillions of spurious diff failures occurred all over the
place due to the different order of processing PHIs:

-       %tmp.111 = getelementptr %struct.Connector_struct* %upcon.0.0, uint 0, uint 0
+       %tmp.111 = getelementptr %struct.Connector_struct* %upcon.0.1, uint 0, uint 0

Now, the diffs match.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14244 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-19 07:40:14 +00:00
Chris Lattner
1654cff8e8 Do not sort by the address of LLVM ConstantInt* objects. This produces
nondeterministic results that depend on where these objects land in memory.
Instead, sort by the value of the constant, which is stable.

Before this patch, the -simplifycfg pass run from two different compilers
could cause different code to be generated, though it was semantically the
same:

@@ -12258,8 +12258,8 @@
        %s_addr.1 = phi sbyte* [ %s, %entry ], [ %inc.0, %no_exit ]             ; <sbyte*> [#uses=5]
        %tmp.1 = load sbyte* %s_addr.1          ; <sbyte> [#uses=1]
        switch sbyte %tmp.1, label %no_exit [
-                sbyte 0, label %loopexit
                 sbyte 46, label %loopexit
+                sbyte 0, label %loopexit
        ]

We need to stomp all of this stuff out.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14243 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-19 07:02:14 +00:00
Chris Lattner
8430a4545c Do not loop over uses as we delete them. This causes iterators to be
invalidated out from under us.  This bug goes back to revision 1.1: scary.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14242 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-19 02:02:22 +00:00
Chris Lattner
5b62aa743d Implement Transforms/InstCombine/and.ll:test17, a common case that
occurs due to unordered comparison macros in math.h


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14221 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-18 06:07:51 +00:00
Chris Lattner
e5ad50b2e8 Do not function resolve intrinsics. This prevents warnings and possible bad
things from happening due to

declare bool %llvm.isunordered(double, double)
declare bool %llvm.isunordered(float, float)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14219 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-18 05:50:48 +00:00
Brian Gaeke
afe16e1742 I love the smell of a freshly broken PowerPC build in the morning.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14206 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-17 22:27:04 +00:00
Chris Lattner
5253f05709 Fix compilation problem on freebsd. Problem noted by Vladimir Merzliakov in
PR371


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14203 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-17 21:20:52 +00:00
Chris Lattner
f70c22b019 Rename Type::PrimitiveID to TypeId and ::getPrimitiveID() to ::getTypeID()
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14201 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-17 18:19:28 +00:00
Chris Lattner
5dd04027c7 Rename Type::PrimitiveID to TypeId and ::getPrimitiveID() to ::getTypeID()
Delete two functions that are now methods on the Type class


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14200 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-17 18:16:02 +00:00
Brian Gaeke
802daf8b7d Fix typo in DEBUG printout.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14196 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-17 07:26:52 +00:00
Brian Gaeke
83a7049270 Um, did someone make a typo or something?
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14192 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-15 23:09:50 +00:00
Chris Lattner
c45ef6d395 Remove support for the isnan intrinsic
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14186 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-15 21:37:54 +00:00
Brian Gaeke
fda2cce3bf Quick hack to get this file compiling again on Mac OS X. The right thing to do
is write an autoconf macro that checks whether __isnan or isnan actually works
**using the C++ compiler after #include <cmath>**, instead of doing it the easy
way with AC_CHECK_FUNCS().


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14171 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-14 06:33:19 +00:00
Alkis Evlogimenos
df497317f1 Add constant folding capabilities to the isunordered intrinsic.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14168 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-13 01:23:56 +00:00
Chris Lattner
cf11035a6f Constant fold the isnan intrinsic
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14150 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-11 06:16:23 +00:00
Chris Lattner
3285a6f426 Fix a bug in my checkin from last night that caused miscompilations of
186.crafty, fhourstones and 132.ijpeg.

Bugpoint makes really nasty miscompilations embarassingly easy to find.  It
narrowed it down to the instcombiner and this testcase (from fhourstones):

bool %l7153_l4706_htstat_loopentry_2E_4_no_exit_2E_4(int* %i, [32 x int]* %works, int* %tmp.98.out) {
newFuncRoot:
        %tmp.96 = load int* %i          ; <int> [#uses=1]
        %tmp.97 = getelementptr [32 x int]* %works, long 0, int %tmp.96         ; <int*> [#uses=1]
        %tmp.98 = load int* %tmp.97             ; <int> [#uses=2]
        %tmp.99 = load int* %i          ; <int> [#uses=1]
        %tmp.100 = and int %tmp.99, 7           ; <int> [#uses=1]
        %tmp.101 = seteq int %tmp.100, 7                ; <bool> [#uses=2]
        %tmp.102 = cast bool %tmp.101 to int            ; <int> [#uses=0]
        br bool %tmp.101, label %codeRepl4.exitStub, label %codeRepl3.exitStub

codeRepl4.exitStub:             ; preds = %newFuncRoot
        store int %tmp.98, int* %tmp.98.out
        ret bool true

codeRepl3.exitStub:             ; preds = %newFuncRoot
        store int %tmp.98, int* %tmp.98.out
        ret bool false
}

... which only has one combination performed on it:

$ llvm-as < t.ll | opt -instcombine -debug | llvm-dis
IC: Old =       %tmp.101 = seteq int %tmp.100, 7                ; <bool> [#uses=1]
    New =       setne int %tmp.100, 0           ; <bool>:<badref> [#uses=0]
IC: MOD =       br bool %tmp.101, label %codeRepl3.exitStub, label %codeRepl4.exitStub
IC: MOD =       %tmp.97 = getelementptr [32 x int]* %works, uint 0, int %tmp.96         ; <int*> [#uses=1]

It doesn't get much better than this.  :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14109 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-10 02:33:20 +00:00
Chris Lattner
448c323cba More minor cleanups
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14108 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-10 02:12:35 +00:00
Chris Lattner
48595f18cf Eliminate many occurrances of Instruction::
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14107 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-10 02:07:29 +00:00
Chris Lattner
457dd829ad Implement InstCombine/select.ll:test15*
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14095 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-09 07:59:58 +00:00
Chris Lattner
f523d06816 Be more careful about the order we put stuff onto the worklist. This allow us to
collapse this:
bool %le(int %A, int %B) {
        %c1 = setgt int %A, %B
        %tmp = select bool %c1, int 1, int 0
        %c2 = setlt int %A, %B
        %result = select bool %c2, int -1, int %tmp
        %c3 = setle int %result, 0
        ret bool %c3
}

into:

bool %le(int %A, int %B) {
        %c3 = setle int %A, %B          ; <bool> [#uses=1]
        ret bool %c3
}

which is handy, because the Java FE makes these sequences all over the place.

This is tested as: test/Regression/Transforms/InstCombine/JavaCompare.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14086 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-09 05:08:07 +00:00
Chris Lattner
2be51ae22d Implement select.ll:test14*
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14083 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-09 04:24:29 +00:00
Brian Gaeke
f36b5f0fb6 Expand head-of-file comment.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13982 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-03 05:03:02 +00:00
Brian Gaeke
dfb2e7d7c9 Use new form of unconditional branch constructor.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13930 91177308-0d34-0410-b5e6-96231b3b80d8
2004-06-01 20:06:10 +00:00
Chris Lattner
11b9be5a1a Fix one of the major things that is causing the C Backend to infinite loop
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13872 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-28 05:02:13 +00:00
John Criswell
e7b9a1a5f2 Fix a bug in the -deadtypeelim pass. The SymbolTable re-write changed it
to eliminate the wrong type.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13855 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-27 21:16:46 +00:00
Chris Lattner
e1368aef23 Fix InstCombine/load.ll & PR347.
This code hadn't been updated after the "structs with more than 256 elements"
related changes to the GEP instruction.  Also it was not handling the
ConstantAggregateZero class.

Now it does!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13834 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-27 17:30:27 +00:00
Chris Lattner
8dfe5705b1 Implement constant folding of fmod, which is used a lot in povray
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13823 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-27 07:25:00 +00:00
Chris Lattner
b18b9d7374 Restructure call constant folding code a bit to make it simpler
Add support for acos/asin/atan.  188.ammp contains three calls to acos with
constant arguments.  Constant folding it allows elimination of those 3 calls
and three FP divisions of the results.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13821 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-27 06:26:28 +00:00
Alkis Evlogimenos
fe3a093bc6 Do not pass a null pointer if this instruction is not prepended or
appended anywhere.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13798 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-26 22:50:28 +00:00
Alkis Evlogimenos
99c58f4910 Use one destination constructor for the unconditional branch.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13792 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-26 21:38:14 +00:00
Reid Spencer
9231ac8b6f Convert to SymbolTable's new iteration interface.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13754 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-25 08:53:40 +00:00
Reid Spencer
567bc2cc1e Convert to SymbolTable's new lookup and iteration interfaces.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13751 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-25 08:52:20 +00:00
Reid Spencer
c8a1fcdb48 Remove unused header file.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13750 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-25 08:51:36 +00:00
Reid Spencer
3f0635e012 Make this pass simply invoke SymbolTable::strip().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13749 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-25 08:51:25 +00:00
Chris Lattner
3c6a0d4ae2 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13740 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-25 06:32:08 +00:00
Chris Lattner
a710ddc9c4 Implement instcombine/cast.ll:test16:
Canonicalize cast X to bool into a setne instruction


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13736 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-25 04:29:21 +00:00
Chris Lattner
b11a99bd39 Fix a bug in my previous checkin
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13717 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-24 06:24:46 +00:00
Chris Lattner
f52988a92d Spelling people's names right is kinda important
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13702 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-23 21:27:29 +00:00
Chris Lattner
befa499d45 Fix cases where we missed inlining some more obvious candidates because the
caller was in an SCC.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13693 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-23 21:22:17 +00:00
Chris Lattner
74c68ffd5f Simplify the interface and remove an unneeded #include
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13692 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-23 21:21:35 +00:00
Chris Lattner
9e7cc2f0d4 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13691 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-23 21:21:17 +00:00
Chris Lattner
2741c97104 Adjust to the changes in the AliasSetTracker interface
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13690 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-23 21:20:19 +00:00
Chris Lattner
057f78ab4e Add support for replacement of formal arguments with simpler expressions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13689 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-23 21:19:55 +00:00
Chris Lattner
08005dfdc9 Implement the -lowergc pass which is used by code generators (like the CBE)
that do not have builtin support for garbage collection.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13688 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-23 21:19:22 +00:00
Brian Gaeke
c58a7f4b3c Add CloneTraceInto(), which is based on (and has mostly the same
effects as) CloneFunctionInto().


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13601 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-19 09:08:14 +00:00
Brian Gaeke
6129af3fb1 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13600 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-19 09:08:12 +00:00
Brian Gaeke
cc9620ca29 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13581 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-14 21:21:52 +00:00
Chris Lattner
fa28bb4601 This was not meant to be committed
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13565 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-13 20:56:34 +00:00
Chris Lattner
82fec4e31d 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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13564 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-13 20:43:31 +00:00
Chris Lattner
587992721c 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13493 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-12 16:26:18 +00:00
Chris Lattner
d99e1d3afb Implement support for code extracting basic blocks that have a return
instruction in them.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13490 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-12 16:07:41 +00:00
Chris Lattner
e746ad512e 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.  :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13489 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-12 15:29:13 +00:00
Chris Lattner
bf749367cb * 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13482 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-12 06:01:40 +00:00
Chris Lattner
346be7f5bc 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13481 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-12 04:14:24 +00:00
Chris Lattner
5b01e298ed 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13478 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-12 03:22:33 +00:00
Chris Lattner
be97b4e9ab Fix stupid bug in my checkin yesterday
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13429 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-08 22:41:42 +00:00
Chris Lattner
620ce14666 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13415 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-07 22:09:22 +00:00
Chris Lattner
546516c3c0 Fix PR336: The instcombine pass asserts when visiting load instruction
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13400 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-07 15:35:56 +00:00
Chris Lattner
b9110c61fb Do not mark instructions in unreachable sections of the function as live.
This fixes PR332 and ADCE/2004-05-04-UnreachableBlock.llx


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13349 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-04 17:00:46 +00:00
Chris Lattner
32ed46b36e Minor efficiency tweak, suggested by Patrick Meredith
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13341 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-04 15:19:33 +00:00
Brian Gaeke
96e68f9ab1 Fix typo
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13340 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-03 23:52:07 +00:00
Brian Gaeke
ebbc0e9bbf 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13336 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-03 22:06:33 +00:00
Brian Gaeke
c03eb7b923 Add initial implementation of basic-block tracing instrumentation pass.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13335 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-03 22:06:32 +00:00
Chris Lattner
bdcc0b8c55 Do not clone arbitrary condition instructions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13316 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-02 05:19:36 +00:00
Chris Lattner
12fe2b1b82 Do not infinitely "unroll" single BB loops.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13315 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-02 05:02:03 +00:00
Chris Lattner
a1f79fb08b Dont' merge terminators that are needed to select PHI node values.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13312 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-02 01:00:44 +00:00
Chris Lattner
e67fa05036 Implement SimplifyCFG/branch-cond-merge.ll
Turning "if (A < B && B < C)" into "if (A < B & B < C)"


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13311 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-01 23:35:43 +00:00
Chris Lattner
00d513182d Make sure to reprocess instructions used by deleted instructions to avoid
missing opportunities for combination.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13309 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-01 23:27:23 +00:00
Chris Lattner
216d4d85fd Make sure the instruction combiner doesn't lose track of instructions
when replacing them, missing the opportunity to do simplifications


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13308 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-01 23:19:52 +00:00
Chris Lattner
951fdb9764 Fix my missing parens
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13307 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-01 22:41:51 +00:00
Chris Lattner
92da2c2053 Implement SimplifyCFG/branch-cond-prop.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13306 91177308-0d34-0410-b5e6-96231b3b80d8
2004-05-01 22:36:37 +00:00
Chris Lattner
c1526a9da1 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. :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13289 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-30 04:37:52 +00:00
Chris Lattner
6ffe551f65 Changes to fix up the inst_iterator to pass to boost iterator checks. This
patch was graciously contributed by Vladimir Prus.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13185 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-27 15:13:33 +00:00
Chris Lattner
83a2e6e4a1 Instcombine X/-1 --> 0-X
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13172 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-26 14:01:59 +00:00
Misha Brukman
22108fac63 * Allow aggregating extracted function arguments (controlled by flag)
* Commandline option (for now) controls that flag that is passed in


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13141 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-23 23:54:17 +00:00
Chris Lattner
4a7553e2da 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13135 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-23 21:29:48 +00:00
Misha Brukman
7d248397a7 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13112 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-22 23:00:51 +00:00
Misha Brukman
79906c9825 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13111 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-22 22:52:22 +00:00
Chris Lattner
b4782d13d1 Disable a previous patch that was causing indvars to loop infinitely :(
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13108 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-22 15:12:36 +00:00
Chris Lattner
fcb81f5f4c Fix an extremely serious thinko I made in revision 1.60 of this file.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13106 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-22 14:59:40 +00:00
Chris Lattner
1363e85df7 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. :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13103 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-21 23:36:08 +00:00
Chris Lattner
4e5f03602c 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.  :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13102 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-21 22:29:37 +00:00
Chris Lattner
5d461d20ae 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13101 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-21 22:22:01 +00:00
Chris Lattner
3e1358a9fa 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13100 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-21 20:44:33 +00:00
Alkis Evlogimenos
09233fb86e Include cerrno (gcc-3.4 fix)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13091 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-21 16:11:40 +00:00
Chris Lattner
107fb18d89 Fix typeo
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13089 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-21 14:23:18 +00:00
Chris Lattner
68d57e7ae8 REALLY fix PR324: don't delete linkonce functions until after the SCC traversal
is done, which avoids invalidating iterators in the SCC traversal routines


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13088 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-20 22:06:53 +00:00
Chris Lattner
c99acc3709 Fix PR325
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13081 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-20 20:26:03 +00:00
Chris Lattner
5ad2b1d544 Fix PR324 and testcase: Inline/2004-04-20-InlineLinkOnce.llx
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13080 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-20 20:20:59 +00:00
Chris Lattner
18f16094c2 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13068 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-19 18:07:02 +00:00
Chris Lattner
5864aebe92 Add #include
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13057 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-19 03:01:23 +00:00
Chris Lattner
3280f7bd55 Move isLoopInvariant to the Loop class
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13051 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-18 22:46:08 +00:00
Chris Lattner
59fb87d469 Correct rewriting of exit blocks after my last patch
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13048 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-18 22:27:10 +00:00
Chris Lattner
5fa802fe27 Loop exit sets are no longer explicitly held, they are dynamically computed on demand.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13046 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-18 22:15:13 +00:00
Chris Lattner
f1ab4b4eac 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13045 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-18 22:14:10 +00:00
Chris Lattner
e3a55865bb Reduce the unrolling limit
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13040 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-18 18:06:14 +00:00
Chris Lattner
cc43909bb6 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13039 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-18 17:38:42 +00:00
Chris Lattner
998f44f859 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13038 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-18 17:32:39 +00:00
Chris Lattner
50ca0a195a 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13034 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-18 06:27:43 +00:00
Chris Lattner
9c2cc4626b Fix a bug: this does not preserve the CFG!
While we're at it, add support for updating loop information correctly.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13033 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-18 05:38:37 +00:00
Chris Lattner
83bf2880c3 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13028 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-18 05:20:17 +00:00
Chris Lattner
3c85eef81a Make the tail duplication threshold accessible from the command line instead of hardcoded
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13025 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-18 00:52:43 +00:00
Chris Lattner
20aa098ba6 If the loop executes a constant number of times, try a bit harder to replace
exit values.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13018 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-17 18:44:09 +00:00
Chris Lattner
4f1134e51a 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
}


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13016 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-17 18:16:10 +00:00
Chris Lattner
f50af088f1 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13015 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-17 18:08:33 +00:00
Chris Lattner
f5b9eb37a9 Add support for evaluation of exp/log/log10/pow
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13011 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-16 22:35:33 +00:00
Chris Lattner
657253119e Fix some really nasty dominance bugs that were exposed by my patch to
make the verifier more strict.  This fixes building zlib


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13002 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-16 18:08:07 +00:00
Brian Gaeke
c598517c24 Include <cmath> for compatibility with gcc 3.0.x (the system compiler on
Debian.)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12986 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-16 15:57:32 +00:00
Chris Lattner
006118fe8c Fix some of the strange CBE-only failures that happened last night.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12980 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-16 06:03:17 +00:00
Chris Lattner
cd01ae5c70 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12977 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-16 05:17:59 +00:00
Chris Lattner
d244057a48 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12968 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-15 20:26:22 +00:00
Chris Lattner
59fdaeeae8 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12961 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-15 15:21:43 +00:00
Chris Lattner
d9955aaa61 ADd a trivial instcombine: load null -> null
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12940 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-14 03:28:36 +00:00
Chris Lattner
58b7b08ad7 Add SCCP support for constant folding calls, implementing:
test/Regression/Transforms/SCCP/calltest.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12921 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-13 19:43:54 +00:00
Chris Lattner
25b8390bf2 Add a simple call constant propagation interface.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12919 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-13 19:28:52 +00:00
Chris Lattner
4647b7cd69 Constant propagation should remove the dead instructions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12917 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-13 19:28:20 +00:00
Chris Lattner
4b66242c54 Fix LoopSimplify/2004-04-13-LoopSimplifyUpdateDomFrontier.ll
LoopSimplify was not updating dominator frontiers correctly in some cases.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12890 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-13 16:23:25 +00:00
Chris Lattner
1f62f82b05 Refactor code a bit to make it simpler and eliminate the goto
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12888 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-13 15:21:18 +00:00
Chris Lattner
529b28da45 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.  :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12884 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-13 05:05:33 +00:00
Chris Lattner
ce1a3a292d Actually update the call graph as the inliner changes it. This allows us to
execute other CallGraphSCCPasses after the inliner without crashing.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12861 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-12 05:37:29 +00:00
Chris Lattner
1708d12916 Add support for removing invoke instructions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12858 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-12 05:15:13 +00:00
Chris Lattner
85eb157d96 Stop printing Function*
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12857 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-12 04:06:56 +00:00
Chris Lattner
d08ddd3300 Simplify code a bit, and be sure to mark the external node as potentially throwing
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12856 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-12 04:06:38 +00:00
Chris Lattner
fbede52af4 Fix a bug in my select transformation
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12826 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-11 01:39:19 +00:00
Chris Lattner
adb7c0de39 Update the value numbering interface.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12824 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-10 22:33:34 +00:00
Chris Lattner
d76956d444 Implement InstCombine/select.ll:test13*
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12821 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-10 22:21:27 +00:00
Chris Lattner
66331a4e33 Implement InstCombine/add.ll:test20
Canonicalize add of sign bit constant into a xor


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12819 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-10 22:01:55 +00:00
Chris Lattner
38e66bd9d1 Rewrite the GCSE pass to be *substantially* simpler, a bit more efficient,
and a bit more powerful


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12817 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-10 21:11:11 +00:00
Chris Lattner
326c0f3013 Fix spurious warning in release mode
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12816 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-10 19:15:56 +00:00
Chris Lattner
a5f4103931 Simplify code a bit, and fix a bug that was breaking perlbmk
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12814 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-10 18:06:21 +00:00
Chris Lattner
562cb66b84 Fix a bug in my checkin last night that was breaking programs using invoke.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12813 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-10 16:53:29 +00:00
Chris Lattner
27c694bacb Fix previous patch
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12811 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-10 07:27:48 +00:00
Chris Lattner
17177601fb Correctly update counters
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12810 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-10 07:02:02 +00:00
Chris Lattner
ede6ac60a5 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12807 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-10 06:53:09 +00:00
Chris Lattner
e576b91948 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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12800 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-09 23:46:01 +00:00
Chris Lattner
570751c2a7 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) ;
}


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12798 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-09 22:50:22 +00:00
Chris Lattner
2eefe518de 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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12794 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-09 19:05:30 +00:00
Chris Lattner
82e14fe168 Implement select.ll:test11
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12793 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-09 18:19:44 +00:00
Chris Lattner
f499eaca36 Implement InstCombine/cast-propagate.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12784 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-08 20:39:49 +00:00
Chris Lattner
8ba725b456 Implement ScalarRepl/select_promote.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12779 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-08 19:59:34 +00:00
Chris Lattner
775cbdd51a 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12770 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-08 06:34:31 +00:00
Chris Lattner
0c199a7628 Implement InstCombine/select.ll:test[7-10]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12769 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-08 04:43:23 +00:00
Chris Lattner
cb69a4ed64 Implement test/Regression/Transforms/InstCombine/getelementptr_index.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12762 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-07 18:38:20 +00:00
Chris Lattner
548f47efb0 Fix a bug in yesterdays checkins which broke siod. siod is a great testcase! :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12659 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-05 16:02:41 +00:00
Chris Lattner
15a76c0b35 Fix InstCombine/2004-04-04-InstCombineReplaceAllUsesWith.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12658 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-05 02:10:19 +00:00
Chris Lattner
28977af72a 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12653 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-05 01:30:19 +00:00
Chris Lattner
40bf8b48cd 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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12620 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-02 20:24:31 +00:00
Chris Lattner
7aa773bc07 Fix the obvious bug in my previous checkin
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12618 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-02 18:15:10 +00:00
Chris Lattner
147af6b75f Implement Transforms/SimplifyCFG/return-merge.ll
This actually causes us to turn code like:

  return C ? A : B;

into a select instruction.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12617 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-02 18:13:43 +00:00
Chris Lattner
c68bace452 Fix PR310 and TailDup/2004-04-01-DemoteRegToStack.llx
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12597 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-01 20:28:45 +00:00
Chris Lattner
4edf6c043e Remove some assertions that are now bogus with the last patch I put in
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12595 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-01 19:21:46 +00:00
Chris Lattner
4f303bd4a5 Fix PR306: Loop simplify incorrectly updates dominator information
Testcase: LoopSimplify/2004-04-01-IncorrectDomUpdate.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12592 91177308-0d34-0410-b5e6-96231b3b80d8
2004-04-01 19:06:07 +00:00
Chris Lattner
0e28eca4bc Add warning
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12573 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-31 22:00:30 +00:00