Commit Graph

1011 Commits

Author SHA1 Message Date
Chris Lattner
50fad70279 Teach LSR to strength reduce IVs that have a loop-invariant but non-constant stride.
For code like this:

void foo(float *a, float *b, int n, int stride_a, int stride_b) {
  int i;
  for (i=0; i<n; i++)
      a[i*stride_a] = b[i*stride_b];
}

we now emit:

.LBB_foo2_2:    ; no_exit
        lfs f0, 0(r4)
        stfs f0, 0(r3)
        addi r7, r7, 1
        add r4, r2, r4
        add r3, r6, r3
        cmpw cr0, r7, r5
        blt .LBB_foo2_2 ; no_exit

instead of:

.LBB_foo_2:     ; no_exit
        mullw r8, r2, r7     ;; multiply!
        slwi r8, r8, 2
        lfsx f0, r4, r8
        mullw r8, r2, r6     ;; multiply!
        slwi r8, r8, 2
        stfsx f0, r3, r8
        addi r2, r2, 1
        cmpw cr0, r2, r5
        blt .LBB_foo_2  ; no_exit

loops with variable strides occur pretty often.  For example, in SPECFP2K
there are 317 variable strides in 177.mesa, 3 in 179.art, 14 in 188.ammp,
56 in 168.wupwise, 36 in 172.mgrid.

Now we can allow indvars to turn functions written like this:

void foo2(float *a, float *b, int n, int stride_a, int stride_b) {
  int i, ai = 0, bi = 0;
  for (i=0; i<n; i++)
    {
      a[ai] = b[bi];
      ai += stride_a;
      bi += stride_b;
    }
}

into code like the above for better analysis.  With this patch, they generate
identical code.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22740 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-10 00:45:21 +00:00
Chris Lattner
c41e34520a Fix Regression/Transforms/LoopStrengthReduce/phi_node_update_multiple_preds.ll
by being more careful about updating PHI nodes


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22739 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-10 00:35:32 +00:00
Chris Lattner
87265abffc Fix some 80 column violations.
Once we compute the evolution for a GEP, tell SE about it.  This allows users
of the GEP to know it, if the users are not direct.  This allows us to compile
this testcase:

void fbSolidFillmmx(int w, unsigned char *d) {
    while (w >= 64) {
        *(unsigned long long *) (d +  0) = 0;
        *(unsigned long long *) (d +  8) = 0;
        *(unsigned long long *) (d + 16) = 0;
        *(unsigned long long *) (d + 24) = 0;
        *(unsigned long long *) (d + 32) = 0;
        *(unsigned long long *) (d + 40) = 0;
        *(unsigned long long *) (d + 48) = 0;
        *(unsigned long long *) (d + 56) = 0;
        w -= 64;
        d += 64;
    }
}

into:

.LBB_fbSolidFillmmx_2:  ; no_exit
        li r2, 0
        stw r2, 0(r4)
        stw r2, 4(r4)
        stw r2, 8(r4)
        stw r2, 12(r4)
        stw r2, 16(r4)
        stw r2, 20(r4)
        stw r2, 24(r4)
        stw r2, 28(r4)
        stw r2, 32(r4)
        stw r2, 36(r4)
        stw r2, 40(r4)
        stw r2, 44(r4)
        stw r2, 48(r4)
        stw r2, 52(r4)
        stw r2, 56(r4)
        stw r2, 60(r4)
        addi r4, r4, 64
        addi r3, r3, -64
        cmpwi cr0, r3, 63
        bgt .LBB_fbSolidFillmmx_2       ; no_exit

instead of:

.LBB_fbSolidFillmmx_2:  ; no_exit
        li r11, 0
        stw r11, 0(r4)
        stw r11, 4(r4)
        stwx r11, r10, r4
        add r12, r10, r4
        stw r11, 4(r12)
        stwx r11, r9, r4
        add r12, r9, r4
        stw r11, 4(r12)
        stwx r11, r8, r4
        add r12, r8, r4
        stw r11, 4(r12)
        stwx r11, r7, r4
        add r12, r7, r4
        stw r11, 4(r12)
        stwx r11, r6, r4
        add r12, r6, r4
        stw r11, 4(r12)
        stwx r11, r5, r4
        add r12, r5, r4
        stw r11, 4(r12)
        stwx r11, r2, r4
        add r12, r2, r4
        stw r11, 4(r12)
        addi r4, r4, 64
        addi r3, r3, -64
        cmpwi cr0, r3, 63
        bgt .LBB_fbSolidFillmmx_2       ; no_exit


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22737 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-09 23:39:36 +00:00
Chris Lattner
b965ee5914 SCEVAddExpr::get() of an empty list is invalid.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22724 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-09 01:13:47 +00:00
Chris Lattner
1bbae0cbf2 Implement: LoopStrengthReduce/share_ivs.ll
Two changes:
  * Only insert one PHI node for each stride.  Other values are live in
    values.  This cannot introduce higher register pressure than the
    previous approach, and can take advantage of reg+reg addressing modes.
  * Factor common base values out of uses before moving values from the
    base to the immediate fields.  This improves codegen by starting the
    stride-specific PHI node out at a common place for each IV use.

As an example, we used to generate this for a loop in swim:

.LBB_main_no_exit_2E_6_2E_i_no_exit_2E_7_2E_i_2:        ; no_exit.7.i
        lfd f0, 0(r8)
        stfd f0, 0(r3)
        lfd f0, 0(r6)
        stfd f0, 0(r7)
        lfd f0, 0(r2)
        stfd f0, 0(r5)
        addi r9, r9, 1
        addi r2, r2, 8
        addi r5, r5, 8
        addi r6, r6, 8
        addi r7, r7, 8
        addi r8, r8, 8
        addi r3, r3, 8
        cmpw cr0, r9, r4
        bgt .LBB_main_no_exit_2E_6_2E_i_no_exit_2E_7_2E_i_1

now we emit:

.LBB_main_no_exit_2E_6_2E_i_no_exit_2E_7_2E_i_2:        ; no_exit.7.i
        lfdx f0, r8, r2
        stfdx f0, r9, r2
        lfdx f0, r5, r2
        stfdx f0, r7, r2
        lfdx f0, r3, r2
        stfdx f0, r6, r2
        addi r10, r10, 1
        addi r2, r2, 8
        cmpw cr0, r10, r4
        bgt .LBB_main_no_exit_2E_6_2E_i_no_exit_2E_7_2E_i_1

As another more dramatic example, we used to emit this:

.LBB_main_L_90_no_exit_2E_0_2E_i16_no_exit_2E_1_2E_i19_2:       ; no_exit.1.i19
        lfd f0, 8(r21)
        lfd f4, 8(r3)
        lfd f5, 8(r27)
        lfd f6, 8(r22)
        lfd f7, 8(r5)
        lfd f8, 8(r6)
        lfd f9, 8(r30)
        lfd f10, 8(r11)
        lfd f11, 8(r12)
        fsub f10, f10, f11
        fadd f5, f4, f5
        fmul f5, f5, f1
        fadd f6, f6, f7
        fadd f6, f6, f8
        fadd f6, f6, f9
        fmadd f0, f5, f6, f0
        fnmsub f0, f10, f2, f0
        stfd f0, 8(r4)
        lfd f0, 8(r25)
        lfd f5, 8(r26)
        lfd f6, 8(r23)
        lfd f9, 8(r28)
        lfd f10, 8(r10)
        lfd f12, 8(r9)
        lfd f13, 8(r29)
        fsub f11, f13, f11
        fadd f4, f4, f5
        fmul f4, f4, f1
        fadd f5, f6, f9
        fadd f5, f5, f10
        fadd f5, f5, f12
        fnmsub f0, f4, f5, f0
        fnmsub f0, f11, f3, f0
        stfd f0, 8(r24)
        lfd f0, 8(r8)
        fsub f4, f7, f8
        fsub f5, f12, f10
        fnmsub f0, f5, f2, f0
        fnmsub f0, f4, f3, f0
        stfd f0, 8(r2)
        addi r20, r20, 1
        addi r2, r2, 8
        addi r8, r8, 8
        addi r10, r10, 8
        addi r12, r12, 8
        addi r6, r6, 8
        addi r29, r29, 8
        addi r28, r28, 8
        addi r26, r26, 8
        addi r25, r25, 8
        addi r24, r24, 8
        addi r5, r5, 8
        addi r23, r23, 8
        addi r22, r22, 8
        addi r3, r3, 8
        addi r9, r9, 8
        addi r11, r11, 8
        addi r30, r30, 8
        addi r27, r27, 8
        addi r21, r21, 8
        addi r4, r4, 8
        cmpw cr0, r20, r7
        bgt .LBB_main_L_90_no_exit_2E_0_2E_i16_no_exit_2E_1_2E_i19_1

we now emit:

.LBB_main_L_90_no_exit_2E_0_2E_i16_no_exit_2E_1_2E_i19_2:       ; no_exit.1.i19
        lfdx f0, r21, r20
        lfdx f4, r3, r20
        lfdx f5, r27, r20
        lfdx f6, r22, r20
        lfdx f7, r5, r20
        lfdx f8, r6, r20
        lfdx f9, r30, r20
        lfdx f10, r11, r20
        lfdx f11, r12, r20
        fsub f10, f10, f11
        fadd f5, f4, f5
        fmul f5, f5, f1
        fadd f6, f6, f7
        fadd f6, f6, f8
        fadd f6, f6, f9
        fmadd f0, f5, f6, f0
        fnmsub f0, f10, f2, f0
        stfdx f0, r4, r20
        lfdx f0, r25, r20
        lfdx f5, r26, r20
        lfdx f6, r23, r20
        lfdx f9, r28, r20
        lfdx f10, r10, r20
        lfdx f12, r9, r20
        lfdx f13, r29, r20
        fsub f11, f13, f11
        fadd f4, f4, f5
        fmul f4, f4, f1
        fadd f5, f6, f9
        fadd f5, f5, f10
        fadd f5, f5, f12
        fnmsub f0, f4, f5, f0
        fnmsub f0, f11, f3, f0
        stfdx f0, r24, r20
        lfdx f0, r8, r20
        fsub f4, f7, f8
        fsub f5, f12, f10
        fnmsub f0, f5, f2, f0
        fnmsub f0, f4, f3, f0
        stfdx f0, r2, r20
        addi r19, r19, 1
        addi r20, r20, 8
        cmpw cr0, r19, r7
        bgt .LBB_main_L_90_no_exit_2E_0_2E_i16_no_exit_2E_1_2E_i19_1


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22722 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-09 00:18:09 +00:00
Chris Lattner
a553b0cc01 Suck the base value out of the UsersToProcess vector into the BasedUser
class to simplify the code.  Fuse two loops.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22721 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-08 22:56:21 +00:00
Chris Lattner
44b807e3c0 Split MoveLoopVariantsToImediateField out from MoveImmediateValues. The
first is a correctness thing, and the later is an optzn thing.  This also
is needed to support a future change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22720 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-08 22:32:34 +00:00
Chris Lattner
4bc5f8071a Use the new 'moveBefore' method to simplify some code. Really, which is
easier to understand?  :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22706 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-08 19:11:57 +00:00
Chris Lattner
3821e478a5 Not all constants are legal immediates in load/store instructions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22704 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-08 06:25:50 +00:00
Chris Lattner
5272f3c669 Implement LoopStrengthReduce/share_code_in_preheader.ll by having one
rewriter for all code inserted into the preheader, which is never flushed.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22702 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-08 05:47:49 +00:00
Chris Lattner
010de25f42 Implement a simple optimization for the termination condition of the loop.
The termination condition actually wants to use the post-incremented value
of the loop, not a new indvar with an unusual base.

On PPC, for example, this allows us to compile
LoopStrengthReduce/exit_compare_live_range.ll to:

_foo:
        li r2, 0
.LBB_foo_1:     ; no_exit
        li r5, 0
        stw r5, 0(r3)
        addi r2, r2, 1
        cmpw cr0, r2, r4
        bne .LBB_foo_1  ; no_exit
        blr

instead of:

_foo:
        li r2, 1                ;; IV starts at 1, not 0
.LBB_foo_1:     ; no_exit
        li r5, 0
        stw r5, 0(r3)
        addi r5, r2, 1
        cmpw cr0, r2, r4
        or r2, r5, r5           ;; Reg-reg copy, extra live range
        bne .LBB_foo_1  ; no_exit
        blr

This implements LoopStrengthReduce/exit_compare_live_range.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22699 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-08 05:28:22 +00:00
Chris Lattner
2b83af2d0f Add some simple folds that occur in bitfield cases. Fix a minor bug in
isHighOnes, where it would consider 0 to have high ones.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22693 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-07 07:03:10 +00:00
Chris Lattner
4c0e4cdc40 Fix typoCVS: ----------------------------------------------------------------------
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22692 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-07 07:00:52 +00:00
Chris Lattner
ce869ee05b * Use the new PHINode::hasConstantValue method to simplify some code
* Teach this code to move allocas out of the loop when tail call eliminating
  a call marked 'tail'.  This implements TailCallElim/move_alloca_for_tail_call.ll
* Do not perform this transformation if a call is marked 'tail' and if there
  are allocas that we cannot move out of the loop in #2.  Doing so would increase
  the stack usage of the function.  This implements fixes
  PR615 and TailCallElim/dont-tce-tail-marked-call.ll.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22690 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-07 04:27:41 +00:00
Chris Lattner
9a59fbb896 Make sure to clean CastedPointers after casts are potentially deleted.
This fixes LSR crashes on 301.apsi, 191.fma3d, and 189.lucas


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22673 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-05 01:30:11 +00:00
Chris Lattner
68ee736694 now that hasConstantValue defaults to only returning values that dominate
the PHI node, this ugly code can vanish.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22672 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-05 01:04:30 +00:00
Nate Begeman
a83ba0f5c9 Fix a fixme in CondPropagate.cpp by moving a PhiNode optimization into
BasicBlock's removePredecessor routine.  This requires shuffling around
the definition and implementation of hasContantValue from Utils.h,cpp into
Instructions.h,cpp


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22664 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-04 23:24:19 +00:00
Chris Lattner
26d91f1646 Modify how immediates are removed from base expressions to deal with the fact
that the symbolic evaluator is not always able to use subtraction to remove
expressions.  This makes the code faster, and fixes the last crash on 178.galgel.
Finally, add a statistic to see how many phi nodes are inserted.

On 178.galgel, we get the follow stats:

2562 loop-reduce  - Number of PHIs inserted
3927 loop-reduce  - Number of GEPs strength reduced


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22662 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-04 22:34:05 +00:00
Chris Lattner
2114b273ef * Refactor some code into a new BasedUser::RewriteInstructionToUseNewBase
method.
* Fix a crash on 178.galgel, where we would insert expressions before PHI
  nodes instead of into the PHI node predecessor blocks.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22657 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-04 20:03:32 +00:00
Chris Lattner
7a2ca56ef3 Fix a case that caused this to crash on 178.galgel
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22653 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-04 19:26:19 +00:00
Chris Lattner
7db543f887 Teach LSR about loop-variant expressions, such as loops like this:
for (i = 0; i < N; ++i)
    A[i][foo()] = 0;

here we still want to strength reduce the A[i] part, even though foo() is
l-v.

This also simplifies some of the 'CanReduce' logic.

This implements Transforms/LoopStrengthReduce/ops_after_indvar.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22652 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-04 19:08:16 +00:00
Nate Begeman
f08341457f Remove some more dead code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22650 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-04 18:13:56 +00:00
Chris Lattner
3416e5f645 Refactor this code substantially with the following improvements:
1. We only analyze instructions once, guaranteed
  2. AnalyzeGetElementPtrUsers has been ripped apart and replaced with
     something much simpler.

The next step is to handle expressions that are not all indvar+loop-invariant
values (e.g. handling indvar+loopvariant).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22649 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-04 17:40:30 +00:00
Chris Lattner
49f72e68cf refactor some code
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22643 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-04 01:19:13 +00:00
Chris Lattner
a4479ad25f invert to if's to make the logic simpler
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22641 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-04 00:40:47 +00:00
Chris Lattner
f9186596f0 When processing outer loops and we find uses of an IV in inner loops, make
sure to handle the use, just don't recurse into it.

This permits us to generate this code for a simple nested loop case:

.LBB_foo_0:     ; entry
        stwu r1, -48(r1)
        stw r29, 44(r1)
        stw r30, 40(r1)
        mflr r11
        stw r11, 56(r1)
        lis r2, ha16(L_A$non_lazy_ptr)
        lwz r30, lo16(L_A$non_lazy_ptr)(r2)
        li r29, 1
.LBB_foo_1:     ; no_exit.0
        bl L_bar$stub
        li r2, 1
        or r3, r30, r30
.LBB_foo_2:     ; no_exit.1
        lfd f0, 8(r3)
        stfd f0, 0(r3)
        addi r4, r2, 1
        addi r3, r3, 8
        cmpwi cr0, r2, 100
        or r2, r4, r4
        bne .LBB_foo_2  ; no_exit.1
.LBB_foo_3:     ; loopexit.1
        addi r30, r30, 800
        addi r2, r29, 1
        cmpwi cr0, r29, 100
        or r29, r2, r2
        bne .LBB_foo_1  ; no_exit.0
.LBB_foo_4:     ; return
        lwz r11, 56(r1)
        mtlr r11
        lwz r30, 40(r1)
        lwz r29, 44(r1)
        lwz r1, 0(r1)
        blr

instead of this:

_foo:
.LBB_foo_0:     ; entry
        stwu r1, -48(r1)
        stw r28, 44(r1)                   ;; uses an extra register.
        stw r29, 40(r1)
        stw r30, 36(r1)
        mflr r11
        stw r11, 56(r1)
        li r30, 1
        li r29, 0
        or r28, r29, r29
.LBB_foo_1:     ; no_exit.0
        bl L_bar$stub
        mulli r2, r28, 800           ;; unstrength-reduced multiply
        lis r3, ha16(L_A$non_lazy_ptr)   ;; loop invariant address computation
        lwz r3, lo16(L_A$non_lazy_ptr)(r3)
        add r2, r2, r3
        mulli r4, r29, 800           ;; unstrength-reduced multiply
        addi r3, r3, 8
        add r3, r4, r3
        li r4, 1
.LBB_foo_2:     ; no_exit.1
        lfd f0, 0(r3)
        stfd f0, 0(r2)
        addi r5, r4, 1
        addi r2, r2, 8                 ;; multiple stride 8 IV's
        addi r3, r3, 8
        cmpwi cr0, r4, 100
        or r4, r5, r5
        bne .LBB_foo_2  ; no_exit.1
.LBB_foo_3:     ; loopexit.1
        addi r28, r28, 1               ;;; Many IV's with stride 1
        addi r29, r29, 1
        addi r2, r30, 1
        cmpwi cr0, r30, 100
        or r30, r2, r2
        bne .LBB_foo_1  ; no_exit.0
.LBB_foo_4:     ; return
        lwz r11, 56(r1)
        mtlr r11
        lwz r30, 36(r1)
        lwz r29, 40(r1)
        lwz r28, 44(r1)
        lwz r1, 0(r1)
        blr


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22640 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-04 00:14:11 +00:00
Chris Lattner
7a65839f41 Teach loop-reduce to see into nested loops, to pull out immediate values
pushed down by SCEV.

In a nested loop case, this allows us to emit this:

        lis r3, ha16(L_A$non_lazy_ptr)
        lwz r3, lo16(L_A$non_lazy_ptr)(r3)
        add r2, r2, r3
        li r3, 1
.LBB_foo_2:     ; no_exit.1
        lfd f0, 8(r2)        ;; Uses offset of 8 instead of 0
        stfd f0, 0(r2)
        addi r4, r3, 1
        addi r2, r2, 8
        cmpwi cr0, r3, 100
        or r3, r4, r4
        bne .LBB_foo_2  ; no_exit.1

instead of this:

        lis r3, ha16(L_A$non_lazy_ptr)
        lwz r3, lo16(L_A$non_lazy_ptr)(r3)
        add r2, r2, r3
        addi r3, r3, 8
        li r4, 1
.LBB_foo_2:     ; no_exit.1
        lfd f0, 0(r3)
        stfd f0, 0(r2)
        addi r5, r4, 1
        addi r2, r2, 8
        addi r3, r3, 8
        cmpwi cr0, r4, 100
        or r4, r5, r5
        bne .LBB_foo_2  ; no_exit.1


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22639 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-03 23:44:42 +00:00
Chris Lattner
be3e5212e2 improve debug output
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22638 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-03 23:30:08 +00:00
Chris Lattner
2351abaeab Move from Stage 0 to Stage 1.
Only emit one PHI node for IV uses with identical bases and strides (after
moving foldable immediates to the load/store instruction).

This implements LoopStrengthReduce/dont_insert_redundant_ops.ll, allowing
us to generate this PPC code for test1:

        or r30, r3, r3
.LBB_test1_1:   ; Loop
        li r2, 0
        stw r2, 0(r30)
        stw r2, 4(r30)
        bl L_pred$stub
        addi r30, r30, 8
        cmplwi cr0, r3, 0
        bne .LBB_test1_1        ; Loop

instead of this code:

        or r30, r3, r3
        or r29, r3, r3
.LBB_test1_1:   ; Loop
        li r2, 0
        stw r2, 0(r29)
        stw r2, 4(r30)
        bl L_pred$stub
        addi r30, r30, 8        ;; Two iv's with step of 8
        addi r29, r29, 8
        cmplwi cr0, r3, 0
        bne .LBB_test1_1        ; Loop


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22635 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-03 22:51:21 +00:00
Chris Lattner
ec3fb63af2 Rename IVUse to IVUsersOfOneStride, use a struct instead of a pair to
unify some parallel vectors and get field names more descriptive than
"first" and "second".  This isn't lisp afterall :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22633 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-03 22:21:05 +00:00
Chris Lattner
52d83e66ee Fix a nasty dangling pointer issue. The ScalarEvolution pass would keep a
map from instruction* to SCEVHandles.  When we delete instructions, we have
to tell it about it.  We would run into nasty cases where new instructions
were reallocated at old instruction addresses and get the old map values.
Bad bad bad :(


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22632 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-03 21:36:09 +00:00
Chris Lattner
bcd7db59d0 Update to use the new MathExtras.h support for log2 computation.
Patch contributed by Jim Laskey!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22592 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-02 19:16:58 +00:00
Chris Lattner
8105c76da4 Like the comment says, do not insert cast instructions before phi nodes
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22586 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-02 03:31:14 +00:00
Chris Lattner
7e608bbb5d add a comment, make a check more lenient
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22581 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-02 02:52:02 +00:00
Chris Lattner
e9100c69cb Simplify for loop, clear a per-loop map after processing each loop
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22580 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-02 02:44:31 +00:00
Chris Lattner
07cd0ff298 Add a comment
Make LSR ignore GEP's that have loop variant base values, as we currently
cannot codegen them


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22576 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-02 01:32:29 +00:00
Chris Lattner
1060e09fb2 Fix an iterator invalidation problem
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22575 91177308-0d34-0410-b5e6-96231b3b80d8
2005-08-02 00:41:11 +00:00
Jeff Cohen
d29b6aa608 Keep tabs and trailing spaces out.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22565 91177308-0d34-0410-b5e6-96231b3b80d8
2005-07-30 18:33:25 +00:00
Jeff Cohen
cfb1d4235f Fix VC++ build problems.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22564 91177308-0d34-0410-b5e6-96231b3b80d8
2005-07-30 18:22:27 +00:00
Nate Begeman
f84d5ab5df Ack, typo
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22560 91177308-0d34-0410-b5e6-96231b3b80d8
2005-07-30 00:21:31 +00:00
Nate Begeman
1699748567 Commit a new LoopStrengthReduce pass that can use scalar evolutions and
target data to decide which loop induction variables to strength reduce
and how to do so.  This work is mostly by Chris Lattner, with tweaks by
me to get it working on some of MultiSource.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22558 91177308-0d34-0410-b5e6-96231b3b80d8
2005-07-30 00:15:07 +00:00
Nate Begeman
36f891bdf6 Break SCEVExpander out of IndVarSimplify into its own .h/.cpp file so that
other passes may use it.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22557 91177308-0d34-0410-b5e6-96231b3b80d8
2005-07-30 00:12:19 +00:00
Jeff Cohen
00b16889ab Eliminate all remaining tabs and trailing spaces.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22523 91177308-0d34-0410-b5e6-96231b3b80d8
2005-07-27 06:12:32 +00:00
Chris Lattner
f9944f109c Do not let MaskedValueIsZero consider undef to be zero, for reasons
explained in the comment.

This fixes UnitTests/2003-09-18-BitFieldTest on darwin


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22483 91177308-0d34-0410-b5e6-96231b3b80d8
2005-07-20 18:49:28 +00:00
Chris Lattner
7911f03626 When transforming &A[i] < &A[j] -> i < j, make sure to perform the comparison
as a signed compare.  This patch may fix PR597, but is correct in any case.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22465 91177308-0d34-0410-b5e6-96231b3b80d8
2005-07-18 23:07:33 +00:00
Chris Lattner
b3d59701c8 Fix a problem that instcombine would hit when dealing with unreachable code.
Because the instcombine has to scan the entire function when it starts up
to begin with, we might as well do it in DFO so we can nuke unreachable code.

This fixes: Transforms/InstCombine/2005-07-07-DeadPHILoop.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22348 91177308-0d34-0410-b5e6-96231b3b80d8
2005-07-07 20:40:38 +00:00
Andrew Lenharth
38b5807bd9 prevent va_arg from being hoisted from a loop
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22265 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-20 13:36:33 +00:00
Andrew Lenharth
558bc88a00 core changes for varargs
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22254 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-18 18:34:52 +00:00
Reid Spencer
4b828e6384 Clean up some uninitialized variables and missing return statements that
GCC 4.0.0 compiler (sometimes incorrectly) warns about under release build.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22249 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-18 17:37:34 +00:00
Chris Lattner
e88b7533be This is not true: (X != 13 | X < 15) -> X < 15
It is actually always true.  This fixes PR586 and
Transforms/InstCombine/2005-06-16-SetCCOrSetCCMiscompile.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22236 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-17 03:59:17 +00:00
Chris Lattner
5662503afd Don't crash when dealing with INTMIN. This fixes PR585 and
Transforms/InstCombine/2005-06-16-RangeCrash.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22234 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-17 02:05:55 +00:00
Chris Lattner
d7e31cfaae avoid constructing out of range shift amounts.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22230 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-17 01:29:28 +00:00
Chris Lattner
f9c775c22e Fix PR583 and testcase Transforms/InstCombine/2005-06-15-DivSelectCrash.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22227 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-16 04:55:52 +00:00
Chris Lattner
8d7089e1d5 Fix PR571, removing code that does just the WRONG thing :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22225 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-16 03:00:08 +00:00
Chris Lattner
aa457ac2e7 Fix a bug in my previous patch. Do not get the shift amount type (which
is always ubyte, get the type being shifted).  This unbreaks espresso


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22224 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-16 01:52:07 +00:00
Chris Lattner
4bd09d70cc Fix PR582. The rewriter can move casts around, which invalidated the
BB iterator.  This fixes Transforms/IndVarsSimplify/2005-06-15-InstMoveCrash.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22221 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-15 21:29:31 +00:00
Chris Lattner
e17a128a55 Fix PR577 and testcase InstCombine/2005-06-15-ShiftSetCCCrash.ll.
Do not perform undefined out of range shifts.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22217 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-15 20:53:31 +00:00
Reid Spencer
877c3e2b81 Put the hack back in that removes features, causes regressions to fail, but
allows test programs to succeed. Actual fix for this is forthcoming.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22213 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-15 18:25:30 +00:00
Reid Spencer
16b5644f04 Unbreak several InstCombine regression checks introduced by a hack to
fix the bzip2 test. A better hack is needed.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22209 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-13 06:41:26 +00:00
Andrew Lenharth
837be1ec35 hack to fix bzip2 (bug 571)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22192 91177308-0d34-0410-b5e6-96231b3b80d8
2005-06-04 12:43:56 +00:00
Chris Lattner
e43702695d preserve calling conventions when hacking on code
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22024 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-14 12:25:32 +00:00
Chris Lattner
08b22ecc88 calling a function with the wrong CC is undefined, turn it into an unreachable
instruction.  This is useful for catching optimizers that don't preserve
calling conventions


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21928 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-13 07:09:09 +00:00
Chris Lattner
641f02f10f Fix Reassociate/shifttest.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21839 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-10 03:39:25 +00:00
Chris Lattner
7f78f218fd If a function contains no allocas, all of the calls in it are trivially
suitable for tail calls.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21836 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-09 23:51:13 +00:00
Chris Lattner
6e4c6495eb implement and.ll:test33
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21809 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-09 04:58:36 +00:00
Chris Lattner
44b8c7d5d3 Implement Reassociate/mul-neg-add.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21788 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-08 21:41:35 +00:00
Chris Lattner
6f156856ca Bail out earlier
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21786 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-08 21:33:47 +00:00
Chris Lattner
f33151aff0 Teach reassociate that 0-X === X*-1
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21785 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-08 21:28:52 +00:00
Chris Lattner
9c72319938 Fix PR557 and basictest[34].ll.
This makes reassociate realize that loads should be treated as unmovable, and
gives distinct ranks to distinct values defined in the same basic block, allowing
reassociate to do its thing.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21783 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-08 20:57:04 +00:00
Chris Lattner
c9fd097a01 Add debugging information
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21781 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-08 20:09:57 +00:00
Chris Lattner
989f6229bc eliminate gotos
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21780 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-08 19:48:43 +00:00
Chris Lattner
109d34d6ff Improve reassociation handling of inverses, implementing inverses.ll.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21778 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-08 18:59:37 +00:00
Chris Lattner
928128281f clean up and modernize this pass.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21776 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-08 18:45:26 +00:00
Chris Lattner
120347e8d1 Strength reduce SAR into SHR if there is no way sign bits could be shifted
in.  This tends to get cases like this:

  X = cast ubyte to int
  Y = shr int X, ...

Tested by: shift.ll:test24


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21775 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-08 17:34:56 +00:00
Chris Lattner
4690010006 Refactor some code
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21772 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-08 00:19:31 +00:00
Chris Lattner
cc8a2b98f2 Handle some simple cases where we can see that values get annihilated.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21771 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-08 00:08:33 +00:00
Chris Lattner
f4d4c87985 Fix a miscompilation of crafty by clobbering the "A" variable.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21770 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-07 23:49:08 +00:00
Chris Lattner
c0649ac931 Rewrite the guts of the reassociate pass to be more efficient and logical. Instead
of trying to do local reassociation tweaks at each level, only process an expression
tree once (at its root).  This does not improve the reassociation pass in any real way.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21768 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-07 21:59:39 +00:00
Chris Lattner
0975ed5f4e Convert shifts to muls to assist reassociation. This implements
Reassociate/shifttest.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21761 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-07 04:24:13 +00:00
Chris Lattner
08b43921e1 Simplify the code and rearrange it. No major functionality changes here.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21759 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-07 04:08:02 +00:00
Chris Lattner
a9e9211bbb Preserve tail marker
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21737 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-06 06:48:21 +00:00
Chris Lattner
eabfa4787a Teach instcombine propagate zeroness through shl instructions, implementing
and.ll:test31


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21717 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-06 04:53:20 +00:00
Chris Lattner
d7115b01a0 Implement shift.ll:test23. If we are shifting right then immediately truncating
the result, turn signed shift rights into unsigned shift rights if possible.

This leads to later simplification and happens *often* in 176.gcc.  For example,
this testcase:

struct xxx { unsigned int code : 8; };
enum codes { A, B, C, D, E, F };
int foo(struct xxx *P) {
  if ((enum codes)P->code == A)
     bar();
}

used to be compiled to:

int %foo(%struct.xxx* %P) {
        %tmp.1 = getelementptr %struct.xxx* %P, int 0, uint 0           ; <uint*> [#uses=1]
        %tmp.2 = load uint* %tmp.1              ; <uint> [#uses=1]
        %tmp.3 = cast uint %tmp.2 to int                ; <int> [#uses=1]
        %tmp.4 = shl int %tmp.3, ubyte 24               ; <int> [#uses=1]
        %tmp.5 = shr int %tmp.4, ubyte 24               ; <int> [#uses=1]
        %tmp.6 = cast int %tmp.5 to sbyte               ; <sbyte> [#uses=1]
        %tmp.8 = seteq sbyte %tmp.6, 0          ; <bool> [#uses=1]
        br bool %tmp.8, label %then, label %UnifiedReturnBlock

Now it is compiled to:

        %tmp.1 = getelementptr %struct.xxx* %P, int 0, uint 0           ; <uint*> [#uses=1]
        %tmp.2 = load uint* %tmp.1              ; <uint> [#uses=1]
        %tmp.2 = cast uint %tmp.2 to sbyte              ; <sbyte> [#uses=1]
        %tmp.8 = seteq sbyte %tmp.2, 0          ; <bool> [#uses=1]
        br bool %tmp.8, label %then, label %UnifiedReturnBlock

which is the difference between this:

foo:
        subl $4, %esp
        movl 8(%esp), %eax
        movl (%eax), %eax
        shll $24, %eax
        sarl $24, %eax
        testb %al, %al
        jne .LBBfoo_2

and this:

foo:
        subl $4, %esp
        movl 8(%esp), %eax
        movl (%eax), %eax
        testb %al, %al
        jne .LBBfoo_2

This occurs 3243 times total in the External tests, 215x in povray,
6x in each f2c'd program, 1451x in 176.gcc, 7x in crafty, 20x in perl,
25x in gap, 3x in m88ksim, 25x in ijpeg.

Maybe this will cause a little jump on gcc tommorow :)


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21715 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-06 04:18:52 +00:00
Chris Lattner
7aed7ac5e1 Implement xor.ll:test22
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21713 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-06 02:07:39 +00:00
Chris Lattner
d152380ba8 implement and.ll:test30 and set.ll:test21
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21712 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-06 01:53:19 +00:00
Chris Lattner
828eeddb38 implement or.ll:test20
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21709 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-06 00:58:50 +00:00
Chris Lattner
693787a5ec Instcombine: cast (X != 0) to int, cast (X == 1) to int -> X iff X has only the low bit set.
This implements set.ll:test20.

This triggers 2x on povray, 9x on mesa, 11x on gcc, 2x on crafty, 1x on eon,
6x on perlbmk and 11x on m88ksim.

It allows us to compile these two functions into the same code:

struct s { unsigned int bit : 1; };
unsigned foo(struct s *p) {
  if (p->bit)
    return 1;
  else
    return 0;
}
unsigned bar(struct s *p) { return p->bit; }


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21690 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-04 19:10:26 +00:00
Chris Lattner
9fb25db11e Implement getelementptr.ll:test11
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21647 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-01 04:42:15 +00:00
Chris Lattner
37366c1ba8 Check for volatile loads only once.
Implement load.ll:test7


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21645 91177308-0d34-0410-b5e6-96231b3b80d8
2005-05-01 04:24:53 +00:00
Chris Lattner
93b94a6ccf Fix the compile failures from last night.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21565 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-26 14:40:41 +00:00
Chris Lattner
a70b66d49e implement getelementptr.ll:test10
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21541 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-25 20:17:30 +00:00
Chris Lattner
f52d681657 Eliminate cases where we could << by 64, which is undefined in C.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21500 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-24 17:46:05 +00:00
Chris Lattner
a1df33c0ee Implement xor.ll:test21: select (not C), A, B -> select C, B, A
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21495 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-24 07:30:14 +00:00
Chris Lattner
484d3cf0e3 Use getPrimitiveSizeInBits() instead of getPrimitiveSize()*8
Completely rework the 'setcc (cast x to larger), y' code.  This code has
the advantage of implementing setcc.ll:test19 (being more general than
the previous code) and being correct in all cases.

This allows us to unxfail 2004-11-27-SetCCForCastLargerAndConstant.ll,
and close PR454.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21491 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-24 06:59:08 +00:00
Jeff Cohen
9d80930e95 Eliminate tabs and trailing spaces
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21480 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-23 21:38:35 +00:00
Chris Lattner
6970b661cb Generalize the setcc -> PHI and Select folding optimizations to work with
any constant RHS, not just a constant integer RHS.  This implements
select.ll:test17


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21470 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-23 15:31:55 +00:00
Misha Brukman
fd93908ae8 Remove trailing whitespace
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21427 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-21 23:48:37 +00:00
Chris Lattner
956db27a63 Instcombine this:
%shortcirc_val = select bool %tmp.1, bool true, bool %tmp.4             ; <bool> [#uses=1]
        %tmp.6 = cast bool %shortcirc_val to int                ; <int> [#uses=1]

into this:

        %shortcirc_val = or bool %tmp.1, %tmp.4         ; <bool> [#uses=1]
        %tmp.6 = cast bool %shortcirc_val to int                ; <int> [#uses=1]

not this:

        %tmp.4.cast = cast bool %tmp.4 to int           ; <int> [#uses=1]
        %tmp.6 = select bool %tmp.1, int 1, int %tmp.4.cast             ; <int> [#uses=1]


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21389 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-21 05:43:13 +00:00
Chris Lattner
7d27fc0252 Wrap some long lines.
Make IPSCCP strip off dead constant exprs that are using functions, making
them appear as though their address is taken.  This allows us to propagate
some more pool descriptors, lowering the overhead of pool alloc.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21363 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-19 19:16:19 +00:00
Chris Lattner
240d6f4c9d Eliminate a broken transformation, fixing PR548
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21354 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-19 06:04:18 +00:00
Chris Lattner
ea96b5edbb silence a bogus warning
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21320 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-18 05:26:21 +00:00
Chris Lattner
36d12733bb a new simple pass, which will be extended to be more useful in the future.
This pass forward branches through conditions when it can show that the
conditions is either always true or false for a predecessor.  This currently
only handles the most simple cases of this, but is successful at threading
across 2489 branches and 65 switch instructions in 176.gcc, which isn't bad.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21306 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-15 19:28:32 +00:00
Chris Lattner
bf70b838e7 Fix bug: InstCombine/2005-05-07-UDivSelectCrash.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21152 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-08 04:03:26 +00:00
Chris Lattner
7edc8c223e Implement the following xforms:
(X-Y)-X --> -Y
A + (B - A) --> B
(B - A) + A --> B


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21138 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-07 17:14:51 +00:00
Chris Lattner
08954a26e4 Implement InstCombine/add.ll:test28, transforming C1-(X+C2) --> (C1-C2)-X.
This occurs several dozen times in specint2k, particularly in crafty and gcc
apparently.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21136 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-07 16:28:01 +00:00
Chris Lattner
43d84d6b71 Transform X-(X+Y) == -Y and X-(Y+X) == -Y
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21134 91177308-0d34-0410-b5e6-96231b3b80d8
2005-04-07 16:15:25 +00:00
Chris Lattner
b1515fe522 disable this transformation in the one obscure case that really pessimizes
pointer analysis.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20916 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-29 06:37:47 +00:00
Chris Lattner
70ac2dcb84 Fix a bug where LICM was not updating AA information properly when sinking
a pointer value out of a loop causing it to be duplicated.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20828 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-25 00:22:36 +00:00
Chris Lattner
1f309c1a4e enable -debug-only=licm
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20788 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-23 21:00:12 +00:00
Chris Lattner
e4d5c441e0 This mega patch converts us from using Function::a{iterator|begin|end} to
using Function::arg_{iterator|begin|end}.  Likewise Module::g* -> Module::global_*.

This patch is contributed by Gabor Greif, thanks!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20597 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-15 04:54:21 +00:00
Chris Lattner
2f62fdc9a7 fix a bug where we thought arguments were constants :(
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20506 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-06 22:52:29 +00:00
Chris Lattner
3f93197098 Fix Regression/Transforms/LoopStrengthReduce/dont_insert_redundant_ops.ll,
hopefully not breaking too many other things.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20505 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-06 22:36:12 +00:00
Chris Lattner
2f9b19b4c9 implement Transforms/LoopStrengthReduce/invariant_value_first_arg.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20501 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-06 22:06:22 +00:00
Chris Lattner
2461dff070 minor simplifications of the code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20497 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-06 21:58:22 +00:00
Chris Lattner
decc86db0c Fix a bug where we could corrupt a parent loop's header info if we unrolled
a nested loop.  This fixes Transforms/LoopUnroll/2005-03-06-BadLoopInfoUpdate.ll
and PR532


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20493 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-06 20:57:32 +00:00
Jeff Cohen
e43dd1b8e7 Reformat comments to fix 80 columns.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20467 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-05 22:45:40 +00:00
Jeff Cohen
b21bf9a8d5 Reuse induction variables created for strength-reduced GEPs by other similar GEPs.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20466 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-05 22:40:34 +00:00
Chris Lattner
8b9081081b Do not compute 1ULL << 64, which is undefined. This fixes Ptrdist/ks on the
sparc, and testcase Regression/Transforms/InstCombine/2005-03-04-ShiftOverflow.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20445 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-04 23:21:33 +00:00
Jeff Cohen
2f3c9b7562 Add support for not strength reducing GEPs where the element size is a small
power of two.  This emphatically includes the zeroeth power of two.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20429 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-04 04:04:26 +00:00
Jeff Cohen
0456e4a079 Fixed the following LSR bugs:
* Loop invariant code does not dominate the loop header, but rather
    the end of the loop preheader.

  * The base for a reduced GEP isn't a constant unless all of its
    operands (preceding the induction variable) are constant.

  * Allow induction variable elimination for the simple case after all.

Also made changes recommended by Chris for properly deleting
instructions.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20383 91177308-0d34-0410-b5e6-96231b3b80d8
2005-03-01 03:46:11 +00:00
Jeff Cohen
14dc638081 Fix crash in LSR due to attempt to remove original induction variable. However,
for reasons explained in the comments, I also deactivated this code as it needs
more thought.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20367 91177308-0d34-0410-b5e6-96231b3b80d8
2005-02-28 00:08:56 +00:00
Jeff Cohen
5e1e5e13ff PHI nodes were incorrectly placed when more than one GEP is reduced in a loop.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20360 91177308-0d34-0410-b5e6-96231b3b80d8
2005-02-27 21:08:04 +00:00
Jeff Cohen
f465db6c6a First pass at improved Loop Strength Reduction. Still not yet ready for prime time.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20358 91177308-0d34-0410-b5e6-96231b3b80d8
2005-02-27 19:37:07 +00:00
Chris Lattner
cfa2f8eef4 Remove use of bind_obj
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20276 91177308-0d34-0410-b5e6-96231b3b80d8
2005-02-22 23:22:58 +00:00
Chris Lattner
1a84bd38ef Do not mark obviously unreachable blocks live when processing PHI nodes,
and handle incomplete control dependences correctly.  This fixes:

Regression/Transforms/ADCE/dead-phi-edge.ll
  -> a missed optimization

Regression/Transforms/ADCE/dead-phi-edge.ll
  -> a compiler crash distilled from QT4


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20227 91177308-0d34-0410-b5e6-96231b3b80d8
2005-02-17 19:28:49 +00:00
Chris Lattner
8a7980b5ea Fix the second bug attached to PR504.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20181 91177308-0d34-0410-b5e6-96231b3b80d8
2005-02-14 20:11:45 +00:00
Chris Lattner
f6249261a9 Fix for testcase Transforms/IndVarsSimplify/2005-02-11-InvokeCrash.ll
and PR504.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20129 91177308-0d34-0410-b5e6-96231b3b80d8
2005-02-12 03:26:49 +00:00
Chris Lattner
ac930048d6 API change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19959 91177308-0d34-0410-b5e6-96231b3b80d8
2005-02-01 01:23:49 +00:00
Chris Lattner
fcfe33acda Implement InstCombine/cast.ll:test25, a case that occurs many times
in spec


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


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

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

to 'return 0', not abort().


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


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

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

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


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


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

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


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


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

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

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

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

to:

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


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

instead of generating this:

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


generate this:

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

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

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

to this:

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



instead of this:

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19536 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-13 22:25:21 +00:00
Chris Lattner
5bdf04cc8e Fix some bugs in code I didn't mean to check in.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19534 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-13 20:40:58 +00:00
Chris Lattner
574da9ba0b Fix a crash compiling 129.compress
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19533 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-13 20:14:25 +00:00
Chris Lattner
652f3cf76f Fix uint64_t -> unsigned VS warnings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19381 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-08 19:42:22 +00:00
Chris Lattner
d4bc564531 Silence VS warnings.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19380 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-08 19:37:20 +00:00
Chris Lattner
2cc34627bb Silence warnings
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19379 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-08 19:34:41 +00:00
Jeff Cohen
bf65268def Add more missing createXxxPass functions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19370 91177308-0d34-0410-b5e6-96231b3b80d8
2005-01-08 17:21:40 +00:00