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] Null checks could use i32.eqz instead of i32.const 1023 #134463
When doing null checks, if we're checking a managed object reference for null, in many cases we're working with the object pointer itself. When doing so, we currently use a sequence like the following.
i32.const1023i32.ge_u
However, it would be smaller, and possibly a bit faster (on some platforms) to use a shorter sequence.
i32.eqz
If we only need to do a null check, this should be a better encoding, and equivalent in our semantics.
I remember we had a discussion about this at the start of the year and there was an issue with using 0 directly as the global null check offset, and there was an experimental PR which showed many test failures: #123290. This was across all platforms though. In this particular case, it sounds like we wouldn't be changing the global null check offset (maxUncheckedOffsetForNullObject) and only the behavior on Wasm for null checks. @davidwrighton are you saying it should be safe to directly compare with 0 to detect a null ref on Wasm with no "round to null" for small pointers < 1023?
I'm saying that for null checks, in many/most/all cases it should be safe to check for actual null for references to objects. For byrefs the question is somewhat more nuanced. We couldn't properly test on wasm when @AndyAyersMS made his experimental PR, but that's no longer true, so l'd like to see us try to make such a change and see the impact on test results.
I'm saying that for null checks, in many/most/all cases it should be safe to check for actual null for references to objects. For byrefs the question is somewhat more nuanced. We couldn't properly test on wasm when @AndyAyersMS made his experimental PR, but that's no longer true, so l'd like to see us try to make such a change and see the impact on test results.
Ok, that makes sense. I'd be happy to try and make this change and see what the impact on tests is.
Activity
dotnet-policy-service commentedon Sep 22, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
davidwrighton commentedon Sep 22, 2026
This will save 3 bytes per null check when appropriate.
adamperlin commentedon Sep 22, 2026
I remember we had a discussion about this at the start of the year and there was an issue with using
0directly as the global null check offset, and there was an experimental PR which showed many test failures: #123290. This was across all platforms though. In this particular case, it sounds like we wouldn't be changing the global null check offset (maxUncheckedOffsetForNullObject) and only the behavior on Wasm for null checks. @davidwrighton are you saying it should be safe to directly compare with0to detect a null ref on Wasm with no "round to null" for small pointers < 1023?davidwrighton commentedon Sep 23, 2026
I'm saying that for null checks, in many/most/all cases it should be safe to check for actual null for references to objects. For byrefs the question is somewhat more nuanced. We couldn't properly test on wasm when @AndyAyersMS made his experimental PR, but that's no longer true, so l'd like to see us try to make such a change and see the impact on test results.
adamperlin commentedon Sep 23, 2026
Ok, that makes sense. I'd be happy to try and make this change and see what the impact on tests is.
[JIT] [wasm]: Compare TYP_REF references directly with null using i32…