Skip to content

GlobalStructInference: Handle nested optimizable global.gets#8019

Merged
kripken merged 1 commit into
WebAssembly:mainfrom
kripken:gsi.nested
Nov 3, 2025
Merged

GlobalStructInference: Handle nested optimizable global.gets#8019
kripken merged 1 commit into
WebAssembly:mainfrom
kripken:gsi.nested

Conversation

@kripken
Copy link
Copy Markdown
Member

@kripken kripken commented Nov 3, 2025

When we un-nest, temporarily there is a global.get of a global we have not
yet created. Mark those so we don't read them and get confused.

@kripken kripken requested a review from tlively November 3, 2025 21:54
@kripken
Copy link
Copy Markdown
Member Author

kripken commented Nov 3, 2025

(diff without whitespace is smaller)

Comment thread test/lit/passes/gsi-nontype.wast
;; CHECK-NEXT: )
(func $caller (result anyref)
(call_ref $func
;; TODO: If we did two passes, we could optimize this one too.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why doesn't this get optimized via un-nesting as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It would just take another pass. Maybe worth it as the TODO says.

(We could do it in a single pass with more complexity, or if we traversed in the other direction, in theory...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, we can only do one level of un-nesting per pass because we're function-parallel and therefore cannot actually install the un-nested globals before we move on to the parent? That seems worth fixing! There's no reason why the globals wouldn't have very deep initialization trees, and we don't want to have to run this pass many times to fully optimize them.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, it does seem worth fixing. We could perhaps just take a lock around global creation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Or maintain a per-function set of un-nested globals (with deterministic names) to be de-duplicated at the module level afterward.

Copy link
Copy Markdown
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

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

This change lgtm, though.

@kripken kripken merged commit f23ae35 into WebAssembly:main Nov 3, 2025
16 checks passed
@kripken kripken deleted the gsi.nested branch November 3, 2025 23:57
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