You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Wasm][CoreCLR] Preserve native remainder instead of expanding constant MOD to SUB/MUL/DIV #135982
CoreCLR Wasm expands constant signed remainder into subtract/multiply/divide even though Wasm has a native remainder instruction. Consider preserving MOD for this target.
Generated code comes from CodegenStudy.Cases.RemainderThree:
Whole encoded bodies are 27 bytes (CoreCLR) versus 7 (Mono), with differing ABI/frame overhead. Keeping CoreCLR's frame setup unchanged, direct remainder would structurally avoid six encoded bytes and two arithmetic operators; this is an estimate, not a built patch.
The Checked dump identifies the origin in global morph:
Morphing MOD/UMOD [000002] to Sub/Mul/Div
Analysis
morph.cpp applies the signed non-power-of-two constant transformation through a non-ARM64 branch whose comment describes XARCH magic division. Wasm later retains ordinary division; codegenwasm.cpp already supports i32.rem_s.
Investigate target-aware gating/costing rather than inheriting this morph. % 3 can directly preserve signed semantics, including negative inputs, without divisor-zero or division-overflow cases. Other constants, especially % -1, need separate semantic care.
No timing was collected for this example; a browser may canonicalize both forms to similar host code. Division by eight is not part of this claim: both compared runtimes retained Wasm division there.
Note
This issue was prepared by GitHub Copilot from a locally executed codegen comparison study.
Activity
dotnet-policy-service commentedon Oct 16, 2026
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Oct 16, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.