Allocate local registers in order for optimal coloring.
authorAndrew Trick <atrick@apple.com>
Thu, 25 Jul 2013 18:35:14 +0000 (18:35 +0000)
committerAndrew Trick <atrick@apple.com>
Thu, 25 Jul 2013 18:35:14 +0000 (18:35 +0000)
commit6ea2b9608a38e9b53d208ff85051e8e3ed53192c
treebcb6d902e9da1081ea9fb6a6a1716f3ba3768621
parent9e2ef7780b91d8e01a9ab172f80272fc94f6956b
Allocate local registers in order for optimal coloring.

Also avoid locals evicting locals just because they want a cheaper register.

Problem: MI Sched knows exactly how many registers we have and assumes
they can be colored. In cases where we have large blocks, usually from
unrolled loops, greedy coloring fails. This is a source of
"regressions" from the MI Scheduler on x86. I noticed this issue on
x86 where we have long chains of two-address defs in the same live
range. It's easy to see this in matrix multiplication benchmarks like
IRSmk and even the unit test misched-matmul.ll.

A fundamental difference between the LLVM register allocator and
conventional graph coloring is that in our model a live range can't
discover its neighbors, it can only verify its neighbors. That's why
we initially went for greedy coloring and added eviction to deal with
the hard cases. However, for singly defined and two-address live
ranges, we can optimally color without visiting neighbors simply by
processing the live ranges in instruction order.

Other beneficial side effects:

It is much easier to understand and debug regalloc for large blocks
when the live ranges are allocated in order. Yes, global allocation is
still very confusing, but it's nice to be able to comprehend what
happened locally.

Heuristics could be added to bias register assignment based on
instruction locality (think late register pairing, banks...).

Intuituvely this will make some test cases that are on the threshold
of register pressure more stable.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187139 91177308-0d34-0410-b5e6-96231b3b80d8
19 files changed:
lib/CodeGen/RegAllocGreedy.cpp
test/CodeGen/ARM/2012-10-04-AAPCS-byval-align8.ll
test/CodeGen/ARM/avoid-cpsr-rmw.ll
test/CodeGen/ARM/eh-dispcont.ll
test/CodeGen/ARM/fpcmp-opt.ll
test/CodeGen/ARM/select-imm.ll
test/CodeGen/ARM/struct-byval-frame-index.ll
test/CodeGen/Mips/mips16_fpret.ll
test/CodeGen/SPARC/64cond.ll
test/CodeGen/X86/StackColoring.ll
test/CodeGen/X86/alloca-align-rounding-32.ll
test/CodeGen/X86/legalize-shift-64.ll
test/CodeGen/X86/lsr-loop-exit-cond.ll
test/CodeGen/X86/misched-matmul.ll
test/CodeGen/X86/select.ll
test/CodeGen/X86/sse3.ll
test/CodeGen/X86/x86-64-and-mask.ll
test/CodeGen/X86/zext-sext.ll
test/Transforms/LoopStrengthReduce/ARM/ivchain-ARM.ll