Skip to content

Conversation

@AndyAyersMS
Copy link
Member

Wasm has a few wrinkles here to sort through. There is no NOT or NEG for integer types in Wasm.

Also, support returning TYP_LONG directly.

Wasm has a few wrinkles here to sort through. There is no NOT
or NEG for integer types in Wasm.

Also, support returning TYP_LONG directly.
Copilot AI review requested due to automatic review settings December 10, 2025 02:13
@AndyAyersMS
Copy link
Member Author

@dotgnet/jit PTAL

@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Dec 10, 2025
@AndyAyersMS
Copy link
Member Author

Might want to remove GT_LONG entirely from wasm builds.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds WASM support for NOT and NEG operations in the RyuJIT compiler. Since WASM lacks native NOT and NEG instructions for integer types, the implementation transforms integer NEG operations into SUB(0, x) during lowering, handles NOT using XOR with -1 during code generation, and preserves native f32.neg/f64.neg for floating-point types. Additionally, the PR enables direct TYP_LONG return values for WASM (which has native 64-bit support).

Key Changes

  • Added LowerNeg in lowerwasm.cpp to transform integer NEG operations to SUB(0, x)
  • Added genCodeForNegNot in codegenwasm.cpp to handle NOT (via XOR with -1) and floating-point NEG
  • Modified ContainCheckRet to allow WASM to return TYP_LONG directly without containing GT_LONG nodes

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/coreclr/jit/lowerwasm.cpp Implements LowerNeg to transform integer NEG operations to SUB(0, x) since WASM lacks native integer NEG
src/coreclr/jit/lower.h Declares LowerNeg function under TARGET_WASM guard
src/coreclr/jit/lower.cpp Integrates LowerNeg into LowerNode for GT_NEG case and allows WASM to return TYP_LONG directly
src/coreclr/jit/codegenwasm.cpp Implements genCodeForNegNot to generate WASM instructions: XOR with -1 for NOT, native f32.neg/f64.neg for floating-point NEG

Copy link
Contributor

@SingleAccretion SingleAccretion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with minor comments.

@am11 am11 added the arch-wasm WebAssembly architecture label Dec 10, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

@AndyAyersMS AndyAyersMS merged commit b720354 into dotnet:main Dec 10, 2025
123 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants