Skip to content

JIT: skip lane bounds for constant ARM64 indices - #137583

Open
AndyAyersMS wants to merge 2 commits into
dotnet:mainfrom
AndyAyersMS:jit/preserve-indexed-simd-operands
Open

AndyAyersMS wants to merge 2 commits into
dotnet:mainfrom
AndyAyersMS:jit/preserve-indexed-simd-operands

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

Skip the indexed-element lane-bound lookup in LSRA when the index is constant. It needs no jump-table register, and lowering may have replaced CreateScalarUnsafe with a scalar operand. This matches codegen's existing constant-index handling and preserves scalar-wrapper elimination.

Adds regression coverage for Vector64<float>, Vector128<float>, and Vector128<double>.

Validated on macOS ARM64 (M4): Checked JIT build passed; all 5,381 optimized ARM intrinsic cases passed, including the new regression, which asserts on the unpatched JIT. superpmi.py asmdiffs replayed 446,262 contexts with zero assembly diffs or misses. JIT formatting passed.

Resolves #135526

Note

This PR description and the changes were developed with GitHub Copilot.

Fixes dotnet#135526.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dfb97b66-e90e-4673-a5ce-6fbdf442c56d
@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 15, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 7 pipeline(s).
8 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

Copy link
Copy Markdown
Member Author

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

🟢 Approval recommended

No active review issues are reported for the ARM64 constant-index register-allocation change.

No open issues 🎉

What changed in this PR

This PR adjusts ARM64 JIT register allocation to skip lane-bound lookup for constant indexed-element operands, preserving scalar-wrapper elimination.

Changes:

  • Returns early for constant indices, which need no jump-table register.
  • Adds regression coverage for scalar-created operands with Vector64<float>, Vector128<float>, and Vector128<double>.
File Description
src/​tests/​JIT/​HardwareIntrinsics/​Arm/​AdvSimd/​Program.AdvSimd.cs Adds constant-index multiplication regression tests using CreateScalarUnsafe.
src/​coreclr/​jit/​lsraarm64.cpp Skips indexed-element lane-bound lookup for contained constant indices.

Review effort: Balanced

if (intrin.category == HW_Category_SIMDByIndexedElement)
{
// A constant index needs no jump table, and lowering may have replaced its SIMD operand with a scalar.
if (intrinsicTree->Op(intrin.numOperands)->isContainedIntOrIImmed())

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.

My understanding of this bug is we have something like

AdvSimd.MultiplyBySelectedScalar(a, Vector64.CreateScalarUnsafe(x), index)

Lowering of CreateScalarUnsafe puts a scalar typed node into the IndexedElement position right?

This bail avoids the assert+weird index calculation only when index is constant. Or, is there some enforced invariant that we can't get a scalar operand here UNLESS we have a constant index?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If the index is not constant then the intrinsic becomes a call to a managed fallback and CreateScalarUnsafe remains, and LSRA may need to allow for an internal register.

If the index is a constant CreateScalarUnsafe may get replaced by a scalar, depending on the scalar type and consumer; either way we don't care as no interal register is needed.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: dfb97b66-e90e-4673-a5ce-6fbdf442c56d

This branch has not been deployed

No deployments
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.

JIT: (bug) [ARM64] assert varTypeIsSIMD(indexedElementOpType) for AdvSimd.MultiplyBySelectedScalar with Vector64.CreateScalarUnsafe

3 participants