]> granicus.if.org Git - llvm/commit
[MBP] do not rotate loop if it creates extra branch
authorSerguei Katkov <serguei.katkov@azul.com>
Mon, 26 Jun 2017 05:27:27 +0000 (05:27 +0000)
committerSerguei Katkov <serguei.katkov@azul.com>
Mon, 26 Jun 2017 05:27:27 +0000 (05:27 +0000)
commit0eb7237e7533e7682b653ecfd8e4bce3a88bd9c1
tree1747d969ccd5e8279204cac8d936d6b74546a18b
parent6eebd6c274657317d23a03f160250e4cb808b94d
[MBP] do not rotate loop if it creates extra branch

This is a last fix for the corner case of PR32214. Actually this is not really corner case in general.

We should not do a loop rotation if we create an additional branch due to it.
Consider the case where we have a loop chain H, M, B, C , where
H is header with viable fallthrough from pre-header and exit from the loop
M - some middle block
B - backedge to Header but with exit from the loop also.
C - some cold block of the loop.

Let's H is determined as a best exit. If we do a loop rotation M, B, C, H we can introduce the extra branch.
Let's compute the change in number of branches:
+1 branch from pre-header to header
-1 branch from header to exit
+1 branch from header to middle block if there is such
-1 branch from cold bock to header if there is one

So if C is not a predecessor of H then we introduce extra branch.

This change actually prohibits rotation of the loop if both true
1) Best Exit has next element in chain as successor.
2) Last element in chain is not a predecessor of first element of chain.

Reviewers: iteratee, xur
Reviewed By: iteratee
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D34271

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306272 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/MachineBlockPlacement.cpp
test/CodeGen/X86/block-placement.ll
test/CodeGen/X86/code_placement_cold_loop_blocks.ll