[Instruction] Speculatively undo isIdenticalToWhenDefined() PHI handling changes

The stage2-stage3 differences persist even without instcombine-based
PHI CSE, so this is the only possible reason.
This commit is contained in:
Roman Lebedev 2020-08-29 19:38:33 +03:00
parent 0965272140
commit 5ec2b757cc
No known key found for this signature in database
GPG Key ID: 083C3EBB4A1689E0
2 changed files with 9 additions and 22 deletions

View File

@ -483,33 +483,18 @@ bool Instruction::isIdenticalToWhenDefined(const Instruction *I) const {
if (getNumOperands() == 0 && I->getNumOperands() == 0)
return haveSameSpecialState(this, I);
// PHI nodes are special.
if (const PHINode *thisPHI = dyn_cast<PHINode>(this)) {
const PHINode *otherPHI = cast<PHINode>(I);
// PHI nodes don't necessarily have their operands in the same order,
// so we shouldn't just compare ranges of incoming blocks/values.
// If both PHI's are in the same basic block, which is the most interesting
// case, we know they must have identical predecessor list,
// so we only need to check the incoming values.
if (thisPHI->getParent() == otherPHI->getParent()) {
return all_of(thisPHI->blocks(), [thisPHI, otherPHI](BasicBlock *PredBB) {
return thisPHI->getIncomingValueForBlock(PredBB) ==
otherPHI->getIncomingValueForBlock(PredBB);
});
}
// Otherwise, let's just naively compare operands/blocks.
return std::equal(op_begin(), op_end(), I->op_begin()) &&
std::equal(thisPHI->block_begin(), thisPHI->block_end(),
otherPHI->block_begin());
}
// We have two instructions of identical opcode and #operands. Check to see
// if all operands are the same.
if (!std::equal(op_begin(), op_end(), I->op_begin()))
return false;
// WARNING: this logic must be kept in sync with EliminateDuplicatePHINodes()!
if (const PHINode *thisPHI = dyn_cast<PHINode>(this)) {
const PHINode *otherPHI = cast<PHINode>(I);
return std::equal(thisPHI->block_begin(), thisPHI->block_end(),
otherPHI->block_begin());
}
return haveSameSpecialState(this, I);
}

View File

@ -1117,6 +1117,8 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
return true;
}
// WARNING: this logic must be kept in sync with
// Instruction::isIdenticalToWhenDefined()!
bool llvm::EliminateDuplicatePHINodes(BasicBlock *BB) {
// This implementation doesn't currently consider undef operands
// specially. Theoretically, two phis which are identical except for