summaryrefslogtreecommitdiff
path: root/lib/CodeGen/BranchFolding.cpp
diff options
context:
space:
mode:
authorDale Johannesen <dalej@apple.com>2010-03-09 23:52:37 +0000
committerDale Johannesen <dalej@apple.com>2010-03-09 23:52:37 +0000
commit7f876967c0b368de48a1d0b9318b5113fddcf591 (patch)
tree4f043d606d90dea5018bbfac74b32a5a6dd5e9f0 /lib/CodeGen/BranchFolding.cpp
parent4ecbca558f8ee558dd0e84e079f16528fd9768f2 (diff)
downloadllvm-7f876967c0b368de48a1d0b9318b5113fddcf591.tar.gz
llvm-7f876967c0b368de48a1d0b9318b5113fddcf591.tar.bz2
llvm-7f876967c0b368de48a1d0b9318b5113fddcf591.tar.xz
Ever more complicated DEBUG_VALUE fixes for branch folding.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98104 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/BranchFolding.cpp')
-rw-r--r--lib/CodeGen/BranchFolding.cpp59
1 files changed, 56 insertions, 3 deletions
diff --git a/lib/CodeGen/BranchFolding.cpp b/lib/CodeGen/BranchFolding.cpp
index a937e8f4b4..adf1c14152 100644
--- a/lib/CodeGen/BranchFolding.cpp
+++ b/lib/CodeGen/BranchFolding.cpp
@@ -347,15 +347,29 @@ static unsigned ComputeCommonTailLength(MachineBasicBlock *MBB1,
--I1; --I2;
// Skip debugging pseudos; necessary to avoid changing the code.
while (I1->isDebugValue()) {
- if (I1==MBB1->begin())
+ if (I1==MBB1->begin()) {
+ while (I2->isDebugValue()) {
+ if (I2==MBB2->begin())
+ // I1==DBG at begin; I2==DBG at begin
+ return TailLen;
+ --I2;
+ }
+ ++I2;
+ // I1==DBG at begin; I2==non-DBG, or first of DBGs not at begin
return TailLen;
+ }
--I1;
}
+ // I1==first (untested) non-DBG preceding known match
while (I2->isDebugValue()) {
- if (I2==MBB2->begin())
+ if (I2==MBB2->begin()) {
+ ++I1;
+ // I1==non-DBG, or first of DBGs not at begin; I2==DBG at begin
return TailLen;
+ }
--I2;
}
+ // I1, I2==first (untested) non-DBGs preceding known match
if (!I1->isIdenticalTo(I2) ||
// FIXME: This check is dubious. It's used to get around a problem where
// people incorrectly expect inline asm directives to remain in the same
@@ -368,6 +382,29 @@ static unsigned ComputeCommonTailLength(MachineBasicBlock *MBB1,
}
++TailLen;
}
+ // Back past possible debugging pseudos at beginning of block. This matters
+ // when one block differs from the other only by whether debugging pseudos
+ // are present at the beginning. (This way, the various checks later for
+ // I1==MBB1->begin() work as expected.)
+ if (I1 == MBB1->begin() && I2 != MBB2->begin()) {
+ --I2;
+ while (I2->isDebugValue()) {
+ if (I2 == MBB2->begin()) {
+ return TailLen;
+ }
+ --I2;
+ }
+ ++I2;
+ }
+ if (I2 == MBB2->begin() && I1 != MBB1->begin()) {
+ --I1;
+ while (I1->isDebugValue()) {
+ if (I1 == MBB1->begin())
+ return TailLen;
+ --I1;
+ }
+ ++I1;
+ }
return TailLen;
}
@@ -1163,7 +1200,23 @@ ReoptimizeBlock:
// be 'non-branch terminators' in the block, try removing the branch and
// then seeing if the block is empty.
TII->RemoveBranch(*MBB);
-
+ // If the only things remaining in the block are debug info, remove these
+ // as well, so this will behave the same as an empty block in non-debug
+ // mode.
+ if (!MBB->empty()) {
+ bool NonDebugInfoFound = false;
+ for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end();
+ I != E; ++I) {
+ if (!I->isDebugValue()) {
+ NonDebugInfoFound = true;
+ break;
+ }
+ }
+ if (!NonDebugInfoFound)
+ // Make the block empty, losing the debug info (we could probably
+ // improve this in some cases.)
+ MBB->erase(MBB->begin(), MBB->end());
+ }
// If this block is just an unconditional branch to CurTBB, we can
// usually completely eliminate the block. The only case we cannot
// completely eliminate the block is when the block before this one