mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user