Skip to content

SVE: truncate Extract results for small types#125172

Merged
jakobbotsch merged 4 commits intodotnet:mainfrom
a74nh:lastactive_github
Mar 5, 2026
Merged

SVE: truncate Extract results for small types#125172
jakobbotsch merged 4 commits intodotnet:mainfrom
a74nh:lastactive_github

Conversation

@a74nh
Copy link
Contributor

@a74nh a74nh commented Mar 4, 2026

The clast and last instructions return 32bit or 64bit values, whereas the C# API allows for byte and short return values.

Fixes #125058

The clast and last instructions return 32bit or 64bit values, whereas
the C# API allows for byte and short return values.

Fixes dotnet#125058
Copilot AI review requested due to automatic review settings March 4, 2026 13:01
@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 Mar 4, 2026
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 4, 2026
@dotnet-policy-service
Copy link
Contributor

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

@a74nh a74nh changed the title SVE: truncate extract results for small types SVE: truncate Extract results for small types Mar 4, 2026
@jakobbotsch jakobbotsch self-requested a review March 4, 2026 13:08
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

Fixes ARM64 SVE scalar extract intrinsics (clasta/clastb and lasta/lastb) to ensure results are correctly sign/zero-extended for small integral return types (byte/sbyte/short/ushort), matching the C# API expectations and preventing miscompilations like #125058.

Changes:

  • Adjust SVE scalar codegen to use 32/64-bit emit sizes and explicitly extend results for small integral base types.
  • Simplify SVE scalar intrinsic import by removing an auxiliary JIT type assignment for the conditional extract scalar variant.
  • Add a new JIT regression test covering Sve.ConditionalExtractAfterLastActiveElement returning short.

Reviewed changes

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

File Description
src/coreclr/jit/hwintrinsiccodegenarm64.cpp Ensures scalar clast*/last* results are properly extended for small integral types and uses correct 4/8-byte emission sizes.
src/coreclr/jit/hwintrinsicarm64.cpp Removes auxiliary type propagation for the conditional extract scalar import path.
src/tests/JIT/Regression/Regression_ro_2.csproj Adds the new regression test source file to the compilation list.
src/tests/JIT/Regression/JitBlue/Runtime_125058/Runtime_125058.cs New regression reproducer asserting correct behavior under SVE support.
Comments suppressed due to low confidence (2)

src/coreclr/jit/hwintrinsiccodegenarm64.cpp:2741

  • The comment mentions only "byte/short" base types, but the code uses varTypeIsSmall(intrin.baseType) which also includes sbyte/ushort. Please adjust the wording to reflect that this applies to all 8- and 16-bit integral base types (signed and unsigned).
                    // clasta/clastb scalar variants produce 32-bit results for byte/short base types.
                    // Narrow down to the correct type if required.
                    if (varTypeIsSmall(intrin.baseType))
                    {

src/coreclr/jit/hwintrinsiccodegenarm64.cpp:2783

  • This comment says "byte/short" but the guard is varTypeIsSmall(intrin.baseType), which covers sbyte/ushort as well. Please update the wording to describe all small (8/16-bit) integral base types so the comment matches the behavior.
                    // lasta/lastb scalar variants produce 32-bit results for byte/short base types.
                    // Narrow down to the correct type if required.
                    if (varTypeIsSmall(intrin.baseType))
                    {

Copy link
Member

@jakobbotsch jakobbotsch left a comment

Choose a reason for hiding this comment

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

Thank you!

@jakobbotsch jakobbotsch merged commit 0a4314b into dotnet:main Mar 5, 2026
130 of 137 checks passed
@a74nh a74nh deleted the lastactive_github branch March 5, 2026 11:48
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 community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT: Bad codegen with Sve.ConditionalExtractAfterLastActiveElement

3 participants