-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
[complier] bugfix, mergeConsecutiveBlocks pass, fix phi nodes of merging block's successor blocks #31940
[complier] bugfix, mergeConsecutiveBlocks pass, fix phi nodes of merging block's successor blocks #31940
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Hi @asmjmp0! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
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.
Thanks for the bug report and fix! To get this landed we need a fixture that reproduces the issue. Please add a test case in https://github.com/facebook/react/tree/main/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler and update snapshot fixtures. Make sure the test case fails without the fix (please include what the exact error was wo the fix, or what the incorrect output was).
This comment was marked as resolved.
This comment was marked as resolved.
because of these unreachable if statements that phi nodes with empty operands are generated. If these statements are removed, then it will be impossible to reproduce this bug. |
This comment was marked as resolved.
This comment was marked as resolved.
perhaps you need to assign an initial value to foo, because after constant propagation and unreachable statements removed, and the variable foo is not assigned a value but is directly returned. |
|
after review the case you said, I found that the core of the issue lies in the merge pass, which was not fixing the phi nodes of the successor blocks. This caused the constant propagation pass to mistakenly believe there were no predecessor blocks, leading to the deletion of operands. I have now resubmitted the code, passed the local test cases, could you please take another look? |
nice, now looks good to me too 🚀 |
Thank you for finding this bug! The fix here is subtle and i'm not sure exactly where the best place would be, but my instinct is that the fix should be in constant propagation. Also, as written this requires O(n^2) iterations over the blocks, which seems inefficient. Let me take a look. |
This is an optimized version of @asmjmp0's fix in facebook#31940. When we merge consecutive blocks we need to take care to rewrite later phis whose operands will now be different blocks due to merging. Rather than iterate all the blocks on each merge as in facebook#31940, we can do a single iteration over all the phis at the end to fix them up.
Ok I looked into it, and it does make sense to fix in MergeConsecutiveBlocks but we should iterate once. I put this up in #31959 |
Summary
test code:
after twice constant propagation, we can get the hir code, before invoke
eliminateRedundantPhi
method.we can see the phi node
<unknown> v3$58: phi()
with empty operands, which makeeliminateRedundantPhi
method error.so I remove the phi node with empty operands.
How did you test this change?
I run the command
yarn test
atcompiler
dictionary, and all tests passed.