Skip to content

Commit 713f9b7

Browse files
Merge pull request swiftlang#39839 from nate-chandler/lexical_lifetimes/rauw-all-three-phis-if-proactive-phi-is-unnecessary
[Mem2Reg] RAUW undef lexical lifetime phis.
2 parents e2c3089 + 173c010 commit 713f9b7

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)