[PATCH] D78234: [BranchFolding] assert when removing INLINEASM_BR indirect targets
Nick Desaulniers via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 16 13:23:49 PDT 2020
nickdesaulniers updated this revision to Diff 258154.
nickdesaulniers marked 6 inline comments as done.
nickdesaulniers added a comment.
Herald added a subscriber: MatzeB.
- delete transferInlineAsmBrIndirectTargets so that we can use isInlineAsmBrIndirectTarget correctly.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D78234/new/
https://reviews.llvm.org/D78234
Files:
llvm/include/llvm/CodeGen/MachineBasicBlock.h
llvm/lib/CodeGen/BranchFolding.cpp
llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
Index: llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
+++ llvm/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp
@@ -1072,8 +1072,6 @@
CopyBB->normalizeSuccProbs();
BB->normalizeSuccProbs();
- BB->transferInlineAsmBrIndirectTargets(CopyBB);
-
InsertPos = CopyBB->end();
return CopyBB;
}
Index: llvm/lib/CodeGen/BranchFolding.cpp
===================================================================
--- llvm/lib/CodeGen/BranchFolding.cpp
+++ 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.
Index: llvm/include/llvm/CodeGen/MachineBasicBlock.h
===================================================================
--- llvm/include/llvm/CodeGen/MachineBasicBlock.h
+++ 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78234.258154.patch
Type: text/x-patch
Size: 2697 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200416/b53298c2/attachment.bin>
More information about the llvm-commits
mailing list