-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[SimplifyCFG] Hoist common code when succ is unreachable block #165570
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
Changes from 3 commits
29e07b8
cc6ca09
779580a
4d51e3a
be325aa
ed38ae3
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 |
|---|---|---|
|
|
@@ -1866,10 +1866,19 @@ bool SimplifyCFGOpt::hoistCommonCodeFromSuccessors(Instruction *TI, | |
| // If either of the blocks has it's address taken, then we can't do this fold, | ||
| // because the code we'd hoist would no longer run when we jump into the block | ||
| // by it's address. | ||
| for (auto *Succ : successors(BB)) | ||
| if (Succ->hasAddressTaken() || !Succ->getSinglePredecessor()) | ||
| for (auto *Succ : successors(BB)) { | ||
| if (Succ->hasAddressTaken()) | ||
| return false; | ||
|
|
||
| if (Succ->getSinglePredecessor()) | ||
| continue; | ||
| // If Succ has >1 predecessors, continue to check if the Succ is terminated | ||
|
||
| // by an `unreachable` inst. Since executing `unreachable` inst is an UB, we | ||
| // can relax the condition based on the assumptiom that the program would | ||
| // never enter Succ and trigger an UB. | ||
| if (isa<UnreachableInst>(Succ->getTerminator())) | ||
|
||
| continue; | ||
| return false; | ||
| } | ||
| // The second of pair is a SkipFlags bitmask. | ||
| using SuccIterPair = std::pair<BasicBlock::iterator, unsigned>; | ||
| SmallVector<SuccIterPair, 8> SuccIterPairs; | ||
|
|
||
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.
Moreover, should us relax this condition to support mutl-cases destination in
switch?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.
This makes sense to me -- let's do it as a followup.