[PATCH] D19847: Codegen: Don't outline in favor of return blocks

Kyle Butt via llvm-commits llvm-commits at lists.llvm.org
Mon May 2 18:34:04 PDT 2016


iteratee created this revision.
iteratee added a reviewer: djasper.
iteratee added a subscriber: llvm-commits.
iteratee set the repository for this revision to rL LLVM.

When outlining optional branches, an early exit condition will make the
rest of the function optional. If we outline in favor of this exit
block, it can place the return block in the middle of the function. In 3
very different benchmarks, I found that not outlining in favor of the
return block would fix the performance regression. Two of the benchmarks
are in the test-suite:
MultiSource/Applications/lambda-0.1.3/lambda.test
SingleSource/Benchmarks/fib2

lambda exhibits far worse instruction decode cache with outlining
enabled and without this patch.

fib2 exhibits worse branch prediction, which by itself isn't an argument
for this patch, but it is another point in a pattern.

The internal benchmark that slowed down was basically a large function
where incorrect exit placement created additional icache misses

Taken together these three data points, along with the absence of any
obvious regressions in the test-suite with outlining enabled vs this
patch suggest that this is a reasonable heuristic.


Repository:
  rL LLVM

http://reviews.llvm.org/D19847

Files:
  lib/CodeGen/MachineBlockPlacement.cpp

Index: lib/CodeGen/MachineBlockPlacement.cpp
===================================================================
--- lib/CodeGen/MachineBlockPlacement.cpp
+++ lib/CodeGen/MachineBlockPlacement.cpp
@@ -453,8 +453,11 @@
     // If we outline optional branches, look whether Succ is unavoidable, i.e.
     // dominates all terminators of the MachineFunction. If it does, other
     // successors must be optional. Don't do this for cold branches.
+    // Also, return branches seem to behave perversely as well. Don't outline in
+    // favor of them either, unless the exit branch is hot.
     if (OutlineOptionalBranches && SuccProb > HotProb.getCompl() &&
-        UnavoidableBlocks.count(Succ) > 0) {
+        UnavoidableBlocks.count(Succ) > 0 &&
+        (!Succ->isReturnBlock() || SuccProb > HotProb)) {
       auto HasShortOptionalBranch = [&]() {
         for (MachineBasicBlock *Pred : Succ->predecessors()) {
           // Check whether there is an unplaced optional branch.
@@ -672,7 +675,7 @@
     // after this block.
     MachineBasicBlock *BestSucc = selectBestSuccessor(BB, Chain, BlockFilter);
 
-    // If an immediate successor isn't available, look for the best viable
+   // If an immediate successor isn't available, look for the best viable
     // block among those we've identified as not violating the loop's CFG at
     // this point. This won't be a fallthrough, but it will increase locality.
     if (!BestSucc)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19847.55931.patch
Type: text/x-patch
Size: 1439 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160503/b77d05df/attachment.bin>


More information about the llvm-commits mailing list