OSDN Git Service

Add logic to greedy reg alloc to avoid bad eviction chains
authorMarina Yatsina <marina.yatsina@intel.com>
Sun, 22 Oct 2017 17:59:38 +0000 (17:59 +0000)
committerMarina Yatsina <marina.yatsina@intel.com>
Sun, 22 Oct 2017 17:59:38 +0000 (17:59 +0000)
commitb76f989d6bcfdbc88d3e8c45d5b4363f163f7996
treeaba2417616f81149b5df9c5137236ff53c991df0
parent3dbdbd2328e6df9422f9795d537c40a4c3b1c1ca
Add logic to greedy reg alloc to avoid bad eviction chains

This fixes bugzilla 26810
https://bugs.llvm.org/show_bug.cgi?id=26810

This is intended to prevent sequences like:
movl %ebp, 8(%esp) # 4-byte Spill
movl %ecx, %ebp
movl %ebx, %ecx
movl %edi, %ebx
movl %edx, %edi
cltd
idivl %esi
movl %edi, %edx
movl %ebx, %edi
movl %ecx, %ebx
movl %ebp, %ecx
movl 16(%esp), %ebp # 4 - byte Reload

Such sequences are created in 2 scenarios:

Scenario #1:
vreg0 is evicted from physreg0 by vreg1
Evictee vreg0 is intended for region splitting with split candidate physreg0 (the reg vreg0 was evicted from)
Region splitting creates a local interval because of interference with the evictor vreg1 (normally region spliiting creates 2 interval, the "by reg" and "by stack" intervals. Local interval created when interference occurs.)
one of the split intervals ends up evicting vreg2 from physreg1
Evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills

Scenario #2
vreg0 is evicted from physreg0 by vreg1
vreg2 is evicted from physreg2 by vreg3 etc
Evictee vreg0 is intended for region splitting with split candidate physreg1
Region splitting creates a local interval because of interference with the evictor vreg1
one of the split intervals ends up evicting back original evictor vreg1 from physreg0 (the reg vreg0 was evicted from)
Another evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills

As compile time was a concern, I've added a flag to control weather we do cost calculations for local intervals we expect to be created (it's on by default for X86 target, off for the rest).

Differential Revision: https://reviews.llvm.org/D35816

Change-Id: Id9411ff7bbb845463d289ba2ae97737a1ee7cc39

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316295 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/CodeGen/CalcSpillWeights.h
include/llvm/CodeGen/LiveIntervalAnalysis.h
include/llvm/Target/TargetSubtargetInfo.h
lib/CodeGen/CalcSpillWeights.cpp
lib/CodeGen/LiveIntervalAnalysis.cpp
lib/CodeGen/RegAllocGreedy.cpp
lib/CodeGen/TargetSubtargetInfo.cpp
lib/Target/X86/X86Subtarget.h
test/CodeGen/X86/bug26810.ll [new file with mode: 0644]
test/CodeGen/X86/greedy_regalloc_bad_eviction_sequence.ll [new file with mode: 0644]