summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/BranchFolding.cpp
diff options
context:
space:
mode:
authorAndrew Kaylor <andrew.kaylor@intel.com>2016-12-12 23:05:38 +0000
committerAndrew Kaylor <andrew.kaylor@intel.com>2016-12-12 23:05:38 +0000
commitff6a1edfa8e620c3699e00e809905d4d82757d68 (patch)
tree73b92556776e6370d9c7a50b3008a6bce6b6a697 /llvm/lib/CodeGen/BranchFolding.cpp
parent7495a4895c2cba2ab9c4e0fd1b82a6b818a63abf (diff)
downloadbcm5719-llvm-ff6a1edfa8e620c3699e00e809905d4d82757d68.tar.gz
bcm5719-llvm-ff6a1edfa8e620c3699e00e809905d4d82757d68.zip
Avoid infinite loops in branch folding
Differential Revision: https://reviews.llvm.org/D27582 llvm-svn: 289486
Diffstat (limited to 'llvm/lib/CodeGen/BranchFolding.cpp')
-rw-r--r--llvm/lib/CodeGen/BranchFolding.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp
index 20dc8805150..913d5d91890 100644
--- a/llvm/lib/CodeGen/BranchFolding.cpp
+++ b/llvm/lib/CodeGen/BranchFolding.cpp
@@ -1624,10 +1624,22 @@ ReoptimizeBlock:
// Okay, there is no really great place to put this block. If, however,
// the block before this one would be a fall-through if this block were
- // removed, move this block to the end of the function.
+ // removed, move this block to the end of the function. There is no real
+ // advantage in "falling through" to an EH block, so we don't want to
+ // perform this transformation for that case.
+ //
+ // Also, Windows EH introduced the possibility of an arbitrary number of
+ // successors to a given block. The analyzeBranch call does not consider
+ // exception handling and so we can get in a state where a block
+ // containing a call is followed by multiple EH blocks that would be
+ // rotated infinitely at the end of the function if the transformation
+ // below were performed for EH "FallThrough" blocks. Therefore, even if
+ // that appears not to be happening anymore, we should assume that it is
+ // possible and not remove the "!FallThrough()->isEHPad" condition below.
MachineBasicBlock *PrevTBB = nullptr, *PrevFBB = nullptr;
SmallVector<MachineOperand, 4> PrevCond;
if (FallThrough != MF.end() &&
+ !FallThrough->isEHPad() &&
!TII->analyzeBranch(PrevBB, PrevTBB, PrevFBB, PrevCond, true) &&
PrevBB.isSuccessor(&*FallThrough)) {
MBB->moveAfter(&MF.back());
OpenPOWER on IntegriCloud