-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[SimplifyCFG][NFC] Improve compile time for TryToSimplifyUncondBranchFromEmptyBlock optimization. #110715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SimplifyCFG][NFC] Improve compile time for TryToSimplifyUncondBranchFromEmptyBlock optimization. #110715
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1020,10 +1020,11 @@ static void replaceUndefValuesInPhi(PHINode *PN, | |
| // Only when they shares a single common predecessor, return true. | ||
| // Only handles cases when BB can't be merged while its predecessors can be | ||
| // redirected. | ||
| // \p SuccPredsOut may be partially populated with the predecessors of Succ. | ||
| static bool | ||
| CanRedirectPredsOfEmptyBBToSucc(BasicBlock *BB, BasicBlock *Succ, | ||
| const SmallPtrSetImpl<BasicBlock *> &BBPreds, | ||
| const SmallPtrSetImpl<BasicBlock *> &SuccPreds, | ||
| SmallPtrSetImpl<BasicBlock *> &SuccPredsOut, | ||
| BasicBlock *&CommonPred) { | ||
|
|
||
| // There must be phis in BB, otherwise BB will be merged into Succ directly | ||
|
|
@@ -1042,7 +1043,8 @@ 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)) { | ||
| SuccPredsOut.insert(SuccPred); | ||
| if (BBPreds.count(SuccPred)) { | ||
| if (CommonPred) | ||
| return false; | ||
|
|
@@ -1166,7 +1168,7 @@ 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)); | ||
| SmallPtrSet<BasicBlock *, 16> SuccPreds; | ||
|
|
||
| // The single common predecessor of BB and Succ when BB cannot be killed | ||
| BasicBlock *CommonPred = nullptr; | ||
|
|
@@ -1182,6 +1184,10 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, | |
| if ((!BBKillable && !BBPhisMergeable) || introduceTooManyPhiEntries(BB, Succ)) | ||
| return false; | ||
|
|
||
| // SuccPreds may not have been fully filled by CanRedirectPredsOfEmptyBBToSucc | ||
| // so finish it here. | ||
| SuccPreds.insert(pred_begin(Succ), pred_end(Succ)); | ||
|
||
|
|
||
| // Check to see if merging these blocks/phis would cause conflicts for any of | ||
| // the phi nodes in BB or Succ. If not, we can safely merge. | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which part is important to short-circuit in your case? Is it the checks above or the check in this loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it was the checks in this loop.