@@ -7477,16 +7477,9 @@ bool SimplifyCFGOpt::simplifyDuplicateSwitchArms(SwitchInst *SI) {
74777477 if (A->getNumSuccessors () != B->getNumSuccessors ())
74787478 return false ;
74797479
7480- for (unsigned I = 0 ; I < A->getNumSuccessors (); ++I) {
7481- BasicBlock *ASucc = A->getSuccessor (I);
7482- if (ASucc != B->getSuccessor (I))
7480+ for (unsigned I = 0 ; I < A->getNumSuccessors (); ++I)
7481+ if (A->getSuccessor (I) != B->getSuccessor (I))
74837482 return false ;
7484- // Need to check that PHIs in sucessors have matching values
7485- for (PHINode &Phi : ASucc->phis ())
7486- if (Phi.getIncomingValueForBlock (A->getParent ()) !=
7487- Phi.getIncomingValueForBlock (B->getParent ()))
7488- return false ;
7489- }
74907483
74917484 return true ;
74927485 };
@@ -7497,8 +7490,17 @@ bool SimplifyCFGOpt::simplifyDuplicateSwitchArms(SwitchInst *SI) {
74977490 if (A->size () != 1 || B->size () != 1 )
74987491 return false ;
74997492
7500- return IsBranchEq (cast<BranchInst>(A->getTerminator ()),
7501- cast<BranchInst>(B->getTerminator ()));
7493+ if (!IsBranchEq (cast<BranchInst>(A->getTerminator ()),
7494+ cast<BranchInst>(B->getTerminator ())))
7495+ return false ;
7496+
7497+ // Need to check that PHIs in sucessors have matching values
7498+ for (auto *Succ : cast<BranchInst>(A->getTerminator ())->successors ())
7499+ for (PHINode &Phi : Succ->phis ())
7500+ if (Phi.getIncomingValueForBlock (A) != Phi.getIncomingValueForBlock (B))
7501+ return false ;
7502+
7503+ return true ;
75027504 };
75037505
75047506 // Construct a map from candidate basic block to an equivalent basic block
0 commit comments