[llvm] [ControlFlowHub] Fix duplicate DomTree updates when branch successors are identical (PR #176620)
Shilei Tian via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 18 13:05:00 PST 2026
================
@@ -248,6 +250,11 @@ static void reconnectPhis(BasicBlock *Out, BasicBlock *GuardBlock,
Value *V = PoisonValue::get(Phi->getType());
if (Phi->getBasicBlockIndex(BB) != -1) {
V = Phi->removeIncomingValue(BB, false);
+ // When both successors are the same (Succ0 == Succ1), there are two
+ // edges from BB to Out, so we need to remove the second PHI entry too.
+ if (Succ0 && Succ1 && Succ0 == Succ1 &&
+ Phi->getBasicBlockIndex(BB) != -1)
+ Phi->removeIncomingValue(BB, false);
----------------
shiltian wrote:
Yup, the `Phi` here can have two identical incoming BB and value, since it is a list not a set. I was thinking about using a set for phi node in the past for a separate issue, but that change is too intrusive, and I might miss some design choice and history here.
https://github.com/llvm/llvm-project/pull/176620
More information about the llvm-commits
mailing list