Skip to content

Fix mem2reg error due to multi block mem2reg with store_borrows #65367

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
Apr 22, 2023

Conversation

meg-gupta
Copy link
Contributor

@guaranteed stored values will never be added to a phi in mem2reg because any uses of store borrowed locations have to be accessed via the store borrow return address and since we ban address phis altogether we will never have input sil which necessitates this.

But, the DJ-edges based algorithm for inserting phi blocks in mem2reg can insert unnecessary phis which are removed later.

Ensure fixPhiPredBlock handles both owned and guaranteed stored values correctly for this reason.

…e_borrows

@guaranteed stored values will never be added to a phi in mem2reg because
any uses of store borrowed locations have to be accessed via the store borrow return address
and since we ban address phis altogether we will never have input sil which necessitates this.

But, the DJ-edges based algorithm for inserting phi blocks in mem2reg can insert unnecessary phis
which are removed later.

Ensure fixPhiPredBlock handles both owned and guaranteed stored values correctly for this reason.
@meg-gupta
Copy link
Contributor Author

@swift-ci test

Copy link
Contributor

@nate-chandler nate-chandler left a comment

Choose a reason for hiding this comment

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

LGTM

@nate-chandler
Copy link
Contributor

nate-chandler commented Apr 21, 2023

Incidentally, do these tests fail without this patch? I tried recent main, release/5.9, and release/5.8. Or is # 65345 needed to see them fail? (I haven't tried with that patch.)

@meg-gupta meg-gupta changed the title Fix ownership verification error due to multi block mem2reg with store_borrows Fix mem2reg error due to multi block mem2reg with store_borrows Apr 21, 2023
@meg-gupta
Copy link
Contributor Author

meg-gupta commented Apr 21, 2023

@nate-chandler It gets exposed as an assert with #65345. Without #65345 there is https://github.com/apple/swift/blob/1c3667b52aa7888f7e2cc253b725a7ed055e4ef2/lib/SILOptimizer/Transforms/SILMem2Reg.cpp#L1242 where LiveValues::forOwned is being called during creation even for @guaranteed stored values.

I haven't yet looked if doing https://github.com/apple/swift/blob/1c3667b52aa7888f7e2cc253b725a7ed055e4ef2/lib/SILOptimizer/Transforms/SILMem2Reg.cpp#L1242 unconditionally can have a different implication without #65345 or on 5.9

@nate-chandler
Copy link
Contributor

nate-chandler commented Apr 21, 2023

Yeah, https://github.com/apple/swift/blob/1c3667b52aa7888f7e2cc253b725a7ed055e4ef2/lib/SILOptimizer/Transforms/SILMem2Reg.cpp#L1242 needs this fix. Just asking about these test cases--looks like we get the same output with or without the fix (without # 65345).

@meg-gupta
Copy link
Contributor Author

@nate-chandler Yeah, I added this as a separate PR from #65345, because I thought the explanation deserved a new PR, but I guess it makes it unclear in a different way.

@nate-chandler
Copy link
Contributor

Thanks for the explanation!

@meg-gupta meg-gupta merged commit 8f99736 into swiftlang:main Apr 22, 2023
Copy link
Contributor

@atrick atrick 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.

3 participants