Skip to content

wasm: recompute mir_uavs after Mir.Optimize to prune dead constants - #140

Merged
cataggar merged 1 commit into
wazigfrom
wasm-prune-uavs-110
Nov 4, 2026
Merged

cataggar merged 1 commit into
wazigfrom
wasm-prune-uavs-110

Conversation

@cataggar

@cataggar cataggar commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Summary

  • Rebuild cg.mir_uavs in src/codegen/wasm/CodeGen.zig (generateInner) after Mir.Optimize.optimize by scanning surviving .uav_ref (data.ip_index) and .uav_ref_off (@fromBackingInt(cg.mir_extra.items[data.payload])) instructions while preserving each surviving UAV's computed Alignment.
  • Extend src/codegen/wasm/Optimize.zig to recognize pointer/reference constants (.uav_ref, .uav_ref_off, .nav_ref, .nav_ref_off, .func_ref, .tls_nav_ref, .error_name_table_ref, .enum_tag_name_table_ref) and .errors_len across .drop, constant .select, and dead .local_set elimination, and sink numeric constants across empty .block headers and local_tee branch conditions so folded runtime conditions prune dead branches end-to-end.
  • Add unit tests in src/codegen/wasm/Optimize.zig and a Wasm behavior test in test/behavior/wasm.zig.

Closes #110

@cataggar
cataggar enabled auto-merge (squash) November 4, 2026 15:16
Rebuild cg.mir_uavs from surviving .uav_ref and .uav_ref_off instructions
after Mir.Optimize.optimize runs in CodeGen.generateInner, preserving each
surviving UAV's computed alignment so dead UAVs do not get lowered or
allocated in the Wasm data section.

Extend Mir.Optimize to recognize pointer/reference constants (.uav_ref,
.uav_ref_off, .nav_ref, .nav_ref_off, .func_ref, .tls_nav_ref,
.error_name_table_ref, .enum_tag_name_table_ref) and .errors_len across
drop, constant select, and dead local_set elimination, and sink numeric
constants across empty block headers and local_tee branch conditions so
folded runtime conditions prune dead branches end-to-end.

Closes #110

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@cataggar
cataggar merged commit 60a4c99 into wazig Nov 4, 2026
2 checks passed
@cataggar
cataggar deleted the wasm-prune-uavs-110 branch November 4, 2026 15:26
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.

wasm: recompute mir_uavs after Mir.Optimize to prune dead constants

1 participant