diff options
author | Haicheng Wu <haicheng@codeaurora.org> | 2016-07-03 19:14:17 +0000 |
---|---|---|
committer | Haicheng Wu <haicheng@codeaurora.org> | 2016-07-03 19:14:17 +0000 |
commit | b71b2f622a00ab55073214e4e701f902ebeb8dc9 (patch) | |
tree | c89100d732785acd6c25fcc79d15e74898d07a36 /llvm/lib/CodeGen/MachineBasicBlock.cpp | |
parent | 68ea80649b3fd52b72c42c8e6453b6417012a262 (diff) | |
download | bcm5719-llvm-b71b2f622a00ab55073214e4e701f902ebeb8dc9.tar.gz bcm5719-llvm-b71b2f622a00ab55073214e4e701f902ebeb8dc9.zip |
[MBB] add a missing corner case in UpdateTerminator()
After the block placement, if a block ends with a conditional branch, but the
next block is not its successor. The conditional branch should be changed to
unconditional branch. This patch fixes PR28307, PR28297, PR28402.
Differential Revision: http://reviews.llvm.org/D21811
llvm-svn: 274470
Diffstat (limited to 'llvm/lib/CodeGen/MachineBasicBlock.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineBasicBlock.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp index e2d0c4b7e85..d4453c71da2 100644 --- a/llvm/lib/CodeGen/MachineBasicBlock.cpp +++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp @@ -470,17 +470,27 @@ void MachineBasicBlock::updateTerminator() { FallthroughBB = *SI; } - if (!FallthroughBB && canFallThrough()) { - // We fallthrough to the same basic block as the conditional jump targets. - // Remove the conditional jump, leaving unconditional fallthrough. - // FIXME: This does not seem like a reasonable pattern to support, but it - // has been seen in the wild coming out of degenerate ARM test cases. - TII->RemoveBranch(*this); + if (!FallthroughBB) { + if (canFallThrough()) { + // We fallthrough to the same basic block as the conditional jump targets. + // Remove the conditional jump, leaving unconditional fallthrough. + // FIXME: This does not seem like a reasonable pattern to support, but it + // has been seen in the wild coming out of degenerate ARM test cases. + TII->RemoveBranch(*this); + + // Finally update the unconditional successor to be reached via a branch if + // it would not be reached by fallthrough. + if (!isLayoutSuccessor(TBB)) + TII->InsertBranch(*this, TBB, nullptr, Cond, DL); + return; + } - // Finally update the unconditional successor to be reached via a branch if - // it would not be reached by fallthrough. - if (!isLayoutSuccessor(TBB)) - TII->InsertBranch(*this, TBB, nullptr, Cond, DL); + // We enter here iff exactly one successor is TBB which cannot fallthrough + // and the rest successors if any are EHPads. In this case, we need to + // change the conditional branch into unconditional branch. + TII->RemoveBranch(*this); + Cond.clear(); + TII->InsertBranch(*this, TBB, nullptr, Cond, DL); return; } |