Skip to content

Commit 4e56067

Browse files
fixup! respond to review
1 parent 2db9f00 commit 4e56067

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7463,19 +7463,26 @@ bool SimplifyCFGOpt::simplifyDuplicateSwitchArms(SwitchInst *SI) {
74637463
if (A->isConditional() != B->isConditional())
74647464
return false;
74657465

7466-
if (A->isConditional() && A->getCondition() != B->getCondition())
7467-
return false;
7466+
if (A->isConditional()) {
7467+
// If the conditions are instructions, check equality up to commutativity.
7468+
// Otherwise, check that the two Values are the same.
7469+
Value *AC = A->getCondition();
7470+
Value *BC = B->getCondition();
7471+
auto *ACI = dyn_cast<Instruction>(AC);
7472+
auto *BCI = dyn_cast<Instruction>(BC);
7473+
if ((ACI && BCI && !areIdenticalUpToCommutativity(ACI, BCI)) && AC != BC)
7474+
return false;
7475+
}
74687476

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

7472-
for (unsigned I = 0; I < A->getNumSuccessors(); ++I)
7473-
if (A->getSuccessor(I) != B->getSuccessor(I))
7480+
for (unsigned I = 0; I < A->getNumSuccessors(); ++I) {
7481+
BasicBlock *ASucc = A->getSuccessor(I);
7482+
if (ASucc != B->getSuccessor(I))
74747483
return false;
7475-
7476-
// Need to check that PHIs in sucessors have matching values
7477-
for (auto *Succ : A->successors()) {
7478-
for (PHINode &Phi : Succ->phis())
7484+
// Need to check that PHIs in sucessors have matching values
7485+
for (PHINode &Phi : ASucc->phis())
74797486
if (Phi.getIncomingValueForBlock(A->getParent()) !=
74807487
Phi.getIncomingValueForBlock(B->getParent()))
74817488
return false;

0 commit comments

Comments
 (0)