Skip to content

[RyuJIT Wasm]: Fix incorrect assert for shift amount type in codegenwasm.cpp#129343

Open
adamperlin wants to merge 2 commits into
dotnet:mainfrom
adamperlin:adamperlin/wasm-fix-shift-codegen-bug
Open

[RyuJIT Wasm]: Fix incorrect assert for shift amount type in codegenwasm.cpp#129343
adamperlin wants to merge 2 commits into
dotnet:mainfrom
adamperlin:adamperlin/wasm-fix-shift-codegen-bug

Conversation

@adamperlin

Copy link
Copy Markdown
Contributor

Fixes #129263; This came up due to the following IL in a regression test:

 ldc.i8 0xa60d377f2863e61c
 ldsflda unsigned int16 ILGEN_0x3c109d11::field_0x1
 ldind.u2
 shr.un

We have a load of a ushort as the shift operand, and this is preserved through import down to codegen.
We were asserting that the exact type for the shift amount operand is TYP_INT, when this may not be the case since the shift amount could be a smaller integer type that still fits in TYP_INT. Instead, the assert should use genActualType

@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 Jun 12, 2026
@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 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 adjusts a debug assertion in the Wasm RyuJIT code generator so that 64-bit shift/rotate nodes accept shift-amount operands whose actual type is TYP_INT, even when the operand’s node type is a smaller integral type (e.g., TYP_USHORT).

Changes:

  • In CodeGen::genCodeForShift, replace the strict TypeIs(TYP_INT) check on the shift amount with an genActualType(... ) == TYP_INT check for TYP_LONG shifts/rotates.

Comment thread src/coreclr/jit/codegenwasm.cpp

@AndyAyersMS AndyAyersMS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fix up the comment and we're good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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 / R2R: crossgen2 assert in genCodeForShift on long shift with non-INT shift amount

3 participants