[Mem2Reg] RAUW undef lexical lifetime phis.

Previously, if it was determined that a proactive phi was unnecessary,
it was removed, along with the phis for the lifetime and the original
value of which the proactive phi was a copy.  The uses of only one of
the three phis (namely, the proactive phi) was RAUW undef.  In the case
where the only usage of the phi was to branch back to the block that
took the phi as an argument, that was a problem.  Here, that is fixed by
giving all three phis the same treatment.  To avoid duplicating code,
that treatment is pulled out into a new lambda.

This was exposed by adding lifetime versions of some OSSA versions of
mem2reg tests that had been missed previously.
This commit is contained in:
Nate Chandler
2021-10-20 11:25:04 -07:00
parent 5d0bfeec17
commit 173c010faa
4 changed files with 1723 additions and 4 deletions

View File

@@ -1028,15 +1028,20 @@ void StackAllocationPromoter::fixBranchesAndUses(BlockSetVector &phiBlocks,
}
// Go over all proactively added phis, and delete those that were not marked
// live above.
auto eraseLastPhiFromBlock = [](SILBasicBlock *block) {
auto *phi = cast<SILPhiArgument>(
block->getArgument(block->getNumArguments() - 1));
phi->replaceAllUsesWithUndef();
erasePhiArgument(block, block->getNumArguments() - 1);
};
for (auto *block : phiBlocks) {
auto *proactivePhi = cast<SILPhiArgument>(
block->getArgument(block->getNumArguments() - 1));
if (!livePhis.contains(proactivePhi)) {
proactivePhi->replaceAllUsesWithUndef();
erasePhiArgument(block, block->getNumArguments() - 1);
eraseLastPhiFromBlock(block);
if (shouldAddLexicalLifetime(asi)) {
erasePhiArgument(block, block->getNumArguments() - 1);
erasePhiArgument(block, block->getNumArguments() - 1);
eraseLastPhiFromBlock(block);
eraseLastPhiFromBlock(block);
}
} else {
phiBlocksOut.insert(block);