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() &&
+                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.