diff options
Diffstat (limited to 'llvm/lib/CodeGen/TailDuplicator.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/TailDuplicator.cpp | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/llvm/lib/CodeGen/TailDuplicator.cpp b/llvm/lib/CodeGen/TailDuplicator.cpp index c5fa4e6211a6..6c6d38462484 100644 --- a/llvm/lib/CodeGen/TailDuplicator.cpp +++ b/llvm/lib/CodeGen/TailDuplicator.cpp @@ -38,7 +38,6 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetMachine.h" -#include <algorithm> #include <cassert> #include <iterator> #include <utility> @@ -574,25 +573,15 @@ bool TailDuplicator::shouldTailDuplicate(bool IsSimple, if (TailBB.isSuccessor(&TailBB)) return false; - // Duplicating a BB which has both multiple predecessors and successors will - // result in a complex CFG and also may cause huge amount of PHI nodes. If we - // want to remove this limitation, we have to address - // https://github.com/llvm/llvm-project/issues/78578. - if (TailBB.pred_size() > TailDupPredSize && - TailBB.succ_size() > TailDupSuccSize) - return false; - // Set the limit on the cost to duplicate. When optimizing for size, // duplicate only one, because one branch instruction can be eliminated to // compensate for the duplication. unsigned MaxDuplicateCount; - bool OptForSize = MF->getFunction().hasOptSize() || - llvm::shouldOptimizeForSize(&TailBB, PSI, MBFI); if (TailDupSize == 0) MaxDuplicateCount = TailDuplicateSize; else MaxDuplicateCount = TailDupSize; - if (OptForSize) + if (llvm::shouldOptimizeForSize(&TailBB, PSI, MBFI)) MaxDuplicateCount = 1; // If the block to be duplicated ends in an unanalyzable fallthrough, don't @@ -621,6 +610,7 @@ bool TailDuplicator::shouldTailDuplicate(bool IsSimple, // Check the instructions in the block to determine whether tail-duplication // is invalid or unlikely to be profitable. unsigned InstrCount = 0; + unsigned NumPhis = 0; for (MachineInstr &MI : TailBB) { // Non-duplicable things shouldn't be tail-duplicated. // CFI instructions are marked as non-duplicable, because Darwin compact @@ -664,6 +654,20 @@ bool TailDuplicator::shouldTailDuplicate(bool IsSimple, if (InstrCount > MaxDuplicateCount) return false; + NumPhis += MI.isPHI(); + } + + // Duplicating a BB which has both multiple predecessors and successors will + // may cause huge amount of PHI nodes. If we want to remove this limitation, + // we have to address https://github.com/llvm/llvm-project/issues/78578. + if (TailBB.pred_size() > TailDupPredSize && + TailBB.succ_size() > TailDupSuccSize) { + // If TailBB or any of its successors contains a phi, we may have to add a + // large number of additional phis with additional incoming values. + if (NumPhis != 0 || any_of(TailBB.successors(), [](MachineBasicBlock *MBB) { + return any_of(*MBB, [](MachineInstr &MI) { return MI.isPHI(); }); + })) + return false; } // Check if any of the successors of TailBB has a PHI node in which the @@ -1071,10 +1075,10 @@ void TailDuplicator::removeDeadBlock( LLVM_DEBUG(dbgs() << "\nRemoving MBB: " << *MBB); MachineFunction *MF = MBB->getParent(); - // Update the call site info. + // Update the call info. for (const MachineInstr &MI : *MBB) - if (MI.shouldUpdateCallSiteInfo()) - MF->eraseCallSiteInfo(&MI); + if (MI.shouldUpdateAdditionalCallInfo()) + MF->eraseAdditionalCallInfo(&MI); if (RemovalCallback) (*RemovalCallback)(MBB); |
