[move-only] Fix SILOptimizer code motion to preserve value deinits

Multiple code motion and ARC related passes were removing struct/enum
deinits.

Passes fixed include:
- SILCombine
- EarlyCodeMotion
- ReleaseHoisting
- *many* passes that rely on ARC analysis (RCIndentity)
This commit is contained in:
Andrew Trick
2023-06-05 17:31:33 -07:00
parent 85317c6e8f
commit 280761f0d1
8 changed files with 167 additions and 35 deletions

View File

@@ -564,6 +564,10 @@ bool BBEnumTagDataflowState::visitReleaseValueInst(ReleaseValueInst *RVI) {
if (FindResult == ValueToCaseMap.end())
return false;
// If the enum has a deinit, preserve the original release.
if (hasValueDeinit(RVI->getOperand()))
return false;
// If we do not have any argument, just delete the release value.
if (!(*FindResult)->second->hasAssociatedValues()) {
RVI->eraseFromParent();
@@ -621,6 +625,10 @@ bool BBEnumTagDataflowState::hoistDecrementsIntoSwitchRegions(
continue;
}
// If the enum has a deinit, preserve the original release.
if (hasValueDeinit(Op))
return false;
auto &EnumBBCaseList = (*R)->second;
// If we don't have an enum tag for each predecessor of this BB, bail since
// we do not know how to handle that BB.
@@ -1508,6 +1516,10 @@ static bool tryToSinkRefCountAcrossSwitch(SwitchEnumInst *Switch,
RCIA->getRCIdentityRoot(Switch->getOperand()))
return false;
// If the enum has a deinit, preserve the original release.
assert(!hasValueDeinit(Ptr) &&
"enum with deinit is not RC-identical to its payload");
// If S has a default case bail since the default case could represent
// multiple cases.
//
@@ -1578,6 +1590,10 @@ static bool tryToSinkRefCountAcrossSelectEnum(CondBranchInst *CondBr,
RCIA->getRCIdentityRoot(SEI->getEnumOperand()))
return false;
// If the enum has a deinit, preserve the original release.
assert(!hasValueDeinit(Ptr) &&
"enum with deinit is not RC-identical to its payload");
// Work out which enum element is the true branch, and which is false.
// If the enum only has 2 values and its tag isn't the true branch, then we
// know the true branch must be the other tag.