Skip to content

Commit bcf93c6

Browse files
authored
Merge pull request #26958 from gottesmm/pr-266cfd499d8b73f2e36fbf2ce23b72aa89097910
[semantic-arc] Invert a condition so that the early exit is first.
2 parents 7ce3553 + eb4d0ee commit bcf93c6

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

lib/SILOptimizer/Mandatory/SemanticARCOpts.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,35 +74,37 @@ static bool isDeadLiveRange(
7474
}
7575

7676
// Otherwise, see if we have a forwarding value that has a single
77-
// non-trivial operand that can accept a guaranteed value. If so, at its
78-
// users to the worklist and continue.
77+
// non-trivial operand that can accept a guaranteed value. If not, we can
78+
// not recursively process it, so be conservative and assume that we /may
79+
// consume/ the value, so the live range must not be eliminated.
7980
//
8081
// DISCUSSION: For now we do not support forwarding instructions with
8182
// multiple non-trivial arguments since we would need to optimize all of
8283
// the non-trivial arguments at the same time.
8384
//
8485
// NOTE: Today we do not support TermInsts for simplicity... we /could/
8586
// support it though if we need to.
86-
if (forwardingInsts.isNonNull() && !isa<TermInst>(user) &&
87-
isGuaranteedForwardingInst(user) &&
88-
1 == count_if(user->getOperandValues(
87+
if (forwardingInsts.isNull() || isa<TermInst>(user) ||
88+
!isGuaranteedForwardingInst(user) ||
89+
1 != count_if(user->getOperandValues(
8990
true /*ignore type dependent operands*/),
9091
[&](SILValue v) {
9192
return v.getOwnershipKind() ==
9293
ValueOwnershipKind::Owned;
9394
})) {
94-
forwardingInsts.get()->push_back(user);
95-
for (SILValue v : user->getResults()) {
96-
if (v.getOwnershipKind() != ValueOwnershipKind::Owned)
97-
continue;
98-
llvm::copy(v->getUses(), std::back_inserter(worklist));
99-
}
100-
continue;
95+
return false;
10196
}
10297

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

0 commit comments

Comments
 (0)