[wasm-split] Remove dead globals#8505
Merged
aheejin merged 3 commits intoWebAssembly:mainfrom Mar 21, 2026
Merged
Conversation
Currently dead module items are not split and just end up remaining in the primary module. Usually a user runs DCE before or after the splitting, and the goal of wasm-split is not DCE, so from the optimization perspective it shouldn't be a problem. But after WebAssembly#8441, this can be a problem because a dead global's initializer can refer to another global that is moved to a secondary module: ```wast ;; Primary (global.get $dead i32 (global.get $a)) ;; Secondary (global $a i32 (...)) ``` This PR just removes those dead globals. We leave it and do some post processing to make it work but that's more complicated, or we can move it to the same secondary module but this requires scanning of the reverse mapping. Removing it seems the simplest. We can remove those dead items for other module items (memories, tables, and tags) but they are not necessary for wasm-split to run, and they can be handled later in DCE. Fixes WebAssembly#8442 (comment).
aheejin
commented
Mar 21, 2026
Comment on lines
+62
to
+67
| (drop | ||
| (global.get $glob1) | ||
| ) | ||
| (drop | ||
| (global.get $glob2) | ||
| ) |
Member
Author
There was a problem hiding this comment.
After this PR, glob1 and glob2 are dead and the test doesn't do the intended testing anymore, so we use them here in the primary function
tlively
approved these changes
Mar 21, 2026
Co-authored-by: Thomas Lively <tlively123@gmail.com>
This file contains hidden or 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
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.
Currently dead module items are not split and just end up remaining in the primary module. Usually a user runs DCE before or after the splitting, and the goal of wasm-split is not DCE, so from the optimization perspective it shouldn't be a problem.
But after #8441, this can be a problem because a dead global's initializer can refer to another global that is moved to a secondary module:
This PR just removes those dead globals. We leave it and do some post processing to make it work but that's more complicated, or we can move it to the same secondary module but this requires scanning of the reverse mapping. Removing it seems the simplest. We can remove dead items for other module items (memories, tables, and tags) but it is not necessary for wasm-split to run, and they can be handled later in DCE.
Fixes #8442 (comment).