Commit Graph

416 Commits

Author SHA1 Message Date
Chris Lattner
8b9081081b Do not compute 1ULL << 64, which is undefined. This fixes Ptrdist/ks on the
sparc, and testcase Regression/Transforms/InstCombine/2005-03-04-ShiftOverflow.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20445 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-04 23:21:33 +00:00
Chris Lattner
fcfe33acda Implement InstCombine/cast.ll:test25, a case that occurs many times
in spec


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19953 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-31 05:51:45 +00:00
Chris Lattner
2f503e6c27 Implement the trivial cases in InstCombine/store.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19950 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-31 05:36:43 +00:00
Chris Lattner
f9527850e6 Implement Transforms/InstCombine/cast-load-gep.ll, which allows us to devirtualize
11 indirect calls in perlbmk.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19947 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-31 04:50:46 +00:00
Chris Lattner
5551706b0f Adjust to changes in instruction interfaces.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19900 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-29 00:39:08 +00:00
Chris Lattner
ad5fec12a0 * add some DEBUG statements
* Properly compile this:

struct a {};
int test() {
  struct a b[2];
  if (&b[0] != &b[1])
    abort ();
  return 0;
}

to 'return 0', not abort().


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19875 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-28 19:32:01 +00:00
Chris Lattner
ad1e302723 Get rid of a several dozen more and instructions in specint.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19786 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-23 20:26:55 +00:00
Chris Lattner
45f57b8ee3 Handle comparisons of gep instructions that have different typed indices
as long as they are the same size.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19734 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-21 23:06:49 +00:00
Chris Lattner
6fb5a4a5f8 Add two optimizations. The first folds (X+Y)-X -> Y
The second folds operations into selects, e.g. (select C, (X+Y), (Y+Z))
-> (Y+(select C, X, Z)

This occurs a few times across spec, e.g.

         select    add/sub
mesa:    83        0
povray:  5         2
gcc      4         2
parser   0         22
perlbmk  13        30
twolf    0         3


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19706 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-19 21:50:18 +00:00
Chris Lattner
a3fd1c569c Delete PHI nodes that are not dead but are locked in a cycle of single
useness.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19629 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-17 05:10:15 +00:00
Chris Lattner
b352fa5853 Move code out of indentation one level to make it easier to read.
Disable the xform for < > cases.  It turns out that the following is being
miscompiled:

bool %test(sbyte %S) {
        %T = cast sbyte %S to uint
        %V = setgt uint %T, 255
        ret bool %V
}


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19628 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-17 03:20:02 +00:00
Chris Lattner
906ab50acf Fix some bugs in an xform added yesterday. This fixes Prolangs-C/allroots.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19553 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-14 17:35:12 +00:00
Chris Lattner
6f7f02fdec Fix a compile crash on spiff
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19552 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-14 17:17:59 +00:00
Chris Lattner
4401c9cabe if two gep comparisons only differ by one index, compare that index directly.
This allows us to better optimize begin() -> end() comparisons in common cases.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19542 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-14 00:20:05 +00:00
Chris Lattner
0b84c80c08 Do not overrun iterators. This fixes a 176.gcc crash
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19541 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-13 23:26:48 +00:00
Chris Lattner
87875dac89 Turn select C, (X+Y), (X-Y) --> (X+(select C, Y, (-Y))). This occurs in
the 'sim' program and probably elsewhere.  In sim, it comes up for cases
like this:

#define round(x) ((x)>0.0 ? (x)+0.5 : (x)-0.5)
double G;
void T(double X) { G = round(X); }

(it uses the round macro a lot).  This changes the LLVM code from:

        %tmp.1 = setgt double %X, 0.000000e+00          ; <bool> [#uses=1]
        %tmp.4 = add double %X, 5.000000e-01            ; <double> [#uses=1]
        %tmp.6 = sub double %X, 5.000000e-01            ; <double> [#uses=1]
        %mem_tmp.0 = select bool %tmp.1, double %tmp.4, double %tmp.6
        store double %mem_tmp.0, double* %G

to:

        %tmp.1 = setgt double %X, 0.000000e+00          ; <bool> [#uses=1]
        %mem_tmp.0.p = select bool %tmp.1, double 5.000000e-01, double -5.000000e-01
        %mem_tmp.0 = add double %mem_tmp.0.p, %X
        store double %mem_tmp.0, double* %G
        ret void


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19537 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-13 22:52:24 +00:00
Chris Lattner
e9d782b7be Implement an optimization for == and != comparisons like this:
_Bool test2(int X, int Y) {
  return &arr[X][Y] == arr;
}

instead of generating this:

bool %test2(int %X, int %Y) {
        %tmp.3.idx = mul int %X, 160            ; <int> [#uses=1]
        %tmp.3.idx1 = shl int %Y, ubyte 2               ; <int> [#uses=1]
        %tmp.3.offs2 = sub int 0, %tmp.3.idx            ; <int> [#uses=1]
        %tmp.7 = seteq int %tmp.3.idx1, %tmp.3.offs2            ; <bool> [#uses=1]
        ret bool %tmp.7
}


generate this:

bool %test2(int %X, int %Y) {
        seteq int %X, 0         ; <bool>:0 [#uses=1]
        seteq int %Y, 0         ; <bool>:1 [#uses=1]
        %tmp.7 = and bool %0, %1                ; <bool> [#uses=1]
        ret bool %tmp.7
}

This idiom occurs in C++ programs when iterating from begin() to end(),
in a vector or array.  For example, we now compile this:

void test(int X, int Y) {
  for (int *i = arr; i != arr+100; ++i)
    foo(*i);
}

to this:

no_exit:                ; preds = %entry, %no_exit
	...
        %exitcond = seteq uint %indvar.next, 100                ; <bool> [#uses=1]
        br bool %exitcond, label %return, label %no_exit



instead of this:

no_exit:                ; preds = %entry, %no_exit
	...
        %inc5 = getelementptr [100 x [40 x int]]* %arr, int 0, int 0, int %inc.rec              ; <int*> [#uses=1]
        %tmp.8 = seteq int* %inc5, getelementptr ([100 x [40 x int]]* %arr, int 0, int 100, int 0)              ; <bool> [#uses=1]
        %indvar.next = add uint %indvar, 1              ; <uint> [#uses=1]
        br bool %tmp.8, label %return, label %no_exit


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19536 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-13 22:25:21 +00:00
Chris Lattner
5bdf04cc8e Fix some bugs in code I didn't mean to check in.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19534 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-13 20:40:58 +00:00
Chris Lattner
574da9ba0b Fix a crash compiling 129.compress
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19533 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-13 20:14:25 +00:00
Chris Lattner
652f3cf76f Fix uint64_t -> unsigned VS warnings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19381 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-08 19:42:22 +00:00
Chris Lattner
6e7ba45460 This is a bulk commit that implements the following primary improvements:
* We can now fold cast instructions into select instructions that
    have at least one constant operand.
  * We now optimize expressions more aggressively based on bits that are
    known to be zero.  These optimizations occur a lot in code that uses
    bitfields even in simple ways.
  * We now turn more cast-cast sequences into AND instructions.  Before we
    would only do this if it if all types were unsigned.  Now only the
    middle type needs to be unsigned (guaranteeing a zero extend).
  * We transform sign extensions into zero extensions in several cases.

This corresponds to these test/Regression/Transforms/InstCombine testcases:
  2004-11-22-Missed-and-fold.ll
  and.ll: test28-29
  cast.ll: test21-24
  and-or-and.ll
  cast-cast-to-and.ll
  zeroext-and-reduce.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19220 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-01 16:22:27 +00:00
Chris Lattner
0ce8580fcd Constant exprs are not efficiently negatable in practice. This disables
turning X - (constantexpr) into X + (-constantexpr) among other things.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18935 91177308-0d34-0410-b5e6-96231b3b80d8
2004-12-14 20:08:06 +00:00
Chris Lattner
857e8cdd65 Optimize div/rem + select combinations more.
In particular, implement div.ll:test10 and rem.ll:test4.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18838 91177308-0d34-0410-b5e6-96231b3b80d8
2004-12-12 21:48:58 +00:00
Chris Lattner
13eaf4f14d note to self: Do not check in debugging code!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18693 91177308-0d34-0410-b5e6-96231b3b80d8
2004-12-09 07:15:52 +00:00
Chris Lattner
96a52a6f6c Implement trivial sinking for load instructions. This causes us to sink 567 loads in spec
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18692 91177308-0d34-0410-b5e6-96231b3b80d8
2004-12-09 07:14:34 +00:00
Chris Lattner
ea1c45405d Do extremely simple sinking of instructions when they are only used in a
successor block.  This turns cases like this:

x = a op b
if (c) {
  use x
}

into:

if (c) {
  x = a op b
  use x
}

This triggers 3965 times in spec, and is tested by
Regression/Transforms/InstCombine/sink_instruction.ll

This appears to expose a bug in the X86 backend for 177.mesa, which I'm
looking in to.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18677 91177308-0d34-0410-b5e6-96231b3b80d8
2004-12-08 23:43:58 +00:00
Alkis Evlogimenos
54a96a2ad6 Fix this regression and remove the XFAIL from this test.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18674 91177308-0d34-0410-b5e6-96231b3b80d8
2004-12-08 23:10:30 +00:00
Chris Lattner
2a0cd9c9b5 Fix Transforms/InstCombine/2004-12-08-RemInfiniteLoop.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18670 91177308-0d34-0410-b5e6-96231b3b80d8
2004-12-08 22:20:34 +00:00
Reid Spencer
6731d5c494 Fix for PR454:
* Make sure we handle signed to unsigned conversion correctly
* Move this visitSetCondInst case to its own method.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18312 91177308-0d34-0410-b5e6-96231b3b80d8
2004-11-28 21:31:15 +00:00
Chris Lattner
646641e02c Implement Regression/Transforms/InstCombine/getelementptr_cast.ll, which
occurs many times in crafty


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18273 91177308-0d34-0410-b5e6-96231b3b80d8
2004-11-27 17:55:46 +00:00
Chris Lattner
954f66a8cd Delete stoppoints that occur for the same source line.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17970 91177308-0d34-0410-b5e6-96231b3b80d8
2004-11-18 21:41:39 +00:00
Chris Lattner
50e60c7026 Quiet warnings on the persephone tester
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17821 91177308-0d34-0410-b5e6-96231b3b80d8
2004-11-15 05:54:07 +00:00
Chris Lattner
b58934484b This optimization makes MANY phi nodes that all have the same incoming value.
If this happens, detect it early instead of relying on instcombine to notice
it later.  This can be a big speedup, because PHI nodes can have many
incoming values.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17741 91177308-0d34-0410-b5e6-96231b3b80d8
2004-11-14 19:29:34 +00:00
Chris Lattner
bac32866a7 Implement instcombine/phi.ll:test6 - pulling operations through PHI nodes.
This exposes subsequent optimization possiblities and reduces code size.
This triggers 1423 times in spec.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17740 91177308-0d34-0410-b5e6-96231b3b80d8
2004-11-14 19:13:23 +00:00
Chris Lattner
711b3402aa Transform this:
%X = alloca ...
  %Y = alloca ...
    X == Y

into false.  This allows us to simplify some stuff in eon (and probably
many other C++ programs) where operator= was checking for self assignment.
Folding this allows us to SROA several additional structs.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17735 91177308-0d34-0410-b5e6-96231b3b80d8
2004-11-14 07:33:16 +00:00
Chris Lattner
50af16a97b Simplify handling of shifts to be the same as we do for adds. Add support
for (X * C1) + (X * C2) (where * can be mul or shl), allowing us to fold:

   Y+Y+Y+Y+Y+Y+Y+Y

into
         %tmp.8 = shl long %Y, ubyte 3           ; <long> [#uses=1]

instead of

        %tmp.4 = shl long %Y, ubyte 2           ; <long> [#uses=1]
        %tmp.12 = shl long %Y, ubyte 2          ; <long> [#uses=1]
        %tmp.8 = add long %tmp.4, %tmp.12               ; <long> [#uses=1]

This implements add.ll:test25

Also add support for (X*C1)-(X*C2) -> X*(C1-C2), implementing sub.ll:test18


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17704 91177308-0d34-0410-b5e6-96231b3b80d8
2004-11-13 19:50:12 +00:00
Chris Lattner
65aedc1a4e Fold:
(X + (X << C2)) --> X * ((1 << C2) + 1)
   ((X << C2) + X) --> X * ((1 << C2) + 1)

This means that we now canonicalize "Y+Y+Y" into:

        %tmp.2 = mul long %Y, 3         ; <long> [#uses=1]

instead of:

        %tmp.10 = shl long %Y, ubyte 1          ; <long> [#uses=1]
        %tmp.6 = add long %Y, %tmp.10               ; <long> [#uses=1]


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17701 91177308-0d34-0410-b5e6-96231b3b80d8
2004-11-13 19:31:40 +00:00
Chris Lattner
f158092801 Fix some warnings on VC++
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17481 91177308-0d34-0410-b5e6-96231b3b80d8
2004-11-05 04:45:43 +00:00
Chris Lattner
d308f8a87f * Rearrange code slightly
* Disable broken transforms for simplifying (setcc (cast X to larger), CI)
  where CC is not != or ==


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17422 91177308-0d34-0410-b5e6-96231b3b80d8
2004-11-02 03:50:32 +00:00
Chris Lattner
dc78122242 Hrm, this code was severely botched. As it turns out, this patch:
http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20041018/019708.html

exposed ANOTHER latent bug in this xform, which caused Prolangs-C/bison to fill
the zion nightly tester disk up and make the tester barf.

This is obviously not a good thing, so lets fix this bug shall we? :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17276 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-27 05:57:15 +00:00
Chris Lattner
9b9918246c Fix a bug Nate noticed, where we miscompiled a simple testcase
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17157 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-22 04:53:16 +00:00
Chris Lattner
17be63552a Turn things with obviously undefined semantics into 'store -> null'
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17110 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-18 02:59:09 +00:00
Chris Lattner
77bcee74da My friend the invoke instruction does not dominate all basic blocks if it
occurs in the entry node of a function


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17109 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-18 01:48:31 +00:00
Chris Lattner
ca45930548 Remove printout, realize that instructions in the entry block dominate all
other blocks.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17099 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-17 21:31:34 +00:00
Chris Lattner
c30bda7540 hasConstantValue will soon return instructions that don't dominate the PHI node,
so prepare for this.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17095 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-17 21:22:38 +00:00
Chris Lattner
79a564caa7 Fix a type violation
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17069 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-16 23:28:04 +00:00
Chris Lattner
6e758aee74 Kill the bogon that slipped into my buffer before I committed.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17067 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-16 19:46:33 +00:00
Chris Lattner
061718cba8 Implement InstCombine/getelementptr.ll:test9, which is the source of many
ugly and giant constnat exprs in some programs.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17066 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-16 19:44:59 +00:00
Chris Lattner
e87597fb75 Optimize instructions involving undef values. For example X+undef == undef.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17047 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-16 18:11:37 +00:00
Chris Lattner
35b9e48cfd Transform memmove -> memcpy when the source is obviously constant memory.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16932 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-12 04:52:52 +00:00
Chris Lattner
6a9fdfaec8 Reenable the transform, turning X/-10 < 1 into X > -10
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16918 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-11 19:40:04 +00:00
Chris Lattner
a052f8297a Implement sub.ll:test17, -X/C -> X/-C
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16863 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-09 02:50:40 +00:00
Chris Lattner
340a05fb3a Temporarily disable a buggy transformation until it can be fixed. This fixes
254.gap.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16853 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-08 19:15:44 +00:00
Chris Lattner
b99d6b1cac Instcombine (X & FF00) + xx00 -> (X+xx00) & FF00, implementing and.ll:test27
This comes up when doing adds to bitfield elements.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16836 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-08 05:07:56 +00:00
Chris Lattner
1f7e160f77 Little patch to turn (shl (add X, 123), 4) -> (add (shl X, 4), 123 << 4)
This triggers in cases of bitfield additions, opening opportunities for
future improvements.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16834 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-08 03:46:20 +00:00
Chris Lattner
91ccc15b45 Instcombine: -(X sdiv C) -> (X sdiv -C), tested by sub.ll:test16
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16769 91177308-0d34-0410-b5e6-96231b3b80d8
2004-10-06 15:08:25 +00:00
Chris Lattner
a71989f11b Hrm, debugging printouts do not need to be in here
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16598 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-29 21:21:14 +00:00
Chris Lattner
a96879a26d * Pull range optimization code out into new InsertRangeTest function.
* SubOne/AddOne functions always return ConstantInt, declare them as such
* Pull code for handling setcc X, cst, where cst is at the end of the range,
  or cc is LE or GE up earlier in visitSetCondInst.  This reduces #iterations
  in some cases.
* Fold: (div X, C1) op C2 -> range check, implementing div.ll:test6 - test9.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16588 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-29 17:40:11 +00:00
Chris Lattner
4e998b2fea Fold binary expressions and casts into PHI nodes that have all constant inputs.
This takes something like this:

%A = phi int [ 3, %cond_false.0 ], [ 2, %endif.0.i ], [ 2, %endif.1.i ]
%B = div int %tmp.243, 4

and turns it into:

%A = phi int [ 3/4, %cond_false.0 ], [ 2/4, %endif.0.i ], [ 2/4, %endif.1.i ]

which is later simplified (in this case) into %A = 0.

This triggers thousands of times in spec, for example, 269 times in 176.gcc.

This is tested by InstCombine/add.ll:test23 and set.ll:test18.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16582 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-29 05:07:12 +00:00
Chris Lattner
dd763f401e Hrm, really, all tests passed without this, but it is scary to think how...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16568 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-29 03:16:24 +00:00
Chris Lattner
f6d1d7d2ba Remove debugging printout
Instcombine (setcc (truncate X), C1).

This occurs THOUSANDS of times in many benchmarks.  Particularlly common
seem to be things like (seteq (cast bool X to int), int 0)

This turns it into (seteq bool %X, false), which then becomes (not %X).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16567 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-29 03:09:18 +00:00
Chris Lattner
b4f40d2059 Fold (X setcc C1) | (X setcc C2)
This implements or.ll:test1[89]


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16561 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-28 22:33:08 +00:00
Chris Lattner
955f331a77 Fold (and (setcc X, C1), (setcc X, C2))
This is important for several reasons:

1. Benchmarks have lots of code that looks like this (perlbmk in particular):

  %tmp.2.i = setne int %tmp.0.i, 128              ; <bool> [#uses=1]
  %tmp.6343 = seteq int %tmp.0.i, 1               ; <bool> [#uses=1]
  %tmp.63 = and bool %tmp.2.i, %tmp.6343          ; <bool> [#uses=1]

   we now fold away the setne, a clear improvement.

2. In the more important cases, such as (X >= 10) & (X < 20), we now produce
   smaller code: (X-10) < 10.

3. Perhaps the nicest effect of this patch is that it really helps out the
   code generators.  In particular, for a 'range test' like the above,
   instead of generating this on X86 (the difference on PPC is even more
   pronounced):

        cmp %EAX, 50
        setge %CL
        cmp %EAX, 100
        setl %AL
        and %CL, %AL
        cmp %CL, 0

   we now generate this:

        add %EAX, -50
        cmp %EAX, 50

   Furthermore, this causes setcc's to be folded into branches more often.

These combinations trigger dozens of times in the spec benchmarks, particularly
in 176.gcc, 186.crafty, 253.perlbmk, 254.gap, & 099.go.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16559 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-28 21:48:02 +00:00
Chris Lattner
18d19ca6df Implement X / C1 / C2 folding
Implement (setcc (shl X, C1), C2) folding.

The second one occurs several dozen times in spec.  The first was added
just in case.  :)

These are tested by shift.ll:test2[12], and div.ll:test5


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16549 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-28 18:22:15 +00:00
Chris Lattner
0cba71b0d6 shl is always zero extending, so always use a zero extending shift right.
This latent bug was exposed by recent changes, and is tested as:
llvm/test/Regression/Transforms/InstCombine/2004-09-28-BadShiftAndSetCC.llx


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16546 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-28 17:54:07 +00:00
Chris Lattner
83c4ec0372 Fix two bugs: one where a condition was mistakenly swapped, and another
where we folded (X & 254) -> X < 1 instead of X < 2.  These problems were
latent problems exposed by the latest patch.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16528 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-27 19:29:18 +00:00
Chris Lattner
f63f647345 Fold: (setcc (shr X, ShAmt), CI), where 'cc' is eq or ne. This xform
triggers often, for example:

6x in povray, 1x in gzip, 279x in gcc, 1x in crafty, 8x in eon, 11x in perlbmk,
362x in gap, 4x in vortex, 14 in m88ksim, 211x in 126.gcc, 1x in compress,
11x in ijpeg, and 4x in 147.vortex.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16521 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-27 16:18:50 +00:00
Chris Lattner
0c96766c90 Implement shift-and combinations, implementing InstCombine/and.ll:test19-21
These combinations trigger 4 times in povray, 7x in gcc, 4x in gap, and 2x in bzip2.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16508 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-24 15:21:34 +00:00
Chris Lattner
648e3bc39c Move LHSI->hasOneUse() into the arms of the conditional, reindenting code.
No functionality changes here.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16505 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-23 21:52:49 +00:00
Chris Lattner
b20ba0a83f Implement Transforms/InstCombine/and.ll:test18, a case that occurs 20 times
in perlbmk


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16504 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-23 21:46:38 +00:00
Chris Lattner
684fe210a9 Implement select.ll:test16: fold load (select C, X, null) -> load X
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16499 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-23 15:46:00 +00:00
Chris Lattner
3d834bf2c3 Do not fold (X + C1 != C2) if there are other users of the add. Doing
this transformation used to take a loop like this:

int Array[1000];
void test(int X) {
  int i;
  for (i = 0; i < 1000; ++i)
    Array[i] += X;
}

Compiled to LLVM is:

no_exit:                ; preds = %entry, %no_exit
        %indvar = phi uint [ 0, %entry ], [ %indvar.next, %no_exit ]            ; <uint> [#uses=2]
        %tmp.4 = getelementptr [1000 x int]* %Array, int 0, uint %indvar                ; <int*> [#uses=2]
        %tmp.7 = load int* %tmp.4               ; <int> [#uses=1]
        %tmp.9 = add int %tmp.7, %X             ; <int> [#uses=1]
        store int %tmp.9, int* %tmp.4
***     %indvar.next = add uint %indvar, 1              ; <uint> [#uses=2]
***     %exitcond = seteq uint %indvar.next, 1000               ; <bool> [#uses=1]
        br bool %exitcond, label %return, label %no_exit

and turn it into a loop like this:

no_exit:                ; preds = %entry, %no_exit
        %indvar = phi uint [ 0, %entry ], [ %indvar.next, %no_exit ]            ; <uint> [#uses=3]
        %tmp.4 = getelementptr [1000 x int]* %Array, int 0, uint %indvar                ; <int*> [#uses=2]
        %tmp.7 = load int* %tmp.4               ; <int> [#uses=1]
        %tmp.9 = add int %tmp.7, %X             ; <int> [#uses=1]
        store int %tmp.9, int* %tmp.4
***     %indvar.next = add uint %indvar, 1              ; <uint> [#uses=1]
***     %exitcond = seteq uint %indvar, 999             ; <bool> [#uses=1]
        br bool %exitcond, label %return, label %no_exit

Note that indvar.next and indvar can no longer be coallesced.  In machine
code terms, this patch changes this code:

.LBBtest_1:     # no_exit
        mov %EDX, OFFSET Array
        mov %ESI, %EAX
        add %ESI, DWORD PTR [%EDX + 4*%ECX]
        mov %EDX, OFFSET Array
        mov DWORD PTR [%EDX + 4*%ECX], %ESI
        mov %EDX, %ECX
        inc %EDX
        cmp %ECX, 999
        mov %ECX, %EDX
        jne .LBBtest_1  # no_exit

into this:

.LBBtest_1:     # no_exit
        mov %EDX, OFFSET Array
        mov %ESI, %EAX
        add %ESI, DWORD PTR [%EDX + 4*%ECX]
        mov %EDX, OFFSET Array
        mov DWORD PTR [%EDX + 4*%ECX], %ESI
        inc %ECX
        cmp %ECX, 1000
        jne .LBBtest_1  # no_exit

We need better instruction selection to get this:

.LBBtest_1:     # no_exit
        add DWORD PTR [Array + 4*%ECX], EAX
        inc %ECX
        cmp %ECX, 1000
        jne .LBBtest_1  # no_exit

... but at least there is less register juggling


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16473 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-21 21:35:23 +00:00
Chris Lattner
79f0c8e4ee Fix potential miscompilations: InstCombine/2004-09-20-BadLoadCombine*.llx
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16447 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-20 10:15:10 +00:00
Alkis Evlogimenos
7b6ec600c5 Fix loop condition so that we don't decrement off the beginning of the
list.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16440 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-20 06:42:58 +00:00
Chris Lattner
8a37520f80 Make isSafeToLoadUnconditionally a bit smarter, implementing PR362 and
Regression/Transforms/InstCombine/CPP_min_max.llx


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16409 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-19 19:18:10 +00:00
Chris Lattner
c10acedb2d Make instruction combining a bit more aggressive in the face of volatile
loads, and implement two new transforms: InstCombine/load.ll:test[56].


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16404 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-19 18:43:46 +00:00
Reid Spencer
551ccae044 Changes For Bug 352
Move include/Config and include/Support into include/llvm/Config,
include/llvm/ADT and include/llvm/Support. From here on out, all LLVM
public header files must be under include/llvm/.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16137 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-01 22:55:40 +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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
c32b30a429 Implement select.ll:test[3-6]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12544 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-30 19:37:13 +00:00
Chris Lattner
4df1b8aa26 X % -1 == X % 1 == 0
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12520 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-26 16:11:24 +00:00
Chris Lattner
ebd985cb87 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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12519 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-25 22:59:29 +00:00
Chris Lattner
7c881dffc9 Teach the optimizer to delete zero sized alloca's (but not mallocs!)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12507 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-19 06:08:10 +00:00
Chris Lattner
0cea42a560 Add some debugging output
Fix InstCombine/2004-03-13-InstCombineInfLoop.ll which caused an infinite
loop compiling (I think) povray.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12365 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-13 23:54:27 +00:00
Chris Lattner
bfe492b5c2 Implement sub.ll:test14
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12355 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-13 00:11:49 +00:00
Chris Lattner
9c2906744a Implement InstCombine/sub.ll:test12 & test13
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12353 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-12 23:53:13 +00:00
Chris Lattner
3d69f46d64 Add trivial optimizations for select instructions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12317 91177308-0d34-0410-b5e6-96231b3b80d8
2004-03-12 05:52:32 +00:00
Chris Lattner
7bcc0e7fff Rename AddUsesToWorkList -> AddUsersToWorkList, as that is what it does.
Create a new AddUsesToWorkList method
optimize memmove/set/cpy of zero bytes to a noop.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11941 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-28 05:22:00 +00:00
Chris Lattner
6160e85201 Turn 'free null' into nothing
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11940 91177308-0d34-0410-b5e6-96231b3b80d8
2004-02-28 04:57:37 +00:00