Skip to content

[wasm] Null checks could use i32.eqz instead of i32.const 1023 #134463

Closed

Description

@davidwrighton

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.const 1023
i32.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.

Activity

  1. added
    tenet-performance
    on Sep 22, 2026
  2. added
    untriaged
    on Sep 22, 2026
  3. added
    area-CodeGen-coreclr
    untriaged
    and removed
    tenet-performance
    untriaged
    on Sep 22, 2026
  4. dotnet-policy-service commented on Sep 22, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  5. davidwrighton commented on Sep 22, 2026

    @davidwrighton
    MemberAuthor

    This will save 3 bytes per null check when appropriate.

  6. adamperlin commented on Sep 22, 2026

    @adamperlin
    Contributor

    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?

  7. davidwrighton commented on Sep 23, 2026

    @davidwrighton
    MemberAuthor

    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.

  8. adamperlin commented on Sep 23, 2026

    @adamperlin
    Contributor

    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.

  9. self-assigned this
    on Sep 24, 2026
  10. removed
    untriaged
    on Sep 25, 2026
  11. added this to the 12.0.0 milestone on Sep 25, 2026
  12. added a commit that references this issue on Sep 29, 2026
    505f58f
  13. locked and limited conversation to collaborators on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions