Skip to content

Fix PMO to not scalarize empty tuple #59382

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
Jun 13, 2022
Merged

Conversation

meg-gupta
Copy link
Contributor

@meg-gupta meg-gupta commented Jun 11, 2022

Currently PMO tries to scalarize empty tuple, and ends up deleting
store of an empty tuple. This causes a cascade of problems.
Mem2Reg can end up seeing loads without stores of empty tuple type,
and creates undef while optimizing the alloca away.
This is bad, we don't want to create undef's unnecessarily in SIL.
Some optimization can query the function or the block on the undef leading to nullptr
and a compiler crash.

Fixes rdar://94829482

@meg-gupta meg-gupta requested a review from eeckstein June 11, 2022 16:50
@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta meg-gupta changed the title Fix Mem2Reg to avoid creating undef as a replacement for load of an empty tuple Fix PMO to not scalarize empty tuple Jun 12, 2022
@meg-gupta meg-gupta requested a review from gottesmm June 12, 2022 04:01
@meg-gupta
Copy link
Contributor Author

@swift-ci smoke test

@meg-gupta meg-gupta force-pushed the fixemptytuple branch 2 times, most recently from f73dc78 to 4bcd799 Compare June 12, 2022 05:14
Currently PMO tries to scalarize empty tuple, and ends up deleting
store of an empty tuple. This causes a cascade of problems.
Mem2Reg can end up seeing loads without stores of empty tuple type,
and creates undef while optimizing the alloca away.
This is bad, we don't want to create undef's unnecessarily in SIL.
Some optimization can queiry the function or the block on the undef leading to nullptr
and a compiler crash.

Fixes rdar://94829482
@atrick
Copy link
Contributor

atrick commented Jun 12, 2022

Are we now saying that an undef address is illegal SIL? I'm ok with that as long as the SIL verifier enforces it.

@meg-gupta
Copy link
Contributor Author

@atrick Maybe my PR description is misleading, I was trying to explain the sequence of problems that can happen.

This PR is just trying to avoid deleting stores while there maybe address reads. This part of PMO is replacing a store of a tuple, into stores of tuple elements. It ends up inadvertently deleting the store of an empty tuple (because it doesn't have any elements).

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

@meg-gupta
Copy link
Contributor Author

@swift-ci smoke test

@meg-gupta meg-gupta merged commit 4e2d41a into swiftlang:main Jun 13, 2022
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.

3 participants