In MachineBlockPlacement, filter cold blocks off the loop chain when profile data...
authorCong Hou <congh@google.com>
Mon, 2 Nov 2015 21:24:00 +0000 (21:24 +0000)
committerCong Hou <congh@google.com>
Mon, 2 Nov 2015 21:24:00 +0000 (21:24 +0000)
commitb18412ca5b154559691c5d875fd382e4865f6eab
treed67b38b4fe11eeeb2cc5d439f8507ccdecc0672f
parent258dc25c121c2af07444cd657a0160dc52fdebbc
In MachineBlockPlacement, filter cold blocks off the loop chain when profile data is available.

In the current BB placement algorithm, a loop chain always contains all loop blocks. This has a drawback that cold blocks in the loop may be inserted on a hot function path, hence increasing branch cost and also reducing icache locality.

Consider a simple example shown below:

A
|
B⇆C
|
D

When B->C is quite cold, the best BB-layout should be A,B,D,C. But the current implementation produces A,C,B,D.

This patch filters those cold blocks off from the loop chain by comparing the ratio:

LoopBBFreq / LoopFreq

to 20%: if it is less than 20%, we don't include this BB to the loop chain. Here LoopFreq is the frequency of the loop when we reduce the loop into a single node. In general we have more cold blocks when the loop has few iterations. And vice versa.

Differential revision: http://reviews.llvm.org/D11662

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251833 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/MachineBlockPlacement.cpp
test/CodeGen/X86/code_placement_cold_loop_blocks.ll [new file with mode: 0644]