Skip to content

[NativeAOT-LLVM] Null reference exceptions and transient byrefs #3127

@SingleAccretion

Description

@SingleAccretion

We have this comment in codegen:

// The frontend's contract with the backend is that it will not insert null checks for accesses which
// are inside the "[0..compMaxUncheckedOffsetForNullObject]" range. Thus, we usually need to check not
// just for "null", but "null + small offset". However, for TYP_REF, we know it will either be a valid
// object on heap, or null, and can utilize the more direct form.

Using the "long form" nullcheck costs a lot of code size (measured to be > 1.7% on WasmDebugging), both due to the explicitly longer WASM code sequence and the opaqueness of the check to LLVM.

Thus, the tasks in this issue are as follows:

  1. Rationalize the current "transient invalid byrefs allowed... but only briefly" null checking model.
  2. Stop using the long form checks for WASM by setting compMaxUncheckedOffsetForNullObject to 0. This would also allow us to delete the wasm-global-base argument and the (implicit) ABI coupling it creates.
  3. Fix all (upstream) RyuJit bugs due to this. Ensure it is tested upstream (there is already a stress mode, but the value used is a bit larger).
  4. Fix all (upstream) RyuJit optimization deficiencies due to this. Currently it results in a 1.8% code size increase.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-NativeAOT-LLVMLLVM generation for Native AOT compilation (including Web Assembly)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions