llvm-6502/test
Eric Christopher 63295d884c Fix a problem where the TwoAddressInstructionPass which generate redundant register moves in a loop.
From:
int M, total;
void foo() {
int i;
for (i = 0; i < M; i++) {
  total = total + i / 2;
}
}

This is the kernel loop:

.LBB0_2: # %for.body

=>This Inner Loop Header: Depth=1
movl %edx, %esi
movl %ecx, %edx
shrl $31, %edx
addl %ecx, %edx
sarl %edx
addl %esi, %edx
incl %ecx
cmpl %eax, %ecx
jl .LBB0_2
--------------------------
The first mov insn "movl %edx, %esi" could be removed if we change "addl %esi, %edx" to "addl %edx, %esi".

The IR before TwoAddressInstructionPass is:
BB#2: derived from LLVM BB %for.body

Predecessors according to CFG: BB#1 BB#2
    %vreg3<def> = COPY %vreg12<kill>; GR32:%vreg3,%vreg12
    %vreg2<def> = COPY %vreg11<kill>; GR32:%vreg2,%vreg11
    %vreg7<def,tied1> = SHR32ri %vreg3<tied0>, 31, %EFLAGS<imp-def,dead>; GR32:%vreg7,%vreg3
    %vreg8<def,tied1> = ADD32rr %vreg3<tied0>, %vreg7<kill>, %EFLAGS<imp-def,dead>; GR32:%vreg8,%vreg3,%vreg7
    %vreg9<def,tied1> = SAR32r1 %vreg8<kill,tied0>, %EFLAGS<imp-def,dead>; GR32:%vreg9,%vreg8
    %vreg4<def,tied1> = ADD32rr %vreg9<kill,tied0>, %vreg2<kill>, %EFLAGS<imp-def,dead>; GR32:%vreg4,%vreg9,%vreg2
    %vreg5<def,tied1> = INC64_32r %vreg3<kill,tied0>, %EFLAGS<imp-def,dead>; GR32:%vreg5,%vreg3
    CMP32rr %vreg5, %vreg0, %EFLAGS<imp-def>; GR32:%vreg5,%vreg0
    %vreg11<def> = COPY %vreg4; GR32:%vreg11,%vreg4
    %vreg12<def> = COPY %vreg5<kill>; GR32:%vreg12,%vreg5
    JL_4 <BB#2>, %EFLAGS<imp-use,kill>
Now TwoAddressInstructionPass will choose vreg9 to be tied with vreg4. However, it doesn't see that there is copy from vreg4 to vreg11 and another copy from vreg11 to vreg2 inside the loop body. To remove those copies, it is necessary to choose vreg2 to be tied with vreg4 instead of vreg9. This code pattern commonly appears when there is reduction operation in a loop.

So check for a reversed copy chain and if we encounter one then we can commute the add instruction so we can avoid a copy.

Patch by Wei Mi.
http://reviews.llvm.org/D7806

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231148 91177308-0d34-0410-b5e6-96231b3b80d8
2015-03-03 22:03:03 +00:00
..
Analysis Make llvm.eh.begincatch use an outparam 2015-03-03 17:41:09 +00:00
Assembler DebugInfo: Move new hierarchy into place 2015-03-03 17:24:31 +00:00
Bindings DebugInfo: Move new hierarchy into place 2015-03-03 17:24:31 +00:00
Bitcode [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
BugPoint DebugInfo: Move new hierarchy into place 2015-03-03 17:24:31 +00:00
CodeGen Fix a problem where the TwoAddressInstructionPass which generate redundant register moves in a loop. 2015-03-03 22:03:03 +00:00
DebugInfo [X86][ELF] Correct relocation for DWARF TLS references 2015-03-03 21:01:27 +00:00
ExecutionEngine [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
Feature DebugInfo: Move new hierarchy into place 2015-03-03 17:24:31 +00:00
FileCheck FileCheck: Add CHECK-SAME 2015-02-26 04:53:00 +00:00
Instrumentation DebugInfo: Move new hierarchy into place 2015-03-03 17:24:31 +00:00
Integer [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
JitListener DebugInfo: Move new hierarchy into place 2015-03-03 17:24:31 +00:00
Linker DebugInfo: Move new hierarchy into place 2015-03-03 17:24:31 +00:00
LTO [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
MC Add the following 64-bit vector integer arithmetic instructions added in POWER8: 2015-03-03 19:55:45 +00:00
Object Make llvm/test/Object/archive-format.test CRLF-tolerant. 2015-03-03 15:54:48 +00:00
Other [opaque pointer type] Add textual IR support for explicit type parameter to load instruction 2015-02-27 21:17:42 +00:00
SymbolRewriter SymbolRewriter: allow rewriting with comdats 2015-01-27 22:57:39 +00:00
TableGen
tools Correctly handle -pass-remarks in the gold plugin. 2015-03-03 21:11:13 +00:00
Transforms Teach ComputeNumSignBits about signed divisions. 2015-03-03 21:39:02 +00:00
Unit
Verifier Teach the verifier to enforce that the alignment argument of memory intrinsics must be a power of 2. 2015-03-02 09:35:06 +00:00
YAMLParser
.clang-format
CMakeLists.txt Back out two accidental changes that snuck in with r229245. Sorry these 2015-02-14 09:05:58 +00:00
lit.cfg Change SystemZ large tests to use the existing long_tests property 2015-03-02 19:34:11 +00:00
lit.site.cfg.in Remove log statements from config scripts. 2015-02-22 07:31:42 +00:00
Makefile Attempt to fix the builders. 2015-02-22 07:01:41 +00:00
Makefile.tests
TestRunner.sh