Commit Graph

453 Commits

Author SHA1 Message Date
Chris Lattner
98509ef3c7 Don't crash on packed logical ops
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27125 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-25 21:58:26 +00:00
Jim Laskey
930ac0606c Can't combine anymore - we don't have a chain through llvm.dbg intrinsics.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26992 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-23 18:10:42 +00:00
Chris Lattner
51c26e911a Teach the alignment handling code to look through constant expr casts and GEPs
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26580 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-07 01:28:57 +00:00
Chris Lattner
95a959dc1a Teach instcombine to increase the alignment of memset/memcpy/memmove when
the pointer is known to come from either a global variable, alloca or
malloc.  This allows us to compile this:

  P = malloc(28);
  memset(P, 0, 28);

into explicit stores on PPC instead of a memset call.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26577 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-06 20:18:44 +00:00
Chris Lattner
220b0cf3e4 Make vector narrowing more effective, implementing
Transforms/InstCombine/vec_narrow.ll.  This add support for narrowing
extract_element(insertelement) also.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26538 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-05 00:22:33 +00:00
Chris Lattner
ab51f3fa96 Canonicalize (X+C1)*C2 -> X*C2+C1*C2
This implements Transforms/InstCombine/add.ll:test31


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26519 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-04 06:04:02 +00:00
Chris Lattner
21959390c1 Change this to work with renamed intrinsics.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26484 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-03 01:34:17 +00:00
Chris Lattner
db3f873bd8 Generalize the REM folding code to handle another case Nick Lewycky
pointed out: realize the AND can provide factors and look through Casts.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26469 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-02 06:50:58 +00:00
Chris Lattner
06e1e25368 Fix a regression in a patch from a couple of days ago. This fixes
Transforms/InstCombine/2006-02-28-Crash.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26427 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-28 19:47:20 +00:00
Chris Lattner
9794392781 Implement rem.ll:test[7-9] and PR712
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26415 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-28 05:49:21 +00:00
Chris Lattner
6c9951b0da Simplify some code now that the RHS of a rem can't be 0
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26413 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-28 05:40:55 +00:00
Chris Lattner
19ccd5c757 Rearrange some code, fold "rem X, 0", implementing rem.ll:test6
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26411 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-28 05:30:45 +00:00
Chris Lattner
3e88a4d700 Merge two almost-identical pieces of code.
Make this code more powerful by using ComputeMaskedBits instead of looking
for an AND operand.  This lets us fold this:

int %test23(int %a) {
        %tmp.1 = and int %a, 1
        %tmp.2 = seteq int %tmp.1, 0
        %tmp.3 = cast bool %tmp.2 to int  ;; xor tmp1, 1
        ret int %tmp.3
}

into: xor (and a, 1), 1


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26396 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-27 02:38:23 +00:00
Chris Lattner
26ab9a9218 Fold (A^B) == A -> B == 0
and  (A-B) == A  ->  B == 0


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26394 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-27 01:44:11 +00:00
Chris Lattner
02bd1b3e94 Fold (X|C1)^C2 -> X^(C1|C2) when possible. This implements
InstCombine/or.ll:test23.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26385 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-26 19:57:54 +00:00
Chris Lattner
97f37a439c Fix a problem that Nate noticed that boils down to an over conservative check
in the code that does "select C, (X+Y), (X-Y) --> (X+(select C, Y, (-Y)))".
We now compile this loop:

LBB1_1: ; no_exit
        add r6, r2, r3
        subf r3, r2, r3
        cmpwi cr0, r2, 0
        addi r7, r5, 4
        lwz r2, 0(r5)
        addi r4, r4, 1
        blt cr0, LBB1_4 ; no_exit
LBB1_3: ; no_exit
        mr r3, r6
LBB1_4: ; no_exit
        cmpwi cr0, r4, 16
        mr r5, r7
        bne cr0, LBB1_1 ; no_exit

into this instead:

LBB1_1: ; no_exit
        srawi r6, r2, 31
        add r2, r2, r6
        xor r6, r2, r6
        addi r7, r5, 4
        lwz r2, 0(r5)
        addi r4, r4, 1
        add r3, r3, r6
        cmpwi cr0, r4, 16
        mr r5, r7
        bne cr0, LBB1_1 ; no_exit


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26356 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-24 18:05:58 +00:00
Jeff Cohen
bce4805d6f Fix bugs identified by VC++.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26287 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-18 03:20:33 +00:00
Nate Begeman
368e18d56a Rework the SelectionDAG-based implementations of SimplifyDemandedBits
and ComputeMaskedBits to match the new improved versions in instcombine.
Tested against all of multisource/benchmarks on ppc.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26238 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-16 21:11:51 +00:00
Chris Lattner
2082ad9b41 Implement Instcombine/and.ll:test34
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26155 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-13 23:07:23 +00:00
Chris Lattner
f345fe4d9a If any of the sign extended bits are demanded, the input sign bit is demanded
for a sign extension.

This fixes InstCombine/2006-02-13-DemandedMiscompile.ll and Ptrdist/bc.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26152 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-13 22:41:07 +00:00
Chris Lattner
c15637bafc Be careful not to request or look at bits shifted in from outside the size
of the input.  This fixes the mediabench/gsm/toast failure last night.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26138 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-13 06:09:08 +00:00
Chris Lattner
8d6bbdbbcb remove some more dead special case code
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26135 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-12 08:07:37 +00:00
Chris Lattner
f8c36f502b Eliminate special case hacks that are superceded by general purpose hacks
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26134 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-12 08:02:11 +00:00
Chris Lattner
bf5d8a8270 Three changes:
1. Teach GetConstantInType to handle boolean constants.
2. Teach instcombine to fold (compare X, CST) when X has known 0/1 bits.
   Testcase here: set.ll:test22
3. Improve the "(X >> c1) & C2 == 0" folding code to allow a noop cast
   between the shift and and.  More aggressive bitfolding for other reasons
   was turning signed shr's into unsigned shr's, leaving the noop cast in
   the way.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26131 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-12 02:07:56 +00:00
Chris Lattner
255d8919b6 Port the recent innovations in ComputeMaskedBits to SimplifyDemandedBits.
This allows us to simplify on conditions where bits are not known, but they
are not demanded either!  This also fixes a couple of bugs in
ComputeMaskedBits that were exposed during this work.

In the future, swaths of instcombine should be removed, as this code
subsumes a bunch of ad-hockery.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26122 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-11 09:31:47 +00:00
Chris Lattner
9a4cacb7c2 Fix 80-column violations
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26088 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-09 07:41:14 +00:00
Chris Lattner
68d5ff2b83 Enhance MVIZ in three ways:
1. Teach it new tricks: in particular how to propagate through signed shr and sexts.
2. Teach it to return a bitset of known-1 and known-0 bits, instead of just zero.
3. Teach instcombine (AND X, C) to fold when we know all C bits of X.

This implements Regression/Transforms/InstCombine/bittest.ll, and allows
future things to be simplified.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26087 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-09 07:38:58 +00:00
Chris Lattner
7560c3af83 Simplify some code, reducing calls to MaskedValueIsZero. Implement a minor
optimization where we reduce the number of bits in AND masks when possible.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26056 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-08 07:34:50 +00:00
Chris Lattner
9ca96410fc Use EraseInstFromFunction in a few cases to put the uses of the removed
instruction onto the worklist (in case they are now dead).

Add a really trivial local DSE implementation to help out bitfield code.
We now fold this:

struct S {
    unsigned char a : 1, b : 1, c : 1, d : 2, e : 3;
    S();
};

S::S() : a(0), b(0), c(1), d(0), e(6) {}

to this:

void %_ZN1SC1Ev(%struct.S* %this) {
entry:
        %tmp.1 = getelementptr %struct.S* %this, int 0, uint 0
        store ubyte 38, ubyte* %tmp.1
        ret void
}

much earlier (in gccas instead of only in gccld after DSE runs).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26050 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-08 03:25:32 +00:00
Chris Lattner
62d1ade893 Fix a problem in my patch yesterday, causing a miscompilation of 176.gcc
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26045 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-08 01:20:23 +00:00
Chris Lattner
d89d888cc5 Fix Transforms/InstCombine/2006-02-07-SextZextCrash.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26040 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-07 19:07:40 +00:00
Chris Lattner
74c51a0ff2 Generalize MaskedValueIsZero into a ComputeMaskedNonZeroBits function, which
is just as efficient as MVIZ and is also more general.

Fix a few minor bugs introduced in recent patches


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26036 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-07 08:05:22 +00:00
Chris Lattner
3bedbd9d71 Make MaskedValueIsZero take a uint64_t instead of a ConstantIntegral as a
mask.  This allows the code to be simpler and more efficient.

Also, generalize some of the cases in MVIZ a bit, making it slightly more aggressive.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26035 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-07 07:27:52 +00:00
Chris Lattner
1a074fce15 Use Type::getIntegralTypeMask() to simplify some code
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26034 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-07 07:00:41 +00:00
Chris Lattner
6dce1a7dfe Implement the beginnings of a facility for simplifying expressions based on
'demanded bits', inspired by Nate's work in the dag combiner.  This isn't
complete, but needs to unrelated instcombiner changes to continue.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26033 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-07 06:56:34 +00:00
Chris Lattner
5f3b0eeddb Turn A % (C << N), where C is 2^k, into A & ((C << N)-1) [urem only].
Turn A / (C1 << N), where C1 is "1<<C2" into A >> (N+C2) [udiv only].

Tested with: rem.ll:test5, div.ll:test10


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26003 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-05 07:54:04 +00:00
Chris Lattner
dac58ad983 Make iostream #inclusion explicit
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25514 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-22 23:32:06 +00:00
Chris Lattner
bc528efa76 Implement casts.ll:test26: a cast from float -> double -> integer, doesn't
need the float->double part.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25452 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-19 07:40:22 +00:00
Chris Lattner
72223eea95 fix a crash due to missing parens
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25363 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-16 19:47:21 +00:00
Robert Bocchino
1d7456d0bf Added instcombine support for extractelement.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25299 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-13 22:48:06 +00:00
Chris Lattner
a728ddc815 Do a simple instcombine xforms to delete llvm.stackrestore cases.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25294 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-13 21:28:09 +00:00
Chris Lattner
8b0ea313d9 Simplify this a tiny bit by using the new IntrinsicInst functionality.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25292 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-13 20:11:04 +00:00
Chris Lattner
e8d56c536d fix some 176.gcc miscompilation from my previous patch.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25137 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-07 01:32:28 +00:00
Chris Lattner
4f637d4db1 silence some bogus gcc warnings on fenris
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25130 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-06 17:59:59 +00:00
Chris Lattner
ad0124c188 Enhance the shift-shift folding code to allow a no-op cast to occur in between
the shifts.

This allows us to fold this (which is the 'integer add a constant' sequence
from cozmic's scheme compmiler):

int %x(uint %anf-temporary776) {
        %anf-temporary777 = shr uint %anf-temporary776, ubyte 1
        %anf-temporary800 = cast uint %anf-temporary777 to int
        %anf-temporary804 = shl int %anf-temporary800, ubyte 1
        %anf-temporary805 = add int %anf-temporary804, -2
        %anf-temporary806 = or int %anf-temporary805, 1
        ret int %anf-temporary806
}

into this:

int %x(uint %anf-temporary776) {
        %anf-temporary776 = cast uint %anf-temporary776 to int
        %anf-temporary776.mask1 = add int %anf-temporary776, -2
        %anf-temporary805 = or int %anf-temporary776.mask1, 1
        ret int %anf-temporary805
}

note that instcombine already knew how to eliminate the AND that the two
shifts fold into.  This is tested by InstCombine/shift.ll:test26

-Chris


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25128 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-06 07:52:12 +00:00
Chris Lattner
830ed03e8b Simplify the code a bit more
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25126 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-06 07:22:22 +00:00
Chris Lattner
4d5542ce6e Extract a bunch of code out of visitShiftInst into FoldShiftByConstant. No
functionality changes.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25125 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-06 07:12:35 +00:00
Nate Begeman
14b0529532 Add support alignment of allocation instructions.
Add support for specifying alignment and size of setjmp jmpbufs.

No targets currently do anything with this information, nor is it presrved
in the bytecode representation.  That's coming up next.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24196 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-05 09:21:28 +00:00
Chris Lattner
c812e5d6b8 Turn sdiv into udiv if both operands have a clear sign bit. This occurs
a few times in crafty:

OLD:    %tmp.36 = div int %tmp.35, 8            ; <int> [#uses=1]
NEW:    %tmp.36 = div uint %tmp.35, 8           ; <uint> [#uses=0]
OLD:    %tmp.19 = div int %tmp.18, 8            ; <int> [#uses=1]
NEW:    %tmp.19 = div uint %tmp.18, 8           ; <uint> [#uses=0]
OLD:    %tmp.117 = div int %tmp.116, 8          ; <int> [#uses=1]
NEW:    %tmp.117 = div uint %tmp.116, 8         ; <uint> [#uses=0]
OLD:    %tmp.92 = div int %tmp.91, 8            ; <int> [#uses=1]
NEW:    %tmp.92 = div uint %tmp.91, 8           ; <uint> [#uses=0]

Which all turn into shrs.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24190 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-05 07:40:31 +00:00
Chris Lattner
11a49f2c0d Turn srem -> urem when neither input has their sign bit set. This triggers
8 times in vortex, allowing the srems to be turned into shrs:

OLD:    %tmp.104 = rem int %tmp.5.i37, 16               ; <int> [#uses=1]
NEW:    %tmp.104 = rem uint %tmp.5.i37, 16              ; <uint> [#uses=0]
OLD:    %tmp.98 = rem int %tmp.5.i24, 16                ; <int> [#uses=1]
NEW:    %tmp.98 = rem uint %tmp.5.i24, 16               ; <uint> [#uses=0]
OLD:    %tmp.91 = rem int %tmp.5.i19, 8         ; <int> [#uses=1]
NEW:    %tmp.91 = rem uint %tmp.5.i19, 8                ; <uint> [#uses=0]
OLD:    %tmp.88 = rem int %tmp.5.i14, 8         ; <int> [#uses=1]
NEW:    %tmp.88 = rem uint %tmp.5.i14, 8                ; <uint> [#uses=0]
OLD:    %tmp.85 = rem int %tmp.5.i9, 1024               ; <int> [#uses=2]
NEW:    %tmp.85 = rem uint %tmp.5.i9, 1024              ; <uint> [#uses=0]
OLD:    %tmp.82 = rem int %tmp.5.i, 512         ; <int> [#uses=2]
NEW:    %tmp.82 = rem uint %tmp.5.i1, 512               ; <uint> [#uses=0]
OLD:    %tmp.48.i = rem int %tmp.5.i.i161, 4            ; <int> [#uses=1]
NEW:    %tmp.48.i = rem uint %tmp.5.i.i161, 4           ; <uint> [#uses=0]
OLD:    %tmp.20.i2 = rem int %tmp.5.i.i, 4              ; <int> [#uses=1]
NEW:    %tmp.20.i2 = rem uint %tmp.5.i.i, 4             ; <uint> [#uses=0]

it also occurs 9 times in gcc, but with odd constant divisors (1009 and 61)
so the payoff isn't as great.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24189 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-05 07:28:37 +00:00