-
Notifications
You must be signed in to change notification settings - Fork 45.7k
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
[compiler] Allow reordering of LoadLocal after their last assignment #29882
base: gh/josephsavona/30/base
Are you sure you want to change the base?
Conversation
[ghstack-poisoned]
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Comparing: 0f56841...b0643a2 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
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.
Not sure I understand the exact criteria that make a LoadLocal reorderable, can you explain the rationale here? See the inline comments for exactly what I'm confused about!
compiler/packages/babel-plugin-react-compiler/src/Optimization/InstructionReordering.ts
Outdated
Show resolved
Hide resolved
lastAssignment !== undefined && | ||
lastAssignment < instr.id && | ||
range !== undefined && | ||
range.end === range.start // this LoadLocal is used exactly once |
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.
I don't think I understand what the accessedRanges
conditions are enforcing here, or why it matters that a local is used exactly once. It seems like it would be safe to reorder a load to be anywhere between the last place that the local was written to (which this pass enforces) and the first place that the load's lvalue is read from -- which I would expect is enforced by the existing dependency analysis. I'm sure there's something I'm missing here though!
Also -- if the thing we want to validate is just that the local is used exactly once, maybe rather than building an accessed range for the local, we could just count the number of reads?
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.
Yeah i was on the fence about checking the accessed range or just counting reads. Without some form of this check i saw some cases where a LoadLocal was used twice, but once was at the wrong block scope level, so it would be invalid to reorder to the first usage. I'll update this to just count reads and only reorder for LoadLocals whose temp is used exactly once.
…assignment" [ghstack-poisoned]
…assignment" [ghstack-poisoned]
…assignment" [ghstack-poisoned]
Stack from ghstack (oldest at bottom):