llvm-6502/lib/Transforms/Scalar
Chris Lattner 3d834bf2c3 Do not fold (X + C1 != C2) if there are other users of the add. Doing
this transformation used to take a loop like this:

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

Compiled to LLVM is:

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

and turn it into a loop like this:

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

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

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

into this:

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

We need better instruction selection to get this:

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

... but at least there is less register juggling


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16473 91177308-0d34-0410-b5e6-96231b3b80d8
2004-09-21 21:35:23 +00:00
..
ADCE.cpp Prototype these functions more accurately 2004-09-20 04:43:15 +00:00
BasicBlockPlacement.cpp Changes For Bug 352 2004-09-01 22:55:40 +00:00
ConstantProp.cpp Prototype these functions more accurately 2004-09-20 04:43:15 +00:00
CorrelatedExprs.cpp Prototype these functions more accurately 2004-09-20 04:43:15 +00:00
DCE.cpp Prototype these functions more accurately 2004-09-20 04:43:15 +00:00
DeadStoreElimination.cpp Prototype these functions more accurately 2004-09-20 04:43:15 +00:00
DecomposeMultiDimRefs.cpp Changes For Bug 352 2004-09-01 22:55:40 +00:00
GCSE.cpp Changes For Bug 352 2004-09-01 22:55:40 +00:00
IndVarSimplify.cpp Prototype these functions more accurately 2004-09-20 04:43:15 +00:00
InstructionCombining.cpp Do not fold (X + C1 != C2) if there are other users of the add. Doing 2004-09-21 21:35:23 +00:00
LICM.cpp Fix a bug in the previous checkin that broke 255.vortex 2004-09-15 02:34:40 +00:00
LoopUnroll.cpp Convert code to compile with vc7.1. 2004-09-15 17:06:42 +00:00
LoopUnswitch.cpp Fixes to make LLVM compile with vc7.1. 2004-09-03 18:19:51 +00:00
LowerConstantExprs.cpp Fix #includes of i*.h => Instructions.h as per PR403. 2004-07-29 17:05:13 +00:00
LowerGC.cpp Update GC intrinsics to take a pointer to the object as well as a pointer 2004-07-22 05:51:13 +00:00
LowerPacked.cpp Changes For Bug 352 2004-09-01 22:55:40 +00:00
Makefile Added LLVM copyright notice to Makefiles. 2003-10-20 22:26:57 +00:00
PRE.cpp Changes For Bug 352 2004-09-01 22:55:40 +00:00
Reassociate.cpp Changes For Bug 352 2004-09-01 22:55:40 +00:00
ScalarReplAggregates.cpp Prototype these functions more accurately 2004-09-20 04:43:15 +00:00
SCCP.cpp Prototype these functions more accurately 2004-09-20 04:43:15 +00:00
SimplifyCFG.cpp Changes For Bug 352 2004-09-01 22:55:40 +00:00
SymbolStripping.cpp Prototype these functions more accurately 2004-09-20 04:43:15 +00:00
TailDuplication.cpp Prototype these functions more accurately 2004-09-20 04:43:15 +00:00
TailRecursionElimination.cpp Changes For Bug 352 2004-09-01 22:55:40 +00:00