From e3b557809604d036af6e00c60f012c2025b59a5e Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 11 Feb 2023 13:38:04 +0100 Subject: Vendor import of llvm-project main llvmorg-16-init-18548-gb0daacf58f41, the last commit before the upstream release/17.x branch was created. --- llvm/lib/CodeGen/TailDuplicator.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'llvm/lib/CodeGen/TailDuplicator.cpp') diff --git a/llvm/lib/CodeGen/TailDuplicator.cpp b/llvm/lib/CodeGen/TailDuplicator.cpp index 18507b8fa84f..865add28f781 100644 --- a/llvm/lib/CodeGen/TailDuplicator.cpp +++ b/llvm/lib/CodeGen/TailDuplicator.cpp @@ -370,8 +370,10 @@ void TailDuplicator::processPHI( // Remove PredBB from the PHI node. MI->removeOperand(SrcOpIdx + 1); MI->removeOperand(SrcOpIdx); - if (MI->getNumOperands() == 1) + if (MI->getNumOperands() == 1 && !TailBB->hasAddressTaken()) MI->eraseFromParent(); + else if (MI->getNumOperands() == 1) + MI->setDesc(TII->get(TargetOpcode::IMPLICIT_DEF)); } /// Duplicate a TailBB instruction to PredBB and update @@ -395,7 +397,7 @@ void TailDuplicator::duplicateInstruction( if (!MO.isReg()) continue; Register Reg = MO.getReg(); - if (!Register::isVirtualRegister(Reg)) + if (!Reg.isVirtual()) continue; if (MO.isDef()) { const TargetRegisterClass *RC = MRI->getRegClass(Reg); @@ -716,8 +718,7 @@ bool TailDuplicator::canCompletelyDuplicateBB(MachineBasicBlock &BB) { bool TailDuplicator::duplicateSimpleBB( MachineBasicBlock *TailBB, SmallVectorImpl &TDBBs, - const DenseSet &UsedByPhi, - SmallVectorImpl &Copies) { + const DenseSet &UsedByPhi) { SmallPtrSet Succs(TailBB->succ_begin(), TailBB->succ_end()); SmallVector Preds(TailBB->predecessors()); @@ -799,6 +800,15 @@ bool TailDuplicator::canTailDuplicate(MachineBasicBlock *TailBB, return false; if (!PredCond.empty()) return false; + // FIXME: This is overly conservative; it may be ok to relax this in the + // future under more specific conditions. If TailBB is an INLINEASM_BR + // indirect target, we need to see if the edge from PredBB to TailBB is from + // an INLINEASM_BR in PredBB, and then also if that edge was from the + // indirect target list, fallthrough/default target, or potentially both. If + // it's both, TailDuplicator::tailDuplicate will remove the edge, corrupting + // the successor list in PredBB and predecessor list in TailBB. + if (TailBB->isInlineAsmBrIndirectTarget()) + return false; return true; } @@ -826,7 +836,7 @@ bool TailDuplicator::tailDuplicate(bool IsSimple, MachineBasicBlock *TailBB, getRegsUsedByPHIs(*TailBB, &UsedByPhi); if (IsSimple) - return duplicateSimpleBB(TailBB, TDBBs, UsedByPhi, Copies); + return duplicateSimpleBB(TailBB, TDBBs, UsedByPhi); // Iterate through all the unique predecessors and tail-duplicate this // block into them, if possible. Copying the list ahead of time also -- cgit v1.2.3