Skip to content

[semantic-arc] Invert a condition so that the early exit is first. #26958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions lib/SILOptimizer/Mandatory/SemanticARCOpts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,35 +74,37 @@ static bool isDeadLiveRange(
}

// Otherwise, see if we have a forwarding value that has a single
// non-trivial operand that can accept a guaranteed value. If so, at its
// users to the worklist and continue.
// non-trivial operand that can accept a guaranteed value. If not, we can
// not recursively process it, so be conservative and assume that we /may
// consume/ the value, so the live range must not be eliminated.
//
// DISCUSSION: For now we do not support forwarding instructions with
// multiple non-trivial arguments since we would need to optimize all of
// the non-trivial arguments at the same time.
//
// NOTE: Today we do not support TermInsts for simplicity... we /could/
// support it though if we need to.
if (forwardingInsts.isNonNull() && !isa<TermInst>(user) &&
isGuaranteedForwardingInst(user) &&
1 == count_if(user->getOperandValues(
if (forwardingInsts.isNull() || isa<TermInst>(user) ||
!isGuaranteedForwardingInst(user) ||
1 != count_if(user->getOperandValues(
true /*ignore type dependent operands*/),
[&](SILValue v) {
return v.getOwnershipKind() ==
ValueOwnershipKind::Owned;
})) {
forwardingInsts.get()->push_back(user);
for (SILValue v : user->getResults()) {
if (v.getOwnershipKind() != ValueOwnershipKind::Owned)
continue;
llvm::copy(v->getUses(), std::back_inserter(worklist));
}
continue;
return false;
}

// Otherwise be conservative and assume that we /may consume/ the value,
// so the live range must not be eliminated.
return false;
// Ok, this is a forwarding instruction whose ownership we can flip from
// owned -> guaranteed. Visit its users recursively to see if the the
// users force the live range to be alive.
forwardingInsts.get()->push_back(user);
for (SILValue v : user->getResults()) {
if (v.getOwnershipKind() != ValueOwnershipKind::Owned)
continue;
llvm::copy(v->getUses(), std::back_inserter(worklist));
}
continue;
}
case UseLifetimeConstraint::MustBeLive:
// Ok, this constraint can take something owned as live. Assert that it
Expand Down