Skip to content

arm64: Optimize Vector helper APIs - #132117

Open
jonathandavies-arm wants to merge 9 commits into
dotnet:mainfrom
jonathandavies-arm:upstream/sve/common-vector-routines
Open

jonathandavies-arm wants to merge 9 commits into
dotnet:mainfrom
jonathandavies-arm:upstream/sve/common-vector-routines

Conversation

@jonathandavies-arm

Copy link
Copy Markdown
Contributor

Import Vector64/128 helper APIs through Arm64 compare masks so Count, IndexOf, LastIndexOf, and related Any/All/None helpers can benefit from existing ExtractMostSignificantBits lowering. Preserve Scalar.Equals NaN semantics for floating-point value helpers and keep unsupported 64-bit mask encodings on fallback paths.
#121981 (comment)

dotnet#121981 (comment)
Import Vector64/128 helper APIs through Arm64 compare masks so Count, IndexOf, LastIndexOf, and related Any/All/None helpers can benefit from existing ExtractMostSignificantBits lowering. Preserve Scalar<T>.Equals NaN semantics for floating-point value helpers and keep unsupported 64-bit mask encodings on fallback paths.
@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 Aug 11, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Aug 11, 2026
@azure-pipelines

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

@SwapnilGaikwad

Copy link
Copy Markdown
Contributor

cc: @dotnet/arm64-contrib @dhartglassMSFT

@dhartglassMSFT

Copy link
Copy Markdown
Contributor

/azp run runtime-coreclr superpmi-diffs

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@dhartglassMSFT

dhartglassMSFT commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Hi @jonathandavies-arm, did you look at diffs? From the pipeline (fullopts)

Target Code-size delta
Windows x64 +861 bytes
Linux x64 −622 bytes
Windows ARM64 +7,036 bytes
Linux ARM64 +13,404 bytes
macOS ARM64 +304 bytes
Windows x86 +218 bytes

@SwapnilGaikwad SwapnilGaikwad mentioned this pull request Oct 26, 2026
2 of 27 tasks
Gate the new Vector helper registrations and importer paths on TARGET_ARM64, and remove their xarch-specific lowering. This preserves Arm64 code generation while leaving other targets on the existing managed paths.
@jonathandavies-arm

Copy link
Copy Markdown
Contributor Author

Hi @jonathandavies-arm, did you look at diffs? From the pipeline (fullopts)
Target Code-size delta
Windows x64 +861 bytes
Linux x64 −622 bytes
Windows ARM64 +7,036 bytes
Linux ARM64 +13,404 bytes
macOS ARM64 +304 bytes
Windows x86 +218 bytes

I've added a change and this work is now limited to ARM64, so the disasm increases should now only be on the ARM64 builds.

The extra instructions come from how the new imports turn vector comparison results into an element index. The existing managed-helper path can use shrn / fmov / clz to find the last matching lane without packing a separate bit for every element. With the new imported form, some callers instead build that packed mask using shifts, widening and horizontal adds; others use a vector selection and minimum reduction. Both can require more instructions and constant loads than the existing sequence.

I've put together a performance suite for this work on a separate branch, perf/vector-helper-investigation. It includes the custom benchmarks, run scripts and recorded results. Despite the larger disassembly in some cases, we see improved execution time for the tested count/index helpers on a Cortex-X925. The table below shows representative median times (including loop and array-access overhead) for integer vectors with the match in the last lane, comparing the PR with main using the same runtime and CoreLib and swapping only the JIT:

Helper Main, ns/op PR, ns/op Time reduction
Vector64.Count<int> 0.764 0.548 28.3%
Vector128.Count<int> 0.710 0.550 22.5%
Vector64.IndexOf<int> 0.865 0.776 10.3%
Vector128.IndexOf<int> 0.811 0.776 4.2%
Vector64.LastIndexOf<int> 0.761 0.670 11.9%
Vector128.LastIndexOf<int> 0.753 0.671 10.9%

I also ran the relevant dotnet/performance benchmarks, where results were mostly unchanged. These vector helpers have little direct coverage in the existing suite, so it provides limited coverage of this change.

Standard span benchmarks Cases Result
Unchanged 23 Classified as unchanged at the 5% comparison threshold
Slower 1 Span<int>.LastIndexOfValue, length 4: 1.895 → 2.016 ns (+6.4%); still needs investigation

I think it is best to allow this change to go in, accept that the asmdiffs will increase but we get better performance.

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

3 participants