[PATCH] D27582: Avoid infinite loops in branch folding

Andy Kaylor via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 8 11:02:51 PST 2016


andrew.w.kaylor created this revision.
andrew.w.kaylor added reviewers: rnk, MatzeB.
andrew.w.kaylor added a subscriber: llvm-commits.
andrew.w.kaylor set the repository for this revision to rL LLVM.

This reintroduces a fix for a problem where the branch folding optimization can go into an infinite loop shuffling blocks at the end of a function.  This problem was originally fixed in https://reviews.llvm.org/D14996 but that change was reverted as seen in https://reviews.llvm.org/D22839 because it was causing compile time to blow up in some circumstances.  At the time this was reverted I believed that the original problem could no longer be reproduced, but I have since seen it with a particular set of optimization options with the spec2006/483 benchmark.

The test case I am adding here is a version of the 483 code that was reduced using bugpoint.  I am not clear as to exactly why this particular case is triggering the problem, but I wasn't able to reduce it any further.  I suspect that the state it is in now just happens to trigger different behavior prior to branch folding when optimizing for size.

In any event, the important thing is that the potential for the problem still exists.  The root cause is that when the branch folding code is hit there is a block near the end of the function with a function call followed by a branch to a block that is higher in the function, then three or more exception handling blocks which are possible successors by way of exceptions in the called function.  In this case, the code prior to this patch would rotate the exception blocks to the end of the function in infinite succession.

The compilation time problem was caused by the previous attempt to find a non-exception handling block beyond the block to be moved.  In a function containing a large number of exception handling blocks this led to quadratic or worse behavior.  The new fix simply gives up if the block following the block to be moved is an exception handling block.


Repository:
  rL LLVM

https://reviews.llvm.org/D27582

Files:
  lib/CodeGen/BranchFolding.cpp
  test/CodeGen/WinEH/wineh-noret-cleanup.ll
  test/CodeGen/X86/branchfolding-catchpads.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27582.80784.patch
Type: text/x-patch
Size: 4828 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161208/151ae863/attachment-0001.bin>


More information about the llvm-commits mailing list