-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
[WIP] Trying to make ternaries do constant propagation #32222
Open
elicwhite
wants to merge
10
commits into
facebook:main
Choose a base branch
from
elicwhite:constant-propagation-ternary
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Comment on lines
193
to
194
fn.body.blocks.get(branchBlock.terminal.consequent)!.kind = 'block'; | ||
fn.body.blocks.get(branchBlock.terminal.alternate)!.kind = 'block'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes that the consequent block doesn't have further nested value blocks "within" it, which would also need to be converted to value blocks. Simplest thing to do is to add a check that the target block ends with a goto to the fallthrough of the outer ternary
196c40b
to
fdfa7a6
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Some basic constant propagation for ternaries.
This has a feature flag, currently disabled.
This change, even when the flag is turned off, does double the number of iterations that needs to be taken through the blocks in the file.
The previous logic was to detect all the local values within the current block (storing in constants), and if you get to an if statement, and that test is in your lookup, use it.
However, with ternaries, the test is in a different block that follows the if statement so it's not clear to me if you can do the single for loop with instructions and blocks together.
Now, it iterates through all the blocks and stores the constants, then iterates over the blocks again to try to inline.
This doesn't seem great, I'm curious if there is a better approach.
How did you test this change?
Jest with the flag disabled, only enabled for the single test. When the flag is enabled globally, there are some other cases it fails on that need to be addressed.
Playground: https://react-compiler-playground-git-fork-elicwhit-fcc939-fbopensource.vercel.app