Repository navigation
Optimize Wasm comparisons against zero - #135380
Merged
Merged
Conversation
Use eqz for integer equality comparisons against zero and avoid redundant boolean normalization before eligible br_if instructions. Co-authored-by: Copilot <[email protected]>
|
Azure Pipelines: Successfully started running 6 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
JulieLeeMSFT
previously approved these changes
Oct 8, 2026
JulieLeeMSFT
left a comment
Member
There was a problem hiding this comment.
LGTM.
The eqz substitutions preserve equality results, and the branch optimization is limited to i32 != 0, so br_if receives the required i32 condition; i64 comparisons retain their conversion.
3 tasks
Keep zero comparisons available for Wasm control-flow reversal and use GTF_RELOP_JMP_USED to emit direct i32 branch conditions during code generation. Co-authored-by: Copilot <[email protected]>
adamperlin
approved these changes
Oct 9, 2026
adamperlin
left a comment
Contributor
There was a problem hiding this comment.
This looks good to me as well!
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
i32.eqzori64.eqzinstead of a zero constant followed by a general equality instruction.i32 != 0normalization when the result feedsbr_ifdirectly.General comparison results remain normalized to 0 or 1. Inequality values therefore use a second
i32.eqz, while eligiblei32 != 0branches can consume the original value directly. The directbr_ifoptimization is restricted toi32;i64values still usei64.eqzbecause Wasm branch conditions requirei32.Size impact
For a browser/Wasm Release build of
System.Private.CoreLib.wasm:The raw reduction was entirely in the CODE section.
Validation
The following builds completed successfully:
Focused Crossgen2 probes verified:
int == 0emitsi32.eqz.int != 0values emiti32.eqz; i32.eqz.long == 0emitsi64.eqz.long != 0values emiti64.eqz; i32.eqz.i32 != 0branches feedbr_ifdirectly.i64branches retain the requiredi64.eqz.i32.eqz.Matched baseline and updated CoreLib disassembly showed:
System.TimeZoneInfo.CacheTransitionsForYear: all 48 zero-constant equality sequences removed; 105 instruction bytes saved.System.SpanHelpers.IndexOfAny_0<System.__Canon>: all 49 zero-constant equality sequences removed; 112 instruction bytes saved.JIT formatting and
git diff --checkcompleted successfully.Resolves #135379
Note
This pull request was drafted with GitHub Copilot.