diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:04 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-02-11 12:38:11 +0000 |
commit | e3b557809604d036af6e00c60f012c2025b59a5e (patch) | |
tree | 8a11ba2269a3b669601e2fd41145b174008f4da8 /llvm/lib/CodeGen/TailDuplicator.cpp | |
parent | 08e8dd7b9db7bb4a9de26d44c1cbfd24e869c014 (diff) |
Diffstat (limited to 'llvm/lib/CodeGen/TailDuplicator.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TailDuplicator.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
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<MachineBasicBlock *> &TDBBs, - const DenseSet<Register> &UsedByPhi, - SmallVectorImpl<MachineInstr *> &Copies) { + const DenseSet<Register> &UsedByPhi) { SmallPtrSet<MachineBasicBlock *, 8> Succs(TailBB->succ_begin(), TailBB->succ_end()); SmallVector<MachineBasicBlock *, 8> 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 |