Skip to content

[semantic-arc-opts] When looking for consuming uses, do not add trivi… #23708

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
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions lib/SILOptimizer/Mandatory/SemanticARCOpts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ static bool isConsumed(
})) {
forwardingInsts.get()->push_back(user);
for (SILValue v : user->getResults()) {
if (v.getOwnershipKind() != ValueOwnershipKind::Owned)
continue;
copy(v->getUses(), std::back_inserter(worklist));
}
continue;
Expand Down
17 changes: 17 additions & 0 deletions test/SILOptimizer/semantic-arc-opts.sil
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ struct NativeObjectPair {

class Klass {}

struct MyInt {
var value: Builtin.Int32
}

struct AnotherStruct {
var i : Builtin.Int32
var c : Klass
Expand Down Expand Up @@ -378,3 +382,16 @@ bb3:
%9999 = tuple()
return %9999 : $()
}

// CHECK-LABEL: sil [ossa] @do_not_add_trivial_users_of_owned_values_to_isconsumed_worklist : $@convention(thin) (@guaranteed (Klass, MyInt)) -> Builtin.Int32 {
// CHECK-NOT: copy_value
// CHECK-NOT: destroy_value
// CHECK: } // end sil function 'do_not_add_trivial_users_of_owned_values_to_isconsumed_worklist'
sil [ossa] @do_not_add_trivial_users_of_owned_values_to_isconsumed_worklist : $@convention(thin) (@guaranteed (Klass, MyInt)) -> Builtin.Int32 {
bb0(%0 : @guaranteed $(Klass, MyInt)):
%1 = copy_value %0 : $(Klass, MyInt)
(%2, %3) = destructure_tuple %1 : $(Klass, MyInt)
%4 = struct_extract %3 : $MyInt, #MyInt.value
destroy_value %2 : $Klass
return %4 : $Builtin.Int32
}