Closed Bug 1783956 Opened 2 years ago Closed 1 year ago

Add MWasmTrapIfNull/Zero to simplify MIR

Categories

(Core :: JavaScript: WebAssembly, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
113 Branch
Tracking Status
firefox113 --- fixed

People

(Reporter: yury, Assigned: jpages)

References

(Blocks 1 open bug)

Details

Attachments

(3 files, 1 obsolete file)

Per conversation at https://phabricator.services.mozilla.com/D154146#inline-848543 :

we should add a MWasmNullCheck instruction which takes a MIRType::RefOrNull operand and performs the null check/branch/trap in a single instruction. This will reduce the number of blocks we create, which will reduce the work that regalloc needs to do.

This shall improve the performance of Wasm function-reference and GC code/instructions.

  • Refactor checkNull() to create MWasmNullCheck instead of null constant and comparison.
  • Implement LIsWasmNullAndBranch to do pointer test and branching
Assignee: nobody → ydelendik
Status: NEW → ASSIGNED
Attachment #9290199 - Attachment description: Bug 1783956 - Add MWasmNullCheck to improve the performance of Ion. r?jseward → Bug 1783956 - Change wasm null check code generation. r?jseward
Attachment #9290199 - Attachment description: Bug 1783956 - Change wasm null check code generation. r?jseward → Bug 1783956 - Add MWasmNullCheck to improve the performance of Ion. r?jseward

Proof-of-concept patch to for generating the required code without adding any new MIR or LIR node kinds. Suggested usage:

IONFLAGS=codegen,dump-mir-expr,mir-to-lir ./dist/bin/js --no-ion --wasm-compiler=ion
--wasm-function-references --no-threads testcase.js

This should generate identical code for the two fns in testcase.js, on x86_64-linux. (one is currently commented out)

Severity: -- → N/A
Priority: -- → P3

I think there was some confusion about what I was originally proposing. Right now the way to conditionally trap with MIR is something like:

block0:
   compare
   test block1, block2

block1:
  trap

block2:
  ... continue

When this is a common pattern, this creates a ton of blocks and causes extra work for regalloc to handle liveness.

I'm suggesting that we create a new MIR node that encapsulates this 'side-exit' pattern: MWasmTrapIfZero [1] or MWasmTrapIfNull. This node would do the comparison and trapping if the input is null/zero, otherwise control flow will continue on. This would reduce the number of blocks we need.

This is less important once we have signal handling, but may still be useful if we can't eliminate all null-checks.

[1] https://searchfox.org/mozilla-central/rev/c33879cb4884c08c11980847cd84ccd76f485894/js/src/wasm/WasmIonCompile.cpp#4087-4113

Assignee: ydelendik → nobody
Status: ASSIGNED → NEW
Summary: Add MWasmNullCheck to improve the performance of Ion code → Add MWasmTrapIfNull/Zero to simplify MIR
Assignee: nobody → jpages

This simplifies the control-flow when compiling ref.as_non_null
with the ion backend.

Pushed by jpages@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/17d9f529b72a
Add a new MIR node MWasmTrapIfNull. r=rhunt
Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 113 Branch
Attachment #9290199 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: