Commit Graph

2606 Commits

Author SHA1 Message Date
Andrew Lenharth
3433141a3e Add a simple pass to make sure that all (non-library) calls to malloc and free
are visible to analysis as intrinsics.  That is, make sure someone doesn't pass
free around by address in some struct (as happens in say 176.gcc).

This doesn't get rid of any indirect calls, just ensure calls to free and malloc
are always direct.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27560 91177308-0d34-0410-b5e6-96231b3b80d8
2006-04-10 19:26:09 +00:00
Chris Lattner
543abdf1d0 Add supprot for shufflevector
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27513 91177308-0d34-0410-b5e6-96231b3b80d8
2006-04-08 01:19:12 +00:00
Chris Lattner
8960766d45 Fix inlining of insert/extract element constantexprs
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27478 91177308-0d34-0410-b5e6-96231b3b80d8
2006-04-07 04:41:03 +00:00
Chris Lattner
e2ed057562 Lower vperm(x,y, mask) -> shuffle(x,y,mask) if mask is constant. This allows
us to compile oh-so-realistic stuff like this:

 vec_vperm(A, B, (vector unsigned char){14});

to:
        vspltb v0, v0, 14

instead of:

        vspltisb v0, 14
        vperm v0, v2, v1, v0


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27452 91177308-0d34-0410-b5e6-96231b3b80d8
2006-04-06 19:19:17 +00:00
Chris Lattner
4132afb0d2 vector casts of casts are eliminable. Transform this:
%tmp = cast <4 x uint> %tmp to <4 x int>                ; <<4 x int>> [#uses=1]
        %tmp = cast <4 x int> %tmp to <4 x float>               ; <<4 x float>> [#uses=1]

into:

        %tmp = cast <4 x uint> %tmp to <4 x float>              ; <<4 x float>> [#uses=1]


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27355 91177308-0d34-0410-b5e6-96231b3b80d8
2006-04-02 05:43:13 +00:00
Chris Lattner
a1c3538537 Allow transforming this:
%tmp = cast <4 x uint>* %testData to <4 x int>*         ; <<4 x int>*> [#uses=1]
        %tmp = load <4 x int>* %tmp             ; <<4 x int>> [#uses=1]

to this:

        %tmp = load <4 x uint>* %testData               ; <<4 x uint>> [#uses=1]
        %tmp = cast <4 x uint> %tmp to <4 x int>                ; <<4 x int>> [#uses=1]


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27353 91177308-0d34-0410-b5e6-96231b3b80d8
2006-04-02 05:37:12 +00:00
Chris Lattner
82ed58f9c4 Turn altivec lvx/stvx intrinsics into loads and stores. This allows the
elimination of one load from this:

int AreSecondAndThirdElementsBothNegative( vector float *in ) {
#define QNaN 0x7FC00000
const vector unsigned int testData = (vector unsigned int)( QNaN, 0, 0, QNaN );
vector float test = vec_ld( 0, (float*) &testData );
return ! vec_any_ge( test, *in );
}

Now generating:

_AreSecondAndThirdElementsBothNegative:
        mfspr r2, 256
        oris r4, r2, 49152
        mtspr 256, r4
        li r4, lo16(LCPI1_0)
        lis r5, ha16(LCPI1_0)
        addi r6, r1, -16
        lvx v0, r5, r4
        stvx v0, 0, r6
        lvx v1, 0, r3
        vcmpgefp. v0, v0, v1
        mfcr r3, 2
        rlwinm r3, r3, 27, 31, 31
        xori r3, r3, 1
        cntlzw r3, r3
        srwi r3, r3, 5
        mtspr 256, r2
        blr


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27352 91177308-0d34-0410-b5e6-96231b3b80d8
2006-04-02 05:30:25 +00:00
Chris Lattner
7224f84c15 Adjust to change in Intrinsics.gen interface.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27344 91177308-0d34-0410-b5e6-96231b3b80d8
2006-04-02 03:35:01 +00:00
Chris Lattner
3805dea3fe add valuemapper support for inline asm
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27332 91177308-0d34-0410-b5e6-96231b3b80d8
2006-04-01 23:17:11 +00:00
Chris Lattner
ae1ab3989c Fix InstCombine/2006-04-01-InfLoop.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27330 91177308-0d34-0410-b5e6-96231b3b80d8
2006-04-01 22:05:01 +00:00
Chris Lattner
64daab56c2 Fold A^(B&A) -> (B&A)^A
Fold (B&A)^A == ~B & A

This implements InstCombine/xor.ll:test2[56]


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27328 91177308-0d34-0410-b5e6-96231b3b80d8
2006-04-01 08:03:55 +00:00
Chris Lattner
6e6b0da303 If we can look through vector operations to find the scalar version of an
extract_element'd value, do so.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27323 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-31 23:01:56 +00:00
Chris Lattner
1f13c88939 extractelement(undef,x) -> undef
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27300 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-31 18:25:14 +00:00
Chris Lattner
df084ff78b Fix Transforms/InstCombine/2006-03-30-ExtractElement.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27261 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-30 22:02:40 +00:00
Chris Lattner
49aaa6a8ee teach the inliner to work with packed constants
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27161 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-27 05:50:18 +00:00
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
Chris Lattner
98d9811db2 Fix spello
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27052 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-24 07:14:34 +00:00
Chris Lattner
0f862e50ae add the actual cost to the debug info
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27051 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-24 07:14:00 +00:00
Jim Laskey
4ca9757a39 Strip changes to llvm.dbg intrinsics.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26993 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-23 18:11:33 +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
035c6a2356 silence a bogus gcc warning
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26953 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-22 17:27:24 +00:00
Chris Lattner
273f202890 Teach cee to propagate through switch statements. This implements
Transforms/CorrelatedExprs/switch.ll

Patch contributed by Eric Kidd!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26872 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-19 19:37:24 +00:00
Evan Cheng
21495775e7 - Fixed a bogus if condition.
- Added more debugging info.
- Allow reuse of IV of negative stride. e.g. -4 stride == 2 * iv of -2 stride.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26841 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-18 08:03:12 +00:00
Evan Cheng
4496a50deb Sort StrideOrder so we can process the smallest strides first. This allows
for more IV reuses.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26837 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-18 00:44:49 +00:00
Evan Cheng
eb8f9e2297 Allow users of iv / stride to be rewritten with expression that is a multiply
of a smaller stride even if they have a common loop invariant expression part.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26828 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-17 19:52:23 +00:00
Evan Cheng
d1d6b5cce2 For each loop, keep track of all the IV expressions inserted indexed by
stride. For a set of uses of the IV of a stride which is a multiple
of another stride, do not insert a new IV expression. Rather, reuse the
previous IV and rewrite the uses as uses of IV expression multiplied by
the factor.

e.g.
x = 0 ...; x ++
y = 0 ...; y += 4
then use of y can be rewritten as use of 4*x for x86.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26803 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-16 21:53:05 +00:00
Chris Lattner
b2f6c0075c Teach the strip pass to strip type names in addition to value names. This
is fallout from the type/value split in the symtab long long ago :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26785 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-15 19:22:41 +00:00
Chris Lattner
e9efecbf47 Implement a FIXME, recusively reassociating
A*A*B + A*A*C   -->   A*(A*B+A*C)   -->   A*(A*(B+C))

This implements Reassociate/mul-factor3.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26757 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-14 16:04:29 +00:00
Chris Lattner
895b392269 extract some code into a method, no functionality change
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26755 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-14 07:11:11 +00:00
Chris Lattner
22a66c41f3 Promote shifts by a constant to multiplies so that we can reassociate
(x<<1)+(y<<1) -> (X+Y)<<1.  This implements
Transforms/Reassociate/shift-factor.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26753 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-14 06:55:18 +00:00
Evan Cheng
d277f2c669 Added target lowering hooks which LSR consults to make more intelligent
transformation decisions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26738 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-13 23:14:23 +00:00
Jim Laskey
f4321a3a43 Handle the removal of the debug chain.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26729 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-13 13:07:37 +00:00
Chris Lattner
aeebe7f208 use autogenerated side-effect information
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26673 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-09 22:38:10 +00:00
Chris Lattner
e2b59d2760 fix a pasto
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26627 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-09 06:09:41 +00:00
Chris Lattner
25de486263 Fix a miscompilation of 188.ammp with the new CFE. 188.ammp is accessing
arrays out of range in a horrible way, but we shouldn't break it anyway.
Details in the comments.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26606 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-08 01:05:29 +00:00
Jim Laskey
e8c3e3b51c Switch to using a numeric id for anchors.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26598 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-07 20:53:47 +00:00
Chris Lattner
e1c173bc77 Fix ConstantMerge/2006-03-07-DontMergeDiffSections.ll, a problem Jim
hypotheticalized about, where we would incorrectly merge two globals in
different sections.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26597 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-07 17:56:59 +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
e5022fe4cd Add factoring of multiplications, e.g. turning A*A+A*B into A*(A+B).
Testcase here: Transforms/Reassociate/mulfactor.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26524 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-04 09:31:13 +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
aecb0627fa Make this work with renamed intrinsics.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26482 91177308-0d34-0410-b5e6-96231b3b80d8
2006-03-03 01:30:23 +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
Chris Lattner
f8bf116f80 Fix Regression/Transforms/LoopUnswitch/2006-02-22-UnswitchCrash.ll, which
caused SPASS to fail building last night.

We can't trivially unswitch a loop if the exit block has phi nodes in it,
because we don't know which predecessor to use.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26320 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-22 23:55:00 +00:00
Chris Lattner
bd28e3f8ef Add some comments, simplify some code, and fix a bug that caused rewriting
to rewrite with the wrong value.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26311 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-22 06:37:14 +00:00
Chris Lattner
a6fc94b71e improved support for branch folding, still not enabled.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26289 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-18 07:57:38 +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
Chris Lattner
db41024a85 Implement deletion of dead blocks, currently disabled.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26285 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-18 02:42:34 +00:00
Chris Lattner
caf4893536 a previous patch completely disabled trivial unswitching, this fixees it.
Thanks to nate for pointing this out :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26280 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-18 01:32:04 +00:00
Chris Lattner
f4412d890d initial trivial support for folding branches that have now-constant destinations.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26279 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-18 01:27:45 +00:00
Chris Lattner
25cae0fd1c When unswitching a loop, make sure to update loop info with exit blocks in
the right loop.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26277 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-18 00:55:32 +00:00
Chris Lattner
299520de7c Fix Transforms/SimplifyCFG/2006-02-17-InfiniteUnroll.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26275 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-18 00:33:17 +00:00
Chris Lattner
0017d480cc Fix loops where the header has an exit, fixing a loop-unswitch crash on crafty
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26258 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-17 06:39:56 +00:00
Chris Lattner
52221f7b16 start of some new simplification code, not thoroughly tested, use at your own
risk :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26248 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-17 00:31:07 +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
10cd9bbde7 Change SplitBlock to increment a BasicBlock::iterator, not an Instruction*. Apparently they do different things :)
This fixes a testcase that nate reduced from spass.

Also included are a couple minor code changes that don't affect the generated
code at all.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26235 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-16 19:36:22 +00:00
Jeff Cohen
21c107ab0f Fix VC++ warning.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26228 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-16 04:07:37 +00:00
Chris Lattner
f17c42d409 fix a bug where we unswitched the wrong way
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26225 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-16 01:24:41 +00:00
Chris Lattner
a48654ef23 Implement trivial unswitching for switch stmts. This allows us to trivial
unswitch this loop on 2 before sweating to unswitch on 1/3.

void test4(int N, int i, int C, int*P, int*Q) {
  int j;
  for (j = 0; j < N; ++j) {
    switch (C) {                // general unswitching.
    default: P[i+j] = 0; break;
    case 1: Q[i+j] = 0; break;
    case 3: P[i+j] = Q[i+j]; break;
    case 2: break;              //  TRIVIAL UNSWITCH on C==2
    }
  }
}


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26223 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-15 22:52:05 +00:00
Chris Lattner
4e1323969c make "trivial" unswitching significantly more general. It can now handle
this for example:

  for (j = 0; j < N; ++j) {     // trivial unswitch
    if (C)
      P[i+j] = 0;
  }

turning it into the obvious code without bothering to duplicate an empty loop.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26220 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-15 22:03:36 +00:00
Andrew Lenharth
2f9859486a fix a bunch of alpha regressions. see bug 709
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26218 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-15 21:13:37 +00:00
Chris Lattner
3fdde110eb Checking the wrong value. This caused us to emit silly code like
Y = seteq bool X, true
instead of just using X :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26215 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-15 19:05:52 +00:00
Chris Lattner
6d9d13d2e4 more refactoring, no functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26194 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-15 01:44:42 +00:00
Chris Lattner
fed5d9dbd3 pull some code out into a function
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26191 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-15 00:07:43 +00:00
Chris Lattner
0ab9f966de Canonicalize inner loops before outer loops. Inner loop canonicalization
can provide work for the outer loop to canonicalize.

This fixes a case that breaks unswitching.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26189 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-14 23:06:02 +00:00
Chris Lattner
c27e056d4f When splitting exit edges to canonicalize loops, make sure to put the new
block in the appropriate loop nest.

Third time is the charm, right?


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26187 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-14 22:34:08 +00:00
Chris Lattner
3dd4c402de Use statistics to keep track of what flavors of loops we are unswitching
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26157 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-14 01:01:41 +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
ee628cfefb Revert my last patch. It too breaks stuff
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26128 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-12 01:59:10 +00:00
Chris Lattner
d308ddcd67 Fix for my previously reverted patch
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26126 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-11 21:24:54 +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
5077c7be92 revert my previous change, it exposed other problems.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26121 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-11 08:47:47 +00:00
Chris Lattner
8587eb3a51 Make this check stricter. Disallow loop exit blocks from being shared by
loops and their subloops.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26118 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-11 02:13:17 +00:00
Chris Lattner
441365c46e remove dead expr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26116 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-11 01:43:37 +00:00
Chris Lattner
c23580969f implement unswitching of loops with switch stmts and selects in them
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26114 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-11 00:43:37 +00:00
Chris Lattner
e825593bf2 Update PHI nodes in successors of exit blocks.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26113 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-10 23:26:14 +00:00
Chris Lattner
b2bc315eac Reform the unswitching code in terms of edge splitting, not block splitting.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26112 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-10 23:16:39 +00:00
Chris Lattner
81be2e961b Fix a case where UnswitchTrivialCondition broke critical edges with
phi's in the successors


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26108 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-10 19:08:15 +00:00
Chris Lattner
708e1a5c9c add some notes, move some code around. Implement unswitching of loops
with branches on partially invariant computations.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26104 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-10 02:30:37 +00:00
Chris Lattner
dd3ee6d086 Move code around to be more logical, no functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26103 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-10 02:01:22 +00:00
Chris Lattner
4d1ca946ea When unswitching a trivial loop, do admit we are doing it! :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26102 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-10 01:36:35 +00:00
Chris Lattner
4c41d49a92 Implement unconditional unswitching of 'trivial' loops, those loops that contain
branches in their entry block that control whether or not the loop is a noop or not.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26101 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-10 01:24:09 +00:00
Chris Lattner
f4f5f4e56f Simplify control flow a bit, note that unswitch preserves canonical loop form
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26098 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-09 22:15:42 +00:00
Chris Lattner
e487abbfbf Make the threshold a parameter
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26093 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-09 20:15:48 +00:00
Chris Lattner
2f4b898e8c Simplify the loop-unswitch pass, by not even trying to unswitch loops with
uses of loop values outside the loop.  We need loop-closed SSA form to do
this right, or to use SSA rewriting if we really care.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26089 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-09 19:14:52 +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
fe243ebb64 Implement some more interesting select sccp cases. This implements:
test/Regression/Transforms/SCCP/select.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26049 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-08 02:38:11 +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
0a70f219f4 Use SCEVExpander::InsertCastOfTo instead of our own code. This reduces
#LLVM LOC, and auto-cse's cast instructions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25974 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-04 09:52:43 +00:00
Chris Lattner
221fc3c6d6 Fix two significant bugs in LSR:
1. When rewriting code in outer loops, sometimes we would insert code into
   inner loops that is invariant in that loop.
2. Notice that 4*(2+x) is 8+4*x and use that to simplify expressions.

This is a performance neutral change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25964 91177308-0d34-0410-b5e6-96231b3b80d8
2006-02-04 07:36:50 +00:00
Jeff Cohen
9471c8a93b Improve compatibility with VC2005, patch by Morten Ofstad!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25661 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-26 20:41:32 +00:00
Chris Lattner
f47a6b4882 teach the cloner to handle inline asms
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25633 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-26 01:55:22 +00:00
Chris Lattner
15256cb14e Fix Regression/Transforms/ScalarRepl/2006-01-24-IllegalUnionPromoteCrash.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25587 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-24 19:36:27 +00:00
Chris Lattner
3e2fa7a746 rename method
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25572 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-24 04:16:34 +00:00
Chris Lattner
9771aeafca When cloning a module, clone the inline asm.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25559 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-23 23:06:28 +00:00
Chris Lattner
e46f6e99a0 add a bunch more optimizations for unary double math functions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25530 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-23 06:24:46 +00:00
Chris Lattner
7070c5f241 Refactor/genericize this, no functionality change
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25525 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-23 05:57:36 +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
e05cf71616 Make this more efficient in the following ways:
1. Do not statically construct a map when the program starts up, this
   is expensive and cannot be optimized.  Instead, create a list.
2. Do not insert entries for all function in the module into a hashmap
   that lives the full life of the compiler.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25512 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-22 23:10:26 +00:00
Chris Lattner
86a5484079 Add explicit #includes of <iostream>
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25509 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-22 22:53:01 +00:00
Chris Lattner
0f9f8c3759 Several non-functionality changing changes:
1. Use the varargs version of getOrInsertFunction to simplify code.
2. remove #include
3. Reduce the number of #ifdef's.
4. remove extraneous vertical whitespace.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25508 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-22 22:35:08 +00:00
Robert Bocchino
d900c6a8b3 ConstantFoldLoadThroughGEPConstantExpr wasn't handling pointers to
packed types correctly.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25470 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-19 23:53:23 +00:00
Reid Spencer
aa87e0523d For PR696:
Don't do floor->floorf conversion if floorf is not available. This checks
the compiler's host, not its target, which is incorrect for cross-compilers
Not sure that's important as we don't build many cross-compilers.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25456 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-19 08:36:56 +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
727552bb89 If not internalizing, don't mark llvm.global[cd]tors const, as a fix for a
hypothetical future boog.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25430 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-19 00:46:54 +00:00
Chris Lattner
ee9e14cb8a Don't internalize llvm.global[cd]tor unless there are uses of it. This
unbreaks front-ends that don't use __main (like the new CFE).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25429 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-19 00:40:39 +00:00
Chris Lattner
c4e8c9f318 Make sure that cloning a module clones its target triple and dependent
library list as well.  This should help bugpoint.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25424 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-18 21:32:45 +00:00
Robert Bocchino
956fd7254f Constant folding support for the insertelement operation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25407 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-17 20:07:07 +00:00
Robert Bocchino
8fcf01ead0 Lowerpacked and SCCP support for the insertelement operation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25406 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-17 20:06:55 +00:00
Chris Lattner
f91e97ae81 Clean up the FFS optimization code, and make it correctly create the appropriate
unsigned llvm.cttz.* intrinsic, fixing the 2005-05-11-Popcount-ffs-fls regression
last night.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25398 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-17 18:27:17 +00:00
Reid Spencer
0b118206bf For PR411:
This patch is an incremental step towards supporting a flat symbol table.
It de-overloads the intrinsic functions by providing type-specific intrinsics
and arranging for automatically upgrading from the old overloaded name to
the new non-overloaded name. Specifically:
  llvm.isunordered -> llvm.isunordered.f32, llvm.isunordered.f64
  llvm.sqrt -> llvm.sqrt.f32, llvm.sqrt.f64
  llvm.ctpop -> llvm.ctpop.i8, llvm.ctpop.i16, llvm.ctpop.i32, llvm.ctpop.i64
  llvm.ctlz -> llvm.ctlz.i8, llvm.ctlz.i16, llvm.ctlz.i32, llvm.ctlz.i64
  llvm.cttz -> llvm.cttz.i8, llvm.cttz.i16, llvm.cttz.i32, llvm.cttz.i64
New code should not use the overloaded intrinsic names. Warnings will be
emitted if they are used.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25366 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-16 21:12:35 +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
Chris Lattner
57a47d6a4b This pass has never worked correctly. Remove.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25349 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-16 01:06:00 +00:00
Chris Lattner
432a205769 Let the inliner update the callgraph to reflect the changes it makes, instead
of doing it ourselves.  This fixes Transforms/Inline/2006-01-14-CallGraphUpdate.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25321 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-14 20:09:18 +00:00
Chris Lattner
468fb1df7d Teach the inliner to update the CallGraph itself, and have it add edges to
llvm.stacksave/restore when it inserts calls to them.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25320 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-14 20:07:50 +00:00
Chris Lattner
516a74c01a FunctionPass's cannot do IPO things.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25315 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-14 19:30:35 +00:00
Nate Begeman
6fb3bd6a65 Add bswap intrinsics as documented in the Language Reference
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25309 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-14 01:25:24 +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
5522037136 it is ok to dce stacksave.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25295 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-13 21:31:54 +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
ccca3ca85f Permit inlining functions that contain dynamic allocations now that
InlineFunction handles this case safely.  This implements
Transforms/Inline/dynamic_alloca_test.ll.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25288 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-13 19:35:43 +00:00
Chris Lattner
bf229f488a If inlining a call to a function that contains dynamic allocas, wrap the
resultant code with llvm.stacksave/llvm.stackrestore intrinsics.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25286 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-13 19:34:14 +00:00
Chris Lattner
1fdf4a859f Use ClonedCodeInfo to avoid another walk over the inlined code, this this
time in common C cases.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25285 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-13 19:18:11 +00:00
Chris Lattner
727d1dd587 Use the ClonedCodeInfo object to avoid scans of the inlined code when
it doesn't contain any calls.  This is a fairly common case for C++ code,
so it will probably speed up the inliner marginally in these cases.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25284 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-13 19:15:15 +00:00
Chris Lattner
cd4d339ec1 Refactor a bunch of invoke handling stuff out into a new function
"HandleInlinedInvoke".  No functionality change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25283 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-13 19:05:59 +00:00
Chris Lattner
a4c29d2037 Allow the code cloning interfaces to capture some important info about the
code being cloned if the client wants.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25281 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-13 18:39:17 +00:00
Chris Lattner
21f20558d6 Fix a bug I noticed by inspection: if the first instruction in the inlined
function was not an alloca, we wouldn't check the entry block for any allocas,
leading to increased stack space in some cases.  In practice, allocas are almost
always at the top of the block, so this was never noticed.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25280 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-13 18:16:48 +00:00
Chris Lattner
8acb249725 Fix 80 column violations
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25279 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-13 18:06:56 +00:00
Chris Lattner
dd9e956605 Preserve and update ETForest. Patch by Daniel Berlin
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25203 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-11 05:11:13 +00:00
Chris Lattner
88cac3d2f7 Switch these to using ETForest instead of DominatorSet to compute itself.
Patch written by Daniel Berlin!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25202 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-11 05:10:20 +00:00
Chris Lattner
19ef3d5be2 Switch this to using ETForest instead of DominatorSet to compute itself.
Patch written by Daniel Berlin!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25201 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-11 05:09:40 +00:00
Robert Bocchino
b52ee7f5ff Added support for the extractelement operation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25181 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-10 19:05:34 +00:00
Robert Bocchino
56107e21a5 Added lower packed support for the extractelement operation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25180 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-10 19:05:05 +00:00
Chris Lattner
baec98d00b Teach loopsimplify to update et-forest. Patch contributed by Daniel Berlin!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25153 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-09 08:03:08 +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
Chris Lattner
4eb40df1a8 Pull inline methods out of the pass class definition to make it easier to
read the code.

Do not internalize debugger anchors.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25067 91177308-0d34-0410-b5e6-96231b3b80d8
2006-01-03 19:13:17 +00:00
Duraid Madina
b5186853f8 getting there...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25021 91177308-0d34-0410-b5e6-96231b3b80d8
2005-12-26 13:48:44 +00:00
Chris Lattner
6860f6a01c Fix Transforms/ScalarRepl/2005-12-14-UnionPromoteCrash.ll, a crash on undefined
behavior in 126.gcc on big-endian systems.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24708 91177308-0d34-0410-b5e6-96231b3b80d8
2005-12-14 17:23:59 +00:00
Reid Spencer
2f1890792c Improve ResolveFunctions to:
a) use better local variable names (OldMT -> OldFT) where "M" is used to
   mean "Function" (perhaps it was previously "Method"?)
b) print out the module identifier in a warning message so that it is
   possible to track down in which module the error occurred.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24698 91177308-0d34-0410-b5e6-96231b3b80d8
2005-12-13 19:56:51 +00:00
Chris Lattner
a188894d67 Implement a little hack for parity with GCC on crafty. This speeds up
186.crafty by about 16% (from 15.109s to 13.045s) on my system.

This turns allocas with unions/casts into scalars.  For example crafty has
something like this:

    union doub {
      unsigned short i[4];
      long long d;
    };
int f(long long a) {
  return ((union doub){.d=a}).i[1];
}

Instead of generating loads and stores to an alloca, we now promote the
whole thing to a scalar long value.

This implements: Transforms/ScalarRepl/AggregatePromote.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24667 91177308-0d34-0410-b5e6-96231b3b80d8
2005-12-12 07:19:13 +00:00
Chris Lattner
e08dc62b1a getRawValue zero extens for unsigned values, use getsextvalue so that we
know that small negative values fit into the immediate field of addressing
modes.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24608 91177308-0d34-0410-b5e6-96231b3b80d8
2005-12-05 18:23:57 +00:00
Chris Lattner
6b44ba2803 Wrap a long line, never internalize llvm.used.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24602 91177308-0d34-0410-b5e6-96231b3b80d8
2005-12-05 05:07:38 +00:00
Chris Lattner
8e75ee212f Fix SimplifyCFG/2005-12-03-IncorrectPHIFold.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24581 91177308-0d34-0410-b5e6-96231b3b80d8
2005-12-03 18:25:58 +00:00
Chris Lattner
2bd4cb597a Fix a bug where we didn't realize that vaarg reads memory. This fixes
Transforms/DeadStoreElimination/2005-11-30-vaarg.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24545 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-30 19:38:22 +00:00
Andrew Lenharth
8dc2d50988 a few more comments on the interfaces and functions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24500 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-28 18:10:59 +00:00
Andrew Lenharth
bb227c1b79 Added documented rsprofiler interface. Also remove new profiler passes, the
old ones have been updated to implement the interface.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24499 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-28 18:00:38 +00:00
Jeff Cohen
3523f6e7a4 Fix VC++ warning.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24496 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-28 06:45:57 +00:00
Andrew Lenharth
701f5ac73c Random sampling (aka Arnold and Ryder) profiling. This is still preliminary, but it works on spec on x86 and alpha. The idea is to allow profiling passes to remember what profiling they inserted, then a random sampling framework is inserted which consists of duplicated basic blocks (without profiling), such that at each backedge in the program and entry into every function, the framework chooses whether to use the instrumented code or the instrumentation free code. The goal of such a framework is to make it reasonably cheap to do random sampling of very expensive profiling products (such as load-value profiling).
The code is organized into 3 parts (2 passes)
1) a linked set of profiling passes, which implement an analysis group (linked, like alias analysis are).  These insert profiling into the program, and remember what they inserted, so that at a later time they can be queried about any instruction.

2) a pass that handles inserting the random sampling framework.  This also has options to control how random samples are choosen.  Currently implemented are Global counters, register allocated global counters, and read cycle counter (see? there was a reason for it).

The profiling passes are almost identical to the existing ones (block, function, and null profiling is supported right now), and they are valid passes without the sampling framework (hence the existing passes can be unified with the new ones, not done yet).

Some things are a bit ugly still, but that should be fixed up soon enough.

Other todo? making the counter values not "magic 2^16 -1" values, but dynamically choosable.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24493 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-28 00:58:09 +00:00
Andrew Lenharth
b0826529f8 since reg2mem requires it, might as well mention that it preserves it
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24491 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-25 16:04:54 +00:00
Andrew Lenharth
7c0c567058 Reg2Mem is something a pass may depend on, so allow that
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24488 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-22 22:14:23 +00:00
Andrew Lenharth
7045f6c56e turns out, demotion and invokes and critical edges don't mix
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24487 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-22 21:45:19 +00:00
Chris Lattner
1730078d5f Fix a crash building 176.gcc due to my recent patch, which only fixed
half the problem.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24414 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-18 18:30:47 +00:00
Chris Lattner
36ba5006df Implement a refinement to the mem2reg algorithm for cases where an alloca
has a single def.  In this case, look for uses that are dominated by the def
and attempt to rewrite them to directly use the stored value.

This speeds up mem2reg on these values and reduces the number of phi nodes
inserted.  This should address PR665.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24411 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-18 07:31:42 +00:00
Chris Lattner
fed40df846 This needs proper dominance
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24410 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-18 07:29:44 +00:00
Chris Lattner
ceda605fd7 This was checking the wrong GEP expression. Fixing this fixes a gccas crash
compiling mysql reported by Ted Kremenek.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24402 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-17 19:35:42 +00:00
Andrew Lenharth
fa25e48412 the pain isn't gone unless the phinodes are spilled too
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24288 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-10 19:39:09 +00:00
Andrew Lenharth
99b8e26b84 this works with backedges to the existing entry block alot better
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24270 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-10 17:35:34 +00:00
Andrew Lenharth
183119cdf6 The pass everyone has been waiting for!
Reg2Mem

for fun you can opt -reg2mem -mem2reg


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24267 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-10 01:58:38 +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
3b5f45042b Implement Transforms/TailCallElim/return-undef.ll, a trivial case
that has been sitting in my inbox since May 18. :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24194 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-05 08:21:11 +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
Andrew Lenharth
7bbff04f7f make this 64 bit clean, fixed test30 of /Regression/Transforms/InstCombine/add.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24158 91177308-0d34-0410-b5e6-96231b3b80d8
2005-11-02 18:35:40 +00:00
Chris Lattner
76ff2c7504 Limit the search depth of MaskedValueIsZero to 6 instructions, to avoid
bad cases.  This fixes Markus's second testcase in PR639, and should
seal it for good.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24123 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-31 18:35:52 +00:00
Chris Lattner
9fefdb5d66 This pass is now obsolete since all targets have moved to the SelectionDAG
infrastructure and the simple isels have been removed.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24090 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-29 05:33:46 +00:00
Chris Lattner
5af401d5f1 Remove dead #include
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24083 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-29 04:41:30 +00:00
Chris Lattner
1462aa78c7 Now that instcombine does this xform, remove it from the -raise pass
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24082 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-29 04:40:23 +00:00
Chris Lattner
cfd65100c4 Pull some code out into a function, give it the ability to see through +.
This allows us to turn code like malloc(4*x+4) -> malloc int, (x+1)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24081 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-29 04:36:15 +00:00
Chris Lattner
455fcc8d35 Remove a special case, allowing the general case to handle it. No functionality
change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24076 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-29 03:19:53 +00:00
Chris Lattner
325231c925 Fix a bit of backwards logic that broke exptree and smg2000
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24056 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-28 16:27:35 +00:00
Chris Lattner
108e902aeb Do not sink any instruction with side effects, including vaarg. This fixes
PR640


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24046 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-27 17:13:11 +00:00
Chris Lattner
cbbc6b74e3 Fix #include order
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24044 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-27 16:34:00 +00:00
John Criswell
a115643357 Move some constant folding code shared by Analysis and Transform passes
into the LLVMAnalysis library.
This allows LLVMTranform and LLVMTransformUtils to be archives and linked
with LLVMAnalysis.a, which provides any missing definitions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24036 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-27 15:54:34 +00:00
Chris Lattner
0e026de6ac Fix typo
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24033 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-27 06:26:26 +00:00
Chris Lattner
e679288a30 Teach instcombine to promote stuff like (cast (malloc sbyte, 8*X) to int*)
into: malloc int, (2*X)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24032 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-27 06:24:46 +00:00
Chris Lattner
8142b0a54b Promote cases like cast (malloc sbyte, 100) to int* into
(malloc [25 x int]) directly without having to convert to
(malloc [100 x sbyte]) first.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24031 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-27 06:12:00 +00:00
Chris Lattner
0ddac2a1c3 Minor change to this file to support obscure cases with constant array amounts
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24030 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-27 05:53:56 +00:00
John Criswell
e96a1a576b 1. Remove libraries no longer created from the list of libraries linked into the
SparcV9 JIT.
2. Make LLVMTransformUtils a relinked object file and always link it before
   LLVMAnalysis.a.  These two libraries have circular dependencies on each
   other which creates problem when building the SparcV9 JIT.  This change
   fixes the dependency on all platforms problems with a minimum of fuss.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24023 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-26 20:35:13 +00:00
Chris Lattner
e9f15e538a fold nested and's early to avoid inefficiencies in MaskedValueIsZero. This
fixes a very slow compile in PR639.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24011 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-26 17:18:16 +00:00
Alkis Evlogimenos
e9c6d36377 Stop using deprecated types
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23973 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-25 11:18:06 +00:00
Chris Lattner
39387a5c93 Handle allocations that, even after removing dead uses, still have more than
one use (but one is a cast).  This handles the very common case of:

 X = alloc [n x byte]
 Y = cast X to somethingbetter
 seteq X, null

In order to avoid infinite looping when there are multiple casts, we only
allow this if the xform is strictly increasing the alignment of the
allocation.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23961 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-24 06:35:18 +00:00
Chris Lattner
18e78bb09e Fix a bug where we would 'promote' an allocation from one type to another
where the second has less alignment required.  If we had explicit alignment
support in the IR, we could handle this case, but we can't until we do.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23960 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-24 06:26:18 +00:00
Chris Lattner
b53c2382a9 Before promoting a malloc type, remove dead uses. This makes instcombine
more effective at promoting these allocations, catching them earlier in the
compile process.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23959 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-24 06:22:12 +00:00
Chris Lattner
b3f8397a3d Pull some code out into a function, no functionality change
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23958 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-24 06:03:58 +00:00
Chris Lattner
d00a3cee80 Remove some beta code that no longer has an owner.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23944 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-24 02:32:41 +00:00
Chris Lattner
a66459095c Do not build the ProfilePaths directory anymore
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23943 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-24 02:31:49 +00:00
Chris Lattner
f36aeedaa3 DONT_BUILD_RELINKED is gone and implied by BUILD_ARCHIVE now
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23940 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-24 02:26:13 +00:00
Chris Lattner
ab0ed3592b Only build .a file versions of these libraries, instead of .a and .o versions.
This should speed up build times.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23933 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-24 01:59:48 +00:00
Chris Lattner
492d4a9d84 Make sure that anything using the ADCE pass pulls in the UnifyFunctionExitNodes
code


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23931 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-24 01:40:23 +00:00
Jeff Cohen
66c5fd6c53 When a function takes a variable number of pointer arguments, with a zero
pointer marking the end of the list, the zero *must* be cast to the pointer
type.  An un-cast zero is a 32-bit int, and at least on x86_64, gcc will
not extend the zero to 64 bits, thus allowing the upper 32 bits to be
random junk.

The new END_WITH_NULL macro may be used to annotate a such a function
so that GCC (version 4 or newer) will detect the use of un-casted zero
at compile time.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23888 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-23 04:37:20 +00:00
Chris Lattner
63ad7963e4 My previous patch was too conservative. Reject FP and void types, but do
allow pointer types.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23859 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-21 05:45:41 +00:00
Chris Lattner
1e9f3af561 Do NOT touch FP ops with LSR. This fixes a testcase Nate sent me from an
inner loop like this:

LBB_RateConvertMono8AltiVec_2:  ; no_exit
        lis r2, ha16(.CPI_RateConvertMono8AltiVec_0)
        lfs f3, lo16(.CPI_RateConvertMono8AltiVec_0)(r2)
        fmr f3, f3
        fadd f0, f2, f0
        fadd f3, f0, f3
        fcmpu cr0, f3, f1
        bge cr0, LBB_RateConvertMono8AltiVec_2  ; no_exit

to an inner loop like this:

LBB_RateConvertMono8AltiVec_1:  ; no_exit
        fsub f2, f2, f1
        fcmpu cr0, f2, f1
        fmr f0, f2
        bge cr0, LBB_RateConvertMono8AltiVec_1  ; no_exit

Doh! good catch!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23838 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-20 04:47:10 +00:00
Chris Lattner
a27ea769eb Add an option to this pass. If it is set, we are allowed to internalize
all but main.  If it's not set, we can still internalize, but only if an
explicit symbol list is provided.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23783 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-18 06:29:22 +00:00
Chris Lattner
8532cf6258 Make this work for FP constantexprs
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23773 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-17 20:18:38 +00:00
Chris Lattner
5e678e03b7 Oops, X+0.0 isn't foldable, but X+-0.0 is.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23772 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-17 17:56:38 +00:00
Chris Lattner
560a17d3bc relax this a bit, as we only support the default rounding mode
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23771 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-17 17:49:32 +00:00
Chris Lattner
d6155e96f7 Fix (hopefully the last) issue where LSR is nondeterminstic. When pulling
out CSE's of base expressions it could build a result whose order was
nondet.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23698 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-11 18:41:04 +00:00
Chris Lattner
7b445c521b Fix another problem where LSR was being nondeterminstic. Also remove elements
from the end of a vector instead of the beginning


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23697 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-11 18:30:57 +00:00
Chris Lattner
b4dd1b86fa Fix another lsr-is-nondeterministic case
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23695 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-11 18:17:57 +00:00
Chris Lattner
5fb0deb43a Make MaskedValueIsZero a bit more aggressive
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23677 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-09 22:08:50 +00:00
Chris Lattner
60de63d0b6 Fix funky xcode indentation
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23674 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-09 06:36:35 +00:00
Chris Lattner
a18af06360 Hrm, you didn't see this.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23673 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-09 06:24:02 +00:00
Chris Lattner
7305ae28df Fix a source of non-determinism in the backend: the order of processing
IV strides dependend on the pointer order of the strides in memory.
Non-determinism is bad.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23672 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-09 06:20:55 +00:00
Jeff Cohen
68d98e0bdc Remove useless variable.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23656 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-07 05:28:29 +00:00
Chris Lattner
ab55698349 Fix DemoteRegToStack on an invoke. This fixes PR634.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23618 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-04 00:44:01 +00:00
Chris Lattner
7a66e686fe Clean up the code a bit. Use isInstructionTriviallyDead to be more aggressive
and more correct than use_empty().  This fixes PR635 and
SimplifyCFG/2005-10-02-InvokeSimplify.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23616 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-03 23:43:43 +00:00
Chris Lattner
5e8ca66914 Make IVUseShouldUsePostIncValue more aggressive when the use is a PHI. In
particular, it should realize that phi's use their values in the pred block
not the phi block itself.  This change turns our em3d loop from this:

_test:
        cmpwi cr0, r4, 0
        bgt cr0, LBB_test_2     ; entry.no_exit_crit_edge
LBB_test_1:     ; entry.loopexit_crit_edge
        li r2, 0
        b LBB_test_6    ; loopexit
LBB_test_2:     ; entry.no_exit_crit_edge
        li r6, 0
LBB_test_3:     ; no_exit
        or r2, r6, r6
        lwz r6, 0(r3)
        cmpw cr0, r6, r5
        beq cr0, LBB_test_6     ; loopexit
LBB_test_4:     ; endif
        addi r3, r3, 4
        addi r6, r2, 1
        cmpw cr0, r6, r4
        blt cr0, LBB_test_3     ; no_exit
LBB_test_5:     ; endif.loopexit.loopexit_crit_edge
        addi r3, r2, 1
        blr
LBB_test_6:     ; loopexit
        or r3, r2, r2
        blr

into:

_test:
        cmpwi cr0, r4, 0
        bgt cr0, LBB_test_2     ; entry.no_exit_crit_edge
LBB_test_1:     ; entry.loopexit_crit_edge
        li r2, 0
        b LBB_test_5    ; loopexit
LBB_test_2:     ; entry.no_exit_crit_edge
        li r6, 0
LBB_test_3:     ; no_exit
        lwz r2, 0(r3)
        cmpw cr0, r2, r5
        or r2, r6, r6
        beq cr0, LBB_test_5     ; loopexit
LBB_test_4:     ; endif
        addi r3, r3, 4
        addi r6, r6, 1
        cmpw cr0, r6, r4
        or r2, r6, r6
        blt cr0, LBB_test_3     ; no_exit
LBB_test_5:     ; loopexit
        or r3, r2, r2
        blr


Unfortunately, this is actually worse code, because the register coallescer
is getting confused somehow.  If it were doing its job right, it could turn the
code into this:

_test:
        cmpwi cr0, r4, 0
        bgt cr0, LBB_test_2     ; entry.no_exit_crit_edge
LBB_test_1:     ; entry.loopexit_crit_edge
        li r6, 0
        b LBB_test_5    ; loopexit
LBB_test_2:     ; entry.no_exit_crit_edge
        li r6, 0
LBB_test_3:     ; no_exit
        lwz r2, 0(r3)
        cmpw cr0, r2, r5
        beq cr0, LBB_test_5     ; loopexit
LBB_test_4:     ; endif
        addi r3, r3, 4
        addi r6, r6, 1
        cmpw cr0, r6, r4
        blt cr0, LBB_test_3     ; no_exit
LBB_test_5:     ; loopexit
        or r3, r6, r6
        blr

... which I'll work on next. :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23604 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-03 02:50:05 +00:00
Chris Lattner
0ae33eb243 Refactor some code into a function
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23603 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-03 01:04:44 +00:00
Chris Lattner
1902ff4d82 This break is bogus and I have no idea why it was there. Basically it prevents
memoizing code when IV's are used by phinodes outside of loops.  In a simple
example, we were getting this code before (note that r6 and r7 are isomorphic
IV's):

        li r6, 0
        or r7, r6, r6
LBB_test_3:     ; no_exit
        lwz r2, 0(r3)
        cmpw cr0, r2, r5
        or r2, r7, r7
        beq cr0, LBB_test_5     ; loopexit
LBB_test_4:     ; endif
        addi r2, r7, 1
        addi r7, r7, 1
        addi r3, r3, 4
        addi r6, r6, 1
        cmpw cr0, r6, r4
        blt cr0, LBB_test_3     ; no_exit

Now we get:

        li r6, 0
LBB_test_3:     ; no_exit
        or r2, r6, r6
        lwz r6, 0(r3)
        cmpw cr0, r6, r5
        beq cr0, LBB_test_6     ; loopexit
LBB_test_4:     ; endif
        addi r3, r3, 4
        addi r6, r2, 1
        cmpw cr0, r6, r4
        blt cr0, LBB_test_3     ; no_exit

this was noticed in em3d.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23602 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-03 00:37:33 +00:00
Chris Lattner
37edbf0b21 when checking if we should move a split edge block outside of a loop,
check the presplit pred, not the post-split pred.  This was causing us
to make the wrong decision in some cases, leaving the critical edge block
in the loop.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23601 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-03 00:31:52 +00:00
Jeff Cohen
2aeaf4e839 Fix VC++ warnings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23579 91177308-0d34-0410-b5e6-96231b3b80d8
2005-10-01 03:57:14 +00:00
Chris Lattner
93e50ce04c Insert stores after phi nodes in the normal dest. This fixes
LowerInvoke/2005-08-03-InvokeWithPHI.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23525 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-29 17:44:20 +00:00
Chris Lattner
a48bc53cad Fold isascii into a simple comparison. This speeds up 197.parser by 7.4%,
bringing the LLC time down to the CBE time.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23521 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-29 06:17:27 +00:00
Chris Lattner
e9b6242780 remove a bunch of unneeded stuff, or self evident comments
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23519 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-29 06:16:11 +00:00
Chris Lattner
c330069e20 Implement a couple of memcmp folds from the todo list
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23517 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-29 04:54:20 +00:00
Chris Lattner
32643d8e05 Constant fold llvm.sqrt
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23487 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-28 01:34:32 +00:00
Chris Lattner
5b3c70263b add a note about a way to improve this code further, that I won't be getting
to right now.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23485 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-27 22:44:59 +00:00
Chris Lattner
9a5582f251 Fix a regression in my previous patch, fixing GlobalOpt/2005-09-27-Crash.ll
and PR632.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23484 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-27 22:28:11 +00:00
Chris Lattner
4531371960 Avoid spilling stack slots... to stack slots.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23478 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-27 21:33:12 +00:00
Chris Lattner
f4e6c3a69b Completely rewrite 'correct' eh support. This changes how setjmp insertion
is performed so it is only at most once per function that contains an invoke
instead of once per invoke in the function.  This patch has the following perks:

1. It fixes PR631, which complains about slowness.
2. If fixes PR240, which complains about non-volatile vars being live across
   setjmp/longjmps.
3. It improves (but does not fix) the jmpbuf alignment issue on itanium by not
   forcing the jmpbufs to always be 8-bytes off the alignment of the structure.
4. It speeds up 253.perlbmk from 338s to 13.70s (a 25x improvement!), making us
   now about 4% faster than GCC.

Further improvements are also possible.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23477 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-27 21:18:17 +00:00
Chris Lattner
fe15830f96 Make the pass name simpler
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23476 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-27 21:10:32 +00:00
Chris Lattner
6d7277b3b4 allow demotion to volatile values, add support for invoke
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23473 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-27 19:39:00 +00:00
Chris Lattner
a9ec8ab32b Add support for external calls that we know how to constant fold. This implements
ctor-list-opt.ll:CTOR8


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23465 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-27 05:02:43 +00:00
Chris Lattner
231308c545 Fix a bug where we would evaluate stores into linkonce objects which could be
potentially replaced at link-time.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23463 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-27 04:50:03 +00:00
Chris Lattner
cd27142cc8 Implement support for static constructors with calls in them. This is useful
because gccas runs globalopt before inlining.

This implements ctor-list-opt.ll:CTOR7


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23462 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-27 04:45:34 +00:00
Chris Lattner
8a7cc6e71c Refactor this code a bit, no functionality changes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23460 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-27 04:27:01 +00:00
Chris Lattner
ff0c1ef9eb Remove some dead code. ctor evaluation subsumes empty ctor elim
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23453 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 20:38:20 +00:00
Chris Lattner
a22fdb0a37 Add support for alloca, implementing ctor-list-opt.ll:CTOR6
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23452 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 17:07:09 +00:00
Chris Lattner
aae4a1cd3f Add a debug printout, fix a crash on kc++
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23450 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 07:34:35 +00:00
Chris Lattner
798b4d5bb3 Implement loads/stores through GEP's of globals. This implements
ctor-list-opt.ll:CTOR5.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23449 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 06:52:44 +00:00
Chris Lattner
0b142e3920 Replace TraverseGEPInitializer with ConstantFoldLoadThroughGEPConstantExpr
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23447 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 05:34:07 +00:00
Chris Lattner
ebe61201d1 Eliminate GetGEPGlobalInitializer in favor of the more powerful
ConstantFoldLoadThroughGEPConstantExpr function in the utils lib.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23446 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 05:28:52 +00:00
Chris Lattner
363f2a26d5 Factor the GetGEPGlobalInitializer out of this pass and into Transforms/Utils
as ConstantFoldLoadThroughGEPConstantExpr.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23445 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 05:28:06 +00:00
Chris Lattner
c5f52e6da1 Move the ConstantFoldLoadThroughGEPConstantExpr function out of the InstCombine
pass.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23444 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 05:27:10 +00:00
Chris Lattner
562a055ca7 add a comment
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23442 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 05:16:34 +00:00
Chris Lattner
04de1cfb2b Add support for getelementptr, load, and correctly reject volatile stores.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23441 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 05:15:37 +00:00
Chris Lattner
cdf98bed96 Add support for br/brcond/switch and phi
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23439 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 04:57:38 +00:00
Chris Lattner
79c1101947 Add a simple interpreter to this code, allowing us to statically evaluate
global ctors that are simple enough.  This implements ctor-list-opt.ll:CTOR2.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23437 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 04:44:35 +00:00
Chris Lattner
db973e60ce factor some code into a InstallGlobalCtors method, add comments. No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23435 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 02:31:18 +00:00
Chris Lattner
7d8e58f384 Make the global opt optimizer work on modules with a null terminator, by
accepting the null even with a non-65535 init prio


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23434 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 02:19:27 +00:00
Chris Lattner
b1ab458047 Factor this code out into a few methods.
Implement the start of global ctor optimization.  It is currently smart
enough to remove the global ctor for cases like this:

struct foo {
  foo() {}
} x;

... saving a bit of startup time for the program.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23433 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-26 01:43:45 +00:00
Chris Lattner
aebac50e77 Fix some logic I broke that caused a regression on
SimplifyLibCalls/2005-05-20-sprintf-crash.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23430 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-25 07:06:48 +00:00
Chris Lattner
5931c54e85 Move MaskedValueIsZero up.
Match a bunch of idioms for sign extensions, implementing InstCombine/signext.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23428 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-24 23:43:33 +00:00
Chris Lattner
5d735bf29b Simplify this code a bit by relying on recursive simplification. Support
sprintf("%s", P)'s that have uses.

s/hasNUses(0)/use_empty()/


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23425 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-24 22:17:06 +00:00
Chris Lattner
b60e0815df remove some debugging code
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23411 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-23 18:49:09 +00:00
Chris Lattner
263d1e469d Fold two consequtive branches that share a common destination between them.
This implements SimplifyCFG/branch-fold.ll, and is useful on ?:/min/max heavy
code


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23410 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-23 18:47:20 +00:00
Chris Lattner
055dc102e9 simplify some logic further
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23408 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-23 07:23:18 +00:00
Chris Lattner
f58c1a578e pull a bunch of logic out of SimplifyCFG into a helper fn
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23407 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-23 06:39:30 +00:00
Chris Lattner
e9487f0dc8 Start threading across blocks with code in them, so long as the code does
not define a value that is used outside of it's block.  This catches many
more simplifications, e.g. 854 in 176.gcc, 137 in vpr, etc.

This implements branch-phi-thread.ll:test3.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23397 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-20 01:48:40 +00:00
Chris Lattner
2e42e36698 Implement merging of blocks with the same condition if the block has multiple
predecessors.  This implements branch-phi-thread.ll::test1


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23395 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-20 00:43:16 +00:00
Chris Lattner
9c88d98162 Reject a case we don't handle yet
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23393 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-19 23:57:04 +00:00
Chris Lattner
7e1ff8d2d9 remove debugging code :-/
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23392 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-19 23:50:15 +00:00
Chris Lattner
eaba3a194c Implement SimplifyCFG/branch-phi-thread.ll, the most trivial case of threading
control across branches with determined outcomes.  More generality to follow.
This triggers a couple thousand times in specint.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23391 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-19 23:49:37 +00:00
Chris Lattner
7203e158da Refactor this code a bit and make it more general. This now compiles:
struct S { unsigned int i : 6, j : 11, k : 15; } b;
void plus2 (unsigned int x) { b.j += x; }

To:

_plus2:
        lis r2, ha16(L_b$non_lazy_ptr)
        lwz r2, lo16(L_b$non_lazy_ptr)(r2)
        lwz r4, 0(r2)
        slwi r3, r3, 6
        add r3, r4, r3
        rlwimi r3, r4, 0, 26, 14
        stw r3, 0(r2)
        blr


instead of:

_plus2:
        lis r2, ha16(L_b$non_lazy_ptr)
        lwz r2, lo16(L_b$non_lazy_ptr)(r2)
        lwz r4, 0(r2)
        rlwinm r5, r4, 26, 21, 31
        add r3, r5, r3
        rlwimi r4, r3, 6, 15, 25
        stw r4, 0(r2)
        blr

by eliminating an 'and'.

I'm pretty sure this is as small as we can go :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23386 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-18 07:22:02 +00:00
Chris Lattner
150f12af7f Compile
struct S { unsigned int i : 6, j : 11, k : 15; } b;
void plus2 (unsigned int x) {
  b.j += x;
}

to:

plus2:
        mov %EAX, DWORD PTR [b]
        mov %ECX, %EAX
        and %ECX, 131008
        mov %EDX, DWORD PTR [%ESP + 4]
        shl %EDX, 6
        add %EDX, %ECX
        and %EDX, 131008
        and %EAX, -131009
        or %EDX, %EAX
        mov DWORD PTR [b], %EDX
        ret

instead of:

plus2:
        mov %EAX, DWORD PTR [b]
        mov %ECX, %EAX
        shr %ECX, 6
        and %ECX, 2047
        add %ECX, DWORD PTR [%ESP + 4]
        shl %ECX, 6
        and %ECX, 131008
        and %EAX, -131009
        or %ECX, %EAX
        mov DWORD PTR [b], %ECX
        ret


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23385 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-18 06:30:59 +00:00
Chris Lattner
0b7c0bf249 Generalize this transform, using MaskedValueIsZero, allowing us to compile:
struct S { unsigned int i : 6, j : 11, k : 15; } b;
void plus3 (unsigned int x) { b.k += x; }

To:

plus3:
        mov %EAX, DWORD PTR [%ESP + 4]
        shl %EAX, 17
        add DWORD PTR [b], %EAX
        ret

instead of:

plus3:
        mov %EAX, DWORD PTR [%ESP + 4]
        shl %EAX, 17
        mov %ECX, DWORD PTR [b]
        add %EAX, %ECX
        and %EAX, -131072
        and %ECX, 131071
        or %ECX, %EAX
        mov DWORD PTR [b], %ECX
        ret


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23384 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-18 06:02:59 +00:00
Chris Lattner
5aa7666ebe fix typeo
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23383 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-18 05:25:20 +00:00
Chris Lattner
0d947ea943 Remove unintentionally committed code
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23382 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-18 05:12:51 +00:00
Chris Lattner
11021cb988 implement shift.ll:test25. This compiles:
struct S { unsigned int i : 6, j : 11, k : 15; } b;
void plus3 (unsigned int x) {
  b.k += x;
}

to:

_plus3:
        lis r2, ha16(L_b$non_lazy_ptr)
        lwz r2, lo16(L_b$non_lazy_ptr)(r2)
        lwz r3, 0(r2)
        rlwinm r4, r3, 0, 0, 14
        add r4, r4, r3
        rlwimi r4, r3, 0, 15, 31
        stw r4, 0(r2)
        blr

instead of:

_plus3:
        lis r2, ha16(L_b$non_lazy_ptr)
        lwz r2, lo16(L_b$non_lazy_ptr)(r2)
        lwz r4, 0(r2)
        srwi r5, r4, 17
        add r3, r5, r3
        slwi r3, r3, 17
        rlwimi r3, r4, 0, 15, 31
        stw r3, 0(r2)
        blr


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23381 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-18 05:12:10 +00:00
Chris Lattner
c8e7756791 Implement add.ll:test29. Codegening:
struct S { unsigned int i : 6, j : 11, k : 15; } b;
void plus1 (unsigned int x) {
  b.i += x;
}

as:
_plus1:
        lis r2, ha16(L_b$non_lazy_ptr)
        lwz r2, lo16(L_b$non_lazy_ptr)(r2)
        lwz r4, 0(r2)
        add r3, r4, r3
        rlwimi r3, r4, 0, 0, 25
        stw r3, 0(r2)
        blr

instead of:

_plus1:
        lis r2, ha16(L_b$non_lazy_ptr)
        lwz r2, lo16(L_b$non_lazy_ptr)(r2)
        lwz r4, 0(r2)
        rlwinm r5, r4, 0, 26, 31
        add r3, r5, r3
        rlwimi r3, r4, 0, 0, 25
        stw r3, 0(r2)
        blr


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23379 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-18 04:24:45 +00:00
Chris Lattner
3255bd101d remove debug output
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23377 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-18 03:50:25 +00:00
Chris Lattner
e9bed7d107 Implement or.ll:test21. This teaches instcombine to be able to turn this:
struct {
   unsigned int bit0:1;
   unsigned int ubyte:31;
} sdata;

void foo() {
  sdata.ubyte++;
}

into this:

foo:
        add DWORD PTR [sdata], 2
        ret

instead of this:

foo:
        mov %EAX, DWORD PTR [sdata]
        mov %ECX, %EAX
        add %ECX, 2
        and %ECX, -2
        and %EAX, 1
        or %EAX, %ECX
        mov DWORD PTR [sdata], %EAX
        ret


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23376 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-18 03:42:07 +00:00
Chris Lattner
6e2f843114 Fix the regression last night compiling povray
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23348 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-14 17:32:56 +00:00
Chris Lattner
7835cdde40 Add a simple xform to simplify array accesses with casts in the way.
This is useful for 178.galgel where resolution of dope vectors (by the
optimizer) causes the scales to become apparent.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23328 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-13 18:36:04 +00:00
Chris Lattner
396b2baf3c Fix an issue where LSR would miss rewriting a use of an IV expression by a PHI node that is not the original PHI.
This fixes up a dot-product loop in galgel, speeding it up from 18.47s to
16.13s.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23327 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-13 02:09:55 +00:00
Chris Lattner
eed48275a1 Add a helper function, allowing us to simplify some code a bit, changing
indentation, no functionality change


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23325 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-13 00:40:14 +00:00
Chris Lattner
408902b3c4 Implement a simple xform to turn code like this:
if () { store A -> P; } else { store B -> P; }

into a PHI node with one store, in the most trival case.  This implements
load.ll:test10.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23324 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-12 23:23:25 +00:00
Chris Lattner
9c1f0fd8de Another load-peephole optimization: do gcse when two loads are next to
each other.  This implements InstCombine/load.ll:test9


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23322 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-12 22:21:03 +00:00
Chris Lattner
62f254df04 Implement a trivial form of store->load forwarding where the store and the
load are exactly consequtive.  This is picked up by other passes, but this
triggers thousands of times in fortran programs that use static locals
(and is thus a compile-time speedup).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23320 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-12 22:00:15 +00:00
Chris Lattner
12b50410cd Fix a regression from last night, which caused this pass to create invalid
code for IV uses outside of loops that are not dominated by the latch block.
We should only convert these uses to use the post-inc value if they ARE
dominated by the latch block.

Also use a new LoopInfo method to simplify some code.

This fixes Transforms/LoopStrengthReduce/2005-09-12-UsesOutOutsideOfLoop.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23318 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-12 17:11:27 +00:00
Chris Lattner
c6bae65b49 _test:
li r2, 0
LBB_test_1:     ; no_exit.2
        li r5, 0
        stw r5, 0(r3)
        addi r2, r2, 1
        addi r3, r3, 4
        cmpwi cr0, r2, 701
        blt cr0, LBB_test_1     ; no_exit.2
LBB_test_2:     ; loopexit.2.loopexit
        addi r2, r2, 1
        stw r2, 0(r4)
        blr
[zion ~/llvm]$ cat > ~/xx
Uses of IV's outside of the loop should use hte post-incremented version
of the IV, not the preincremented version.  This helps many loops (e.g. in sixtrack)
which used to generate code like this (this is the code from the
dont-hoist-simple-loop-constants.ll testcase):

_test:
        li r2, 0                 **** IV starts at 0
LBB_test_1:     ; no_exit.2
        or r5, r2, r2            **** Copy for loop exit
        li r2, 0
        stw r2, 0(r3)
        addi r3, r3, 4
        addi r2, r5, 1
        addi r6, r5, 2           **** IV+2
        cmpwi cr0, r6, 701
        blt cr0, LBB_test_1     ; no_exit.2
LBB_test_2:     ; loopexit.2.loopexit
        addi r2, r5, 2       ****  IV+2
        stw r2, 0(r4)
        blr

And now generated code like this:

_test:
        li r2, 1               *** IV starts at 1
LBB_test_1:     ; no_exit.2
        li r5, 0
        stw r5, 0(r3)
        addi r2, r2, 1
        addi r3, r3, 4
        cmpwi cr0, r2, 701     *** IV.postinc + 0
        blt cr0, LBB_test_1
LBB_test_2:     ; loopexit.2.loopexit
        stw r2, 0(r4)          *** IV.postinc + 0
        blr


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23313 91177308-0d34-0410-b5e6-96231b3b80d8
2005-09-12 06:04:47 +00:00