[llvm] [SimplifyCFG] Avoid increasing too many phi entries when removing empty blocks (PR #104887)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 19 22:09:59 PDT 2024
================
@@ -1047,6 +1053,34 @@ CanRedirectPredsOfEmptyBBToSucc(BasicBlock *BB, BasicBlock *Succ,
return true;
}
+// Check whether removing BB will make the phis in its Succ have too
+// many incoming entries. This function does not check whether BB is foldable
+// or not.
+static bool introduceTooManyPhiEntries(BasicBlock *BB, BasicBlock *Succ) {
+ // If BB only has one predecessor, then removing it will not introduce more
+ // incoming edges for phis.
+ if (BB->hasNPredecessors(1))
+ return false;
+ unsigned NumPreds = pred_size(BB);
+ unsigned NumChangedPhi = 0;
+ for (auto &Phi : Succ->phis()) {
+ // If the incoming value is a phi and the phi is defined in BB,
+ // then removing BB will not increase the total phi entries of the ir.
+ if (PHINode *IncomingPhi =
----------------
dtcxzyw wrote:
Missing test for this case.
https://github.com/llvm/llvm-project/pull/104887
More information about the llvm-commits
mailing list