Skip to content

Commit

Permalink
fixup! respond to review
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmaitland committed Oct 30, 2024
1 parent 2db9f00 commit 4e56067
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7463,19 +7463,26 @@ bool SimplifyCFGOpt::simplifyDuplicateSwitchArms(SwitchInst *SI) {
if (A->isConditional() != B->isConditional())
return false;

if (A->isConditional() && A->getCondition() != B->getCondition())
return false;
if (A->isConditional()) {
// If the conditions are instructions, check equality up to commutativity.
// Otherwise, check that the two Values are the same.
Value *AC = A->getCondition();
Value *BC = B->getCondition();
auto *ACI = dyn_cast<Instruction>(AC);
auto *BCI = dyn_cast<Instruction>(BC);
if ((ACI && BCI && !areIdenticalUpToCommutativity(ACI, BCI)) && AC != BC)
return false;
}

if (A->getNumSuccessors() != B->getNumSuccessors())
return false;

for (unsigned I = 0; I < A->getNumSuccessors(); ++I)
if (A->getSuccessor(I) != B->getSuccessor(I))
for (unsigned I = 0; I < A->getNumSuccessors(); ++I) {
BasicBlock *ASucc = A->getSuccessor(I);
if (ASucc != B->getSuccessor(I))
return false;

// Need to check that PHIs in sucessors have matching values
for (auto *Succ : A->successors()) {
for (PHINode &Phi : Succ->phis())
// Need to check that PHIs in sucessors have matching values
for (PHINode &Phi : ASucc->phis())
if (Phi.getIncomingValueForBlock(A->getParent()) !=
Phi.getIncomingValueForBlock(B->getParent()))
return false;
Expand Down

0 comments on commit 4e56067

Please sign in to comment.