Skip to content

[Wasm RyuJit] Refactor codegenwasm.cpp to separate div/mod ops and align function names - #122157

Merged
kg merged 4 commits into
mainfrom
copilot/update-codegenwasm-quality
Dec 4, 2025
Merged

kg merged 4 commits into
mainfrom
copilot/update-codegenwasm-quality

Conversation

Copilot AI commented Dec 3, 2025 •

Copy link
Copy Markdown
Contributor

The WebAssembly RyuJIT backend mixed division/modulus operations with basic arithmetic in genCodeForBinary and used an inconsistent function name genCodeForShiftOrRotate that didn't match the declaration in codegen.h.

Changes

  • Extract div/mod operations: Move GT_DIV, GT_MOD, GT_UDIV, GT_UMOD from genCodeForBinary to new genCodeForDivMod function, matching ARM64/x64/RISC-V64 architecture
  • Rename shift function: Change genCodeForShiftOrRotate → genCodeForShift to match codegen.h declaration and other targets
  • Remove redundant declaration: Delete #ifdef TARGET_WASM wrapped genCodeForShiftOrRotate declaration in codegen.h
  • Add validation: Include assert(tree->OperIsShiftOrRotate()) consistent with x64 implementation

Updated dispatch in genCodeForTreeNode:

case GT_DIV:
case GT_MOD:
case GT_UDIV:
case GT_UMOD:
    genCodeForDivMod(treeNode->AsOp());  // Now separate from genCodeForBinary
    break;

Aligns WASM backend structure with established patterns across other architectures.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Wasm RyuJit] Update codegenwasm.cpp to address code quality issues</issue_title>
<issue_description>The WebAssembly RyuJIT backend in codegenwasm.cpp and other files needs to be updated as follows:

  1. Move the GT_DIV, GT_MOD, GT_UDIV and GT_UMOD cases from CodeGen::genCodeForBinary to CodeGen::genCodeForDivMod, which does not currently have a definition in codegenwasm.cpp (you will need to add one that matches the existing declaration in codegen.h.) Make sure to include the header and footer from genCodeForBinary in the new genCodeForDivMod so it will work correctly.
  2. Remove the declaration for genCodeForShiftOrRotate in codegen.h along with the #ifdef TARGET_WASM around it. The declaration is redundant.
  3. Rename the CodeGen::genCodeForShiftOrRotate definition in codegenwasm.cpp to genCodeForShift to match the existing declaration in codegen.h.
  4. Update the cases in CodeGen::genCodeForTreeNode so that GT_DIV, GT_MOD, GT_UDIV and GT_UMOD are implemented by calling genCodeForDivMod instead of calling genCodeForBinary.
    </issue_description>

<agent_instructions>When building the repository while working, only build the clr and libs subsets in order to save time instead of building all subsets. Like the following command:
.\build.cmd clr+libs</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI assigned Copilot and kg Dec 3, 2025
@kg kg added arch-wasm WebAssembly architecture area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI labels Dec 3, 2025
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Copilot AI and others added 3 commits December 3, 2025 22:13
- Move GT_DIV, GT_MOD, GT_UDIV, GT_UMOD cases from genCodeForBinary to new genCodeForDivMod function
- Remove redundant genCodeForShiftOrRotate declaration in codegen.h
- Rename genCodeForShiftOrRotate to genCodeForShift in codegenwasm.cpp
- Update genCodeForTreeNode to call genCodeForDivMod for div/mod operations

Co-authored-by: kg <[email protected]>
Update NYI_WASM error message from "genCodeForShiftOrRotate" to "genCodeForShift" to match the renamed function.

Co-authored-by: kg <[email protected]>
Add assert(tree->OperIsShiftOrRotate()) to match the pattern used in other architectures and improve input validation.

Co-authored-by: kg <[email protected]>
Copilot AI changed the title [WIP] Update codegenwasm.cpp to improve code quality [Wasm RyuJit] Refactor codegenwasm.cpp to separate div/mod ops and align function names Dec 3, 2025
Copilot AI requested a review from kg December 3, 2025 22:20
Copilot finished work on behalf of kg December 3, 2025 22:20
@kg
kg marked this pull request as ready for review December 3, 2025 22:30
Copilot AI review requested due to automatic review settings December 3, 2025 22:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 refactors the WebAssembly RyuJIT backend to align its code structure with other architectures (ARM64, x64, RISC-V64) by separating division/modulus operations from basic arithmetic and standardizing function naming conventions.

Key changes:

  • Extracted division and modulus operations (GT_DIV, GT_MOD, GT_UDIV, GT_UMOD) from genCodeForBinary into a new dedicated genCodeForDivMod function
  • Renamed genCodeForShiftOrRotate to genCodeForShift to match the declaration in codegen.h and align with other architectures
  • Removed redundant #ifdef TARGET_WASM declaration block in codegen.h

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/coreclr/jit/codegenwasm.cpp Extracted div/mod operations to new genCodeForDivMod function, renamed shift function to genCodeForShift, updated dispatch logic in genCodeForTreeNode, added validation assert
src/coreclr/jit/codegen.h Removed redundant #ifdef TARGET_WASM wrapped declaration for genCodeForShiftOrRotate

@kg

kg commented Dec 3, 2025

Copy link
Copy Markdown
Contributor

cc @dotnet/jit-contrib

@kg
kg merged commit 8c37ae7 into main Dec 4, 2025
@jkotas
jkotas deleted the copilot/update-codegenwasm-quality branch December 7, 2025 12:44
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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.

[Wasm RyuJit] Update codegenwasm.cpp to address code quality issues

5 participants