Skip to content

JIT: preserve arm64 widening overloads through lowering - #137455

Merged
AndyAyersMS merged 2 commits into
dotnet:mainfrom
AndyAyersMS:fix-137322-widening-lower
Nov 20, 2026
Merged

AndyAyersMS merged 2 commits into
dotnet:mainfrom
AndyAyersMS:fix-137322-widening-lower

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

Preserve the first operand's original element type for Arm64 lower widening add/subtract intrinsics. Use it to select L/W forms instead of the post-lowering SIMD size, which can change when GetLower() or ToVector128Unsafe() is removed.

Update the internally generated widening add used by ExtractMostSignificantBits and add regression coverage for both operations across all six element-type pairs.

Validation

  • macOS Arm64 Checked: both AdvSimd suites pass in FullOpts and MinOpts, and under NativeAOT. The new optimized regression fails with the unfixed JIT.
  • Four Vector128 suites and exhaustive byte/sbyte ExtractMostSignificantBits checks pass. JIT formatting passes.
  • SuperPMI: all six matching macOS Arm64 collections, 446,262 contexts, no diffs, failures, or misses. A fresh regression collection has 14 expected L/W opcode corrections across 331 contexts, with no code-size or PerfScore change and no failures or misses.

Other platforms were not run.

Resolves #137322

Note

This PR description was generated with GitHub Copilot.

Select L/W forms using the original operand element type, not the
post-lowering SIMD size. Add regression coverage.

Fixes dotnet#137322

Co-authored-by: Copilot <[email protected]>
Copilot-Session: fb633bef-7293-40ce-a6b0-0c3c8193d6fa
@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 Nov 12, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 6 pipeline(s).
9 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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.

@AndyAyersMS
AndyAyersMS requested review from dhartglassMSFT and a balanced review from Copilot November 12, 2026 23:26
@AndyAyersMS

Copy link
Copy Markdown
Member Author

@dhartglassMSFT ptal
fyi @dotnet/jit-contrib

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.

🟡 Changes recommended

The uint/ulong and int/long test cases use a wide-lane value of 1000, allowing the incorrect L instruction to pass; nonzero upper 32 bits are needed to detect the original opcode-selection bug.

1 open issue
What changed in this PR

This PR fixes Arm64 widening add/subtract instruction selection by preserving the original operand element type through JIT lowering.

Changes:

  • Record overload metadata during import and use it to select L/W instruction forms.
  • Set matching metadata for the widening add generated by ExtractMostSignificantBits.
  • Add regression tests for both operations across six element-type pairs.
File Description
src/​tests/​JIT/​HardwareIntrinsics/​Arm/​AdvSimd/​Program.AdvSimd.cs Adds regression coverage for size-changing operand conversions.
src/​coreclr/​jit/​rationalize.cpp Annotates the internally generated widening add.
src/​coreclr/​jit/​hwintrinsiccodegenarm64.cpp Selects instructions using preserved element types.
src/​coreclr/​jit/​hwintrinsic.cpp Preserves first-operand type metadata for lower widening intrinsics.

Review effort: Balanced

@JulieLeeMSFT JulieLeeMSFT 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.

LGTM. It preserves the original operand lane type to ensure correct Arm64 L/W opcode selection regardless of SIMD-size changes.

Updated test to exercise upper 32 bits in ulong/long cases.

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@AndyAyersMS

Copy link
Copy Markdown
Member Author

@JulieLeeMSFT tweaked the test case a bit, can you re-approve?

@AndyAyersMS

Copy link
Copy Markdown
Member Author

/ba-g osx build host stopped responding mid build

@AndyAyersMS
AndyAyersMS merged commit e56caa3 into dotnet:main Nov 20, 2026
127 of 130 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 23, 2026
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.

Arm64: AdvSimd.AddWideningLower/SubtractWideningLower(x.GetLower(), y) compiles to UADDW/USUBW on .NET 11

3 participants