Skip to content

[wasm-split] Remove dead globals#8505

Merged
aheejin merged 3 commits intoWebAssembly:mainfrom
aheejin:wasm_split_dead_global_fix
Mar 21, 2026
Merged

[wasm-split] Remove dead globals#8505
aheejin merged 3 commits intoWebAssembly:mainfrom
aheejin:wasm_split_dead_global_fix

Conversation

@aheejin
Copy link
Member

@aheejin aheejin commented Mar 21, 2026

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:

;; 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 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).

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 aheejin requested a review from tlively March 21, 2026 00:29
@aheejin aheejin requested a review from a team as a code owner March 21, 2026 00:29
@aheejin aheejin removed the request for review from a team March 21, 2026 00:30
Comment on lines +62 to +67
(drop
(global.get $glob1)
)
(drop
(global.get $glob2)
)
Copy link
Member Author

Choose a reason for hiding this comment

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

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

aheejin and others added 2 commits March 20, 2026 17:38
Co-authored-by: Thomas Lively <tlively123@gmail.com>
@aheejin aheejin merged commit 132f7e8 into WebAssembly:main Mar 21, 2026
16 checks passed
@aheejin aheejin deleted the wasm_split_dead_global_fix branch March 21, 2026 03:10
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