[llvm] [CFG] Avoid introducing complex phi when removing empty blocks (PR #104887)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 20 00:59:42 PDT 2024
================
@@ -1040,6 +1045,42 @@ CanRedirectPredsOfEmptyBBToSucc(BasicBlock *BB, BasicBlock *Succ,
return true;
}
+// Check whether removing BB will make the phis in its Succ will have too
+// many incoming entries. This function does not check whether BB is foldable
+// or not.
+static bool introduceTooComplexPhi(BasicBlock *BB) {
+ // Check BB only has phi and an unconditional branch
+ BranchInst *Branch = dyn_cast<BranchInst>(BB->getFirstNonPHIOrDbg(true));
+ assert(Branch && Branch->isUnconditional() && "BB is not an empty block");
----------------
nikic wrote:
Branch is unused outside the assertion, and getFirstNonPHIOrDbg() may be expensive.
I think it would be better to pass in BasicBlock *Succ to this function, like many other parts of this transform. The fact that it's an empty block with single successor is verified elsewhere.
https://github.com/llvm/llvm-project/pull/104887
More information about the llvm-commits
mailing list