diff options
author | Amara Emerson <amara@apple.com> | 2024-10-09 10:12:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-09 10:12:07 -0700 |
commit | 18d655fdcce4d17080e6cb2721f93f6db856277e (patch) | |
tree | 929c86f82852e15b9602fdfded13750ecc9729db /llvm/lib/Transforms/Utils/Local.cpp | |
parent | ec450b19004a653f3db3ad50e88fbf6529a9d841 (diff) | |
download | llvm-18d655fdcce4d17080e6cb2721f93f6db856277e.zip llvm-18d655fdcce4d17080e6cb2721f93f6db856277e.tar.gz llvm-18d655fdcce4d17080e6cb2721f93f6db856277e.tar.bz2 |
[SimplifyCFG][NFC] Improve compile time for TryToSimplifyUncondBranchFromEmptyBlock optimization. (#110715)
In some pathological cases this optimization can spend an unreasonable
amount of time populating the set for predecessors of the successor
block. This change sinks some of that initializing to the point where
it's actually necessary so we can take advantage of the existing
early-exits.
rdar://137063034
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index cfe40f9..f3b8623 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -1023,7 +1023,6 @@ static void replaceUndefValuesInPhi(PHINode *PN, static bool CanRedirectPredsOfEmptyBBToSucc(BasicBlock *BB, BasicBlock *Succ, const SmallPtrSetImpl<BasicBlock *> &BBPreds, - const SmallPtrSetImpl<BasicBlock *> &SuccPreds, BasicBlock *&CommonPred) { // There must be phis in BB, otherwise BB will be merged into Succ directly @@ -1042,7 +1041,7 @@ CanRedirectPredsOfEmptyBBToSucc(BasicBlock *BB, BasicBlock *Succ, // Get the single common predecessor of both BB and Succ. Return false // when there are more than one common predecessors. - for (BasicBlock *SuccPred : SuccPreds) { + for (BasicBlock *SuccPred : predecessors(Succ)) { if (BBPreds.count(SuccPred)) { if (CommonPred) return false; @@ -1166,7 +1165,6 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, return false; SmallPtrSet<BasicBlock *, 16> BBPreds(pred_begin(BB), pred_end(BB)); - SmallPtrSet<BasicBlock *, 16> SuccPreds(pred_begin(Succ), pred_end(Succ)); // The single common predecessor of BB and Succ when BB cannot be killed BasicBlock *CommonPred = nullptr; @@ -1175,9 +1173,8 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, // Even if we can not fold BB into Succ, we may be able to redirect the // predecessors of BB to Succ. - bool BBPhisMergeable = - BBKillable || - CanRedirectPredsOfEmptyBBToSucc(BB, Succ, BBPreds, SuccPreds, CommonPred); + bool BBPhisMergeable = BBKillable || CanRedirectPredsOfEmptyBBToSucc( + BB, Succ, BBPreds, CommonPred); if ((!BBKillable && !BBPhisMergeable) || introduceTooManyPhiEntries(BB, Succ)) return false; @@ -1302,7 +1299,7 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, // All predecessors of BB (except the common predecessor) will be moved to // Succ. Updates.reserve(Updates.size() + 2 * pred_size(BB) + 1); - + SmallPtrSet<BasicBlock *, 16> SuccPreds(pred_begin(Succ), pred_end(Succ)); for (auto *PredOfBB : predecessors(BB)) { // Do not modify those common predecessors of BB and Succ if (!SuccPreds.contains(PredOfBB)) |