aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/BranchFolding.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/BranchFolding.cpp')
-rw-r--r--llvm/lib/CodeGen/BranchFolding.cpp50
1 files changed, 6 insertions, 44 deletions
diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp
index 1cb0a23..3b3e7a4 100644
--- a/llvm/lib/CodeGen/BranchFolding.cpp
+++ b/llvm/lib/CodeGen/BranchFolding.cpp
@@ -2083,59 +2083,22 @@ bool BranchFolder::HoistCommonCodeInSuccs(MachineBasicBlock *MBB) {
if (TBB == FBB) {
MBB->splice(Loc, TBB, TBB->begin(), TIB);
} else {
- // Merge the debug locations, and hoist and kill the debug instructions from
- // both branches. FIXME: We could probably try harder to preserve some debug
- // instructions (but at least this isn't producing wrong locations).
- MachineInstrBuilder MIRBuilder(*MBB->getParent(), Loc);
- auto HoistAndKillDbgInstr = [MBB, Loc](MachineBasicBlock::iterator DI) {
- assert(DI->isDebugInstr() && "Expected a debug instruction");
- if (DI->isDebugRef()) {
- const TargetInstrInfo *TII =
- MBB->getParent()->getSubtarget().getInstrInfo();
- const MCInstrDesc &DBGV = TII->get(TargetOpcode::DBG_VALUE);
- DI = BuildMI(*MBB->getParent(), DI->getDebugLoc(), DBGV, false, 0,
- DI->getDebugVariable(), DI->getDebugExpression());
- MBB->insert(Loc, &*DI);
- return;
- }
- // Deleting a DBG_PHI results in an undef at the referenced DBG_INSTR_REF.
- if (DI->isDebugPHI()) {
- DI->eraseFromParent();
- return;
- }
-
- DI->setDebugValueUndef();
- DI->moveBefore(&*Loc);
- };
-
// TIB and FIB point to the end of the regions to hoist/merge in TBB and
// FBB.
MachineBasicBlock::iterator FE = FIB;
MachineBasicBlock::iterator FI = FBB->begin();
for (MachineBasicBlock::iterator TI :
make_early_inc_range(make_range(TBB->begin(), TIB))) {
- // Hoist and kill debug instructions from FBB. After this loop FI points
- // to the next non-debug instruction to hoist (checked in assert after the
- // TBB debug instruction handling code).
- while (FI->isDebugInstr()) {
- assert(FI != FE && "Unexpected end of FBB range");
- MachineBasicBlock::iterator FINext = std::next(FI);
- HoistAndKillDbgInstr(FI);
- FI = FINext;
- }
-
- // Kill debug instructions before moving.
- if (TI->isDebugInstr()) {
- HoistAndKillDbgInstr(TI);
+ // Move debug instructions and pseudo probes without modifying them.
+ // FIXME: This is the wrong thing to do for debug locations, which
+ // should at least be killed (and hoisted from BOTH blocks).
+ if (TI->isDebugOrPseudoInstr()) {
+ TI->moveBefore(&*Loc);
continue;
}
- // If FI is a debug instruction, skip forward to the next non-debug
- // instruction.
+ // Get the next non-meta instruction in FBB.
FI = skipDebugInstructionsForward(FI, FE, false);
- // Pseudo probes are excluded from the range when identifying foldable
- // instructions, so we don't expect to see one now.
- assert(!TI->isPseudoProbe() && "Unexpected pseudo probe in range");
// NOTE: The loop above checks CheckKillDead but we can't do that here as
// it modifies some kill markers after the check.
assert(TI->isIdenticalTo(*FI, MachineInstr::CheckDefs) &&
@@ -2148,7 +2111,6 @@ bool BranchFolder::HoistCommonCodeInSuccs(MachineBasicBlock *MBB) {
++FI;
}
}
-
FBB->erase(FBB->begin(), FIB);
if (UpdateLiveIns)