Implement a simple optimization for the termination condition of the loop.
authorChris Lattner <sabre@nondot.org>
Mon, 8 Aug 2005 05:28:22 +0000 (05:28 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 8 Aug 2005 05:28:22 +0000 (05:28 +0000)
commit010de25f42dabbb7e0a2fe8b42aecc4285362e0c
tree13ee2c5a8cd19811ff6abb3d6003fb2ba096b627
parent0fe34d89126c594e0e8378d978a593350189fedf
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
lib/Transforms/Scalar/LoopStrengthReduce.cpp