aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/IfConversion.cpp
diff options
context:
space:
mode:
authorNick Desaulniers <ndesaulniers@google.com>2023-02-07 10:22:24 -0800
committerNick Desaulniers <ndesaulniers@google.com>2023-02-07 10:28:11 -0800
commit07c7784d7bf69b9944b92ecc283cac823bcfce16 (patch)
tree980a76ec34382f3623d515505f95d3766ff49ac4 /llvm/lib/CodeGen/IfConversion.cpp
parent1cecfa407c1a1a114d75c8b85fbe97e4c1275c1f (diff)
downloadllvm-07c7784d7bf69b9944b92ecc283cac823bcfce16.zip
llvm-07c7784d7bf69b9944b92ecc283cac823bcfce16.tar.gz
llvm-07c7784d7bf69b9944b92ecc283cac823bcfce16.tar.bz2
[llvm][IfConversion] update successor list when merging INLINEASM_BR
If this successor list is not correct, then branch-folding may incorrectly think that the indirect target is dead and remove it. This results in a dangling reference to the removed block as an operand to the INLINEASM_BR, which later will get AsmPrinted into code that doesn't assemble. This was made more obvious by, but is not a regression of https://reviews.llvm.org/D130316. Fixes: https://github.com/llvm/llvm-project/issues/60346 Reviewed By: efriedma, void Differential Revision: https://reviews.llvm.org/D142924
Diffstat (limited to 'llvm/lib/CodeGen/IfConversion.cpp')
-rw-r--r--llvm/lib/CodeGen/IfConversion.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/IfConversion.cpp b/llvm/lib/CodeGen/IfConversion.cpp
index 105ab90..936de31 100644
--- a/llvm/lib/CodeGen/IfConversion.cpp
+++ b/llvm/lib/CodeGen/IfConversion.cpp
@@ -2244,6 +2244,15 @@ void IfConverter::MergeBlocks(BBInfo &ToBBI, BBInfo &FromBBI, bool AddEdges) {
assert(!FromMBB.hasAddressTaken() &&
"Removing a BB whose address is taken!");
+ // If we're about to splice an INLINEASM_BR from FromBBI, we need to update
+ // ToBBI's successor list accordingly.
+ if (FromMBB.mayHaveInlineAsmBr())
+ for (MachineInstr &MI : FromMBB)
+ if (MI.getOpcode() == TargetOpcode::INLINEASM_BR)
+ for (MachineOperand &MO : MI.operands())
+ if (MO.isMBB() && !ToBBI.BB->isSuccessor(MO.getMBB()))
+ ToBBI.BB->addSuccessor(MO.getMBB(), BranchProbability::getZero());
+
// In case FromMBB contains terminators (e.g. return instruction),
// first move the non-terminator instructions, then the terminators.
MachineBasicBlock::iterator FromTI = FromMBB.getFirstTerminator();