diff --git a/llvm/include/llvm/CodeGen/MachineBasicBlock.h b/llvm/include/llvm/CodeGen/MachineBasicBlock.h --- a/llvm/include/llvm/CodeGen/MachineBasicBlock.h +++ b/llvm/include/llvm/CodeGen/MachineBasicBlock.h @@ -484,13 +484,6 @@ InlineAsmBrIndirectTargets.insert(Tgt); } - /// Transfers indirect targets to INLINEASM_BR's copy block. - void transferInlineAsmBrIndirectTargets(MachineBasicBlock *CopyBB) { - for (auto *Target : InlineAsmBrIndirectTargets) - CopyBB->addInlineAsmBrIndirectTarget(Target); - return InlineAsmBrIndirectTargets.clear(); - } - /// Returns true if this is the default dest of an INLINEASM_BR. bool isInlineAsmBrDefaultTarget() const { return InlineAsmBrDefaultTarget; diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp --- a/llvm/lib/CodeGen/BranchFolding.cpp +++ b/llvm/lib/CodeGen/BranchFolding.cpp @@ -159,6 +159,25 @@ void BranchFolder::RemoveDeadBlock(MachineBasicBlock *MBB) { assert(MBB->pred_empty() && "MBB must be dead!"); LLVM_DEBUG(dbgs() << "\nRemoving MBB: " << *MBB); +#ifndef NDEBUG + if (MBB->hasAddressTaken()) + for (const MachineBasicBlock &Pred : *MBB->getParent()) + // Iterating Pred.terminators() may be unreliable in this case. + // MachineBasicBlock#getFirstTerminator() iterates backwards through the + // MachineBasicBlock's MachineInstrs to the first non-Terminal, then + // moves forward one and returns that. If a non-terminator gets inserted + // after the INLINEASM_BR, perhaps by accident, then + // MachineBasicBlock#getFirstTerminator() and + // MachineBasicBlock#terminators() will not return the INLINEASM_BR + // terminator. + for (const MachineInstr &I : Pred) + if (I.getOpcode() == TargetOpcode::INLINEASM_BR) + for (const MachineOperand &Op : I.operands()) + if (Op.isBlockAddress() && Pred.isInlineAsmBrIndirectTarget(MBB) && + Op.getBlockAddress()->getBasicBlock() == MBB->getBasicBlock()) + llvm_unreachable( + "Removing MBB that's an indirect target of INLINEASM_BR"); +#endif MachineFunction *MF = MBB->getParent(); // drop all successors. diff --git a/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp b/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp --- a/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp @@ -1072,8 +1072,6 @@ CopyBB->normalizeSuccProbs(); BB->normalizeSuccProbs(); - BB->transferInlineAsmBrIndirectTargets(CopyBB); - InsertPos = CopyBB->end(); return CopyBB; }