[PATCH] D34271: [MBP] do not rotate loop if it creates extra branch

Serguei Katkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 15 23:02:17 PDT 2017


skatkov created this revision.

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.


https://reviews.llvm.org/D34271

Files:
  lib/CodeGen/MachineBlockPlacement.cpp
  test/CodeGen/X86/block-placement.ll
  test/CodeGen/X86/code_placement_cold_loop_blocks.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34271.102787.patch
Type: text/x-patch
Size: 4120 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170616/43e175e0/attachment.bin>


More information about the llvm-commits mailing list