Skip to content

Commit 173c010

Browse files
committed
[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.
1 parent 5d0bfee commit 173c010

File tree

4 files changed

+1723
-4
lines changed

4 files changed

+1723
-4
lines changed

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,15 +1028,20 @@ void StackAllocationPromoter::fixBranchesAndUses(BlockSetVector &phiBlocks,
10281028
}
10291029
// Go over all proactively added phis, and delete those that were not marked
10301030
// live above.
1031+
auto eraseLastPhiFromBlock = [](SILBasicBlock *block) {
1032+
auto *phi = cast<SILPhiArgument>(
1033+
block->getArgument(block->getNumArguments() - 1));
1034+
phi->replaceAllUsesWithUndef();
1035+
erasePhiArgument(block, block->getNumArguments() - 1);
1036+
};
10311037
for (auto *block : phiBlocks) {
10321038
auto *proactivePhi = cast<SILPhiArgument>(
10331039
block->getArgument(block->getNumArguments() - 1));
10341040
if (!livePhis.contains(proactivePhi)) {
1035-
proactivePhi->replaceAllUsesWithUndef();
1036-
erasePhiArgument(block, block->getNumArguments() - 1);
1041+
eraseLastPhiFromBlock(block);
10371042
if (shouldAddLexicalLifetime(asi)) {
1038-
erasePhiArgument(block, block->getNumArguments() - 1);
1039-
erasePhiArgument(block, block->getNumArguments() - 1);
1043+
eraseLastPhiFromBlock(block);
1044+
eraseLastPhiFromBlock(block);
10401045
}
10411046
} else {
10421047
phiBlocksOut.insert(block);

0 commit comments

Comments
 (0)