Skip to content

JIT: recognize complementary constant funnel shifts - #134514

Open
benaadams wants to merge 1 commit into
dotnet:mainfrom
benaadams:jit/recognize-funnel-shifts
Open

benaadams wants to merge 1 commit into
dotnet:mainfrom
benaadams:jit/recognize-funnel-shifts

Conversation

@benaadams

Copy link
Copy Markdown
Member

Recognize (lo >> count) | (hi << (width - count)) with complementary constant counts and emit SHRD on x64 or EXTR on ARM64. Keep the original memory-access ordering and reject shapes that cannot safely share the two input registers.

Split from #134039 as suggested by @tannergooding. This is independent of the carry/borrow and multiply-accumulate changes in that PR.

Includes containment, register-allocation and code-generation support, plus boundary, randomized, aliasing and negative-pattern tests.

Validation:

  • Checked x64 and ARM64 cross-target JIT builds passed.
  • Focused x64 execution passed with expensive JIT checks, register stress, and hardware intrinsics disabled.
  • Inspected x64 disassembly: the matched constant shifts use SHRD.
  • Test project built with code-style analyzers and documentation generation enabled; IDE0005 explicitly enabled, with no unused imports reported.
  • git diff --check passed. Native ARM64 execution and a full SuperPMI sweep were not run for this extraction.

Copilot AI lite review requested due to automatic review settings September 23, 2026 13:16
@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 Sep 23, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Sep 23, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 7 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.

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.

Copilot review overview

🟡 Changes recommended

Two moderate findings remain unresolved in type matching and test independence.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds JIT recognition and code generation for complementary constant funnel shifts using SHRD on x64 and EXTR on ARM64.

Changes:

  • Adds matching, lowering, containment, and register-allocation support.
  • Adds architecture-specific instruction generation.
  • Adds correctness, boundary, aliasing, randomized, and negative-pattern tests.
File Summary
src/​tests/​JIT/​opt/​Add/​FunnelShift.csproj Configures the funnel-shift tests.
src/​tests/​JIT/​opt/​Add/​FunnelShift.cs Tests correctness and generated instructions. Moderate finding (2 votes): Overlap and Gap need an independent oracle or explicit negative disassembly checks.
src/​coreclr/​jit/​lsraxarch.cpp Adds x64 register constraints.
src/​coreclr/​jit/​lowerxarch.cpp Integrates x64 containment.
src/​coreclr/​jit/​lowerarmarch.cpp Integrates ARM64 containment.
src/​coreclr/​jit/​lower.h Declares funnel-shift lowering helpers.
src/​coreclr/​jit/​lower.cpp Matches and contains funnel-shift patterns. Moderate finding (1 vote): the type guard excludes TYP_ULONG and TYP_UINT; the related GenTree::IsFunnelShift assertion also needs updating.
src/​coreclr/​jit/​gentree.h Declares funnel-shift shape validation.
src/​coreclr/​jit/​gentree.cpp Implements funnel-shift shape validation.
src/​coreclr/​jit/​codegenxarch.cpp Emits SHRD.
src/​coreclr/​jit/​codegenarm64.cpp Emits EXTR.

Comment on lines +133 to +134
Overlap(lo, hi) != ((lo >> 17) | (hi << 46)) ||
Gap(lo, hi) != ((lo >> 17) | (hi << 48)) ||

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.

2 participants