Skip to content

Enable store elimination of enums with uses in multiple blocks #65167

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 17, 2023

Conversation

meg-gupta
Copy link
Contributor

Previously this was disabled, because address with enum types can have incomplete lifetimes on none/trivial paths and on conversion to value form can raise verification errors.

With this change, the optimization is enabled when we have stores with non-lexical source. Lifetime completion utility is used to complete the lifetimes and avoid any verification errors.

@meg-gupta
Copy link
Contributor Author

@swift-ci test

1 similar comment
@meg-gupta
Copy link
Contributor Author

@swift-ci test

@meg-gupta meg-gupta merged commit 38dcfec into swiftlang:main Apr 17, 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.

Cool!

A couple ways we should think about improving this:

  1. handle lexical values

    The lifetime completion utility could be extended to handle lexical values whenever we can guarantee that the value is trivial on any paths where the value isn't consumes. So, in this case, you don't need the isLexical special case.

  2. don't recompute dominance

    Unfortunately, SIL-level dominance is not usually available in the optimization pipeline. Instead, SSA update for SIL actually computes a separate LLVM-level dominance, which we don't get to reuse! Terrible compiler design, but it's what we have.

    Since TempRValue is supposed to be a "peephole pass" that doesn't require global analysis, we should remove the dependence on dominance. The only reason the lifetime computation needs dominance is to detect ahead of time that an enclosing phi already exists. Currently, lifetime completion doesn't do anything with unenclosed phis except assert. See the TODO in OSSALifetimeCompletion::analyzeAndUpdateLifetime. That needs to be fixed anyway if the utility ever runs after guaranteed phis are created. Once that is fixed, we can also check for redundant phis (updateSSA might already do this well enough). By detecting redundant phis during creation, we're immune to extra "unenclosedPhi" entries. So we don't need to pass dominance to the completion utility.

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