Skip to content

[Mem2Reg] When materializing an empty type projected from a non-empty aggregate, populate the non-empty fields of the aggregate with undef. #71521

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
merged 1 commit into from
Feb 12, 2024

Conversation

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Feb 9, 2024

Mem2Reg may materialize the unique instance of empty types when promoting an address of that empty type. Previously, it was required that the top-most type in the aggregate be empty. This failed to handle the case where a projection of empty type from a non-empty aggregate was promoted.

For example:

%addr = alloc_stack $((), C)
%empty_addr = tuple_element_addr $addr : $*((), C), 0
%addr = load %empty_addr : $*()

where C is some non-empty type.

Here, that case is handled by using undef for each non-empty field in the projected-from aggregate.

In the example,

%empty = tuple ()
%tuple = tuple (%empty : $(), undef : $C)
%empty_again = tuple_extract %tuple : $((), C), 0

rdar://122417297

Mem2Reg may materialize the unique instance of empty types when
promoting an address of that empty type.  Previously, it was required
that the top-most type in the aggregate be empty.  This failed to handle
the case where a projection of empty type from a non-empty aggregate was
promoted.

For example:

```
%addr = alloc_stack $((), C)
%empty_addr = tuple_element_addr $addr : $*((), C), 0
%addr = load %empty_addr : $*()
```

where `C` is some non-empty type.

Here, that case is handled by using `undef` for each non-empty field in
the projected-from aggregate.

In the example,

```
%empty = tuple ()
%tuple = tuple (%empty : $(), undef : $C)
%empty_again = tuple_extract %tuple : $((), C), 0
```

rdar://122417297
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler marked this pull request as ready for review February 10, 2024 20:53
Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants