Skip to content

ARM64: Fold shifted extensions into arithmetic and comparisons - #136715

Open
NinoFloris wants to merge 1 commit into
dotnet:mainfrom
NinoFloris:jit/arm64-shifted-extensions
Open

NinoFloris wants to merge 1 commit into
dotnet:mainfrom
NinoFloris:jit/arm64-shifted-extensions

Conversation

@NinoFloris

Copy link
Copy Markdown
Contributor

ARM64 can combine a sign/zero extension and a small left shift into an arithmetic or comparison instruction. The JIT already recognizes the combined expression as GT_BFIZ, but does not fold it into these consumers.

For example the single argument Span<int>.Slice(start) currently computes its address with:

ubfiz x3, x2, #2, #32
add   x0, x0, x3

This change allows:

add   x0, x0, w2, UXTW #2

Extend the existing cast-containment path to handle shifted extensions in ADD, SUB, and CMP, including flag-setting forms. This removes separate UBFIZ/SBFIZ instructions while retaining the existing overflow and evaluation-order restrictions.

@jonathandavies-arm

@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 Oct 30, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 30, 2026
@azure-pipelines

azure-pipelines Bot commented Oct 30, 2026 •

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.

@NinoFloris

Copy link
Copy Markdown
Contributor Author

Nice diffs https://dev.azure.com/dnceng-public/public/_build/results?buildId=1656382&view=ms.vss-build-web.run-extensions-tab

@NinoFloris

NinoFloris commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor Author

The two failing checks are from infra failures. Could somebody retry them?

@NinoFloris NinoFloris changed the title Fold shifted extensions into ARM64 arithmetic and comparisons ARM64: Fold shifted extensions into arithmetic and comparisons Nov 2, 2026
@tannergooding

Copy link
Copy Markdown
Member

@NinoFloris failures look legitimate and are in the arm64 legs:

[06:52:26] ISSUE: #495953 D:\a_work\1\s\src\coreclr\jit\lsra.cpp (3109) - Assertion failed '!conflictingFixedRegReference(physRegRecord->regNum, refPosition)' in 'Runtime_135509:Test(byte[],int):ulong' during 'LSRA build intervals' (IL size 760; hash 0x05de23d6; FullOpts)

@NinoFloris

Copy link
Copy Markdown
Contributor Author

I see now, I needed to click through a few more times to get to the actual logs. On first sight it looks like infra failed to complete a job. Investigating.

@NinoFloris
NinoFloris force-pushed the jit/arm64-shifted-extensions branch from 5055bbb to 25afb41 Compare November 3, 2026 16:07
@NinoFloris

Copy link
Copy Markdown
Contributor Author

This was fixed in #136642. Rebased run should go green now.

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

value == -((long)index << 2) could also do with a similar optimization for CMN which also looks to be missing similar handling.

@tannergooding
tannergooding requested a review from EgorBo November 3, 2026 21:17
@NinoFloris

NinoFloris commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @tannergooding. CMN looks to be a bit more involved to recognize, and I expect it won't have many hits. If you're interested I can make an attempt in a follow-up, otherwise I'll leave it for now.

@tannergooding

Copy link
Copy Markdown
Member

I'm fine with it being separate (and think it's probably better if it is).

@NinoFloris

NinoFloris commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Yeah I do mean as a follow-up PR. Just asking if you'd be up for reviewing it.

@NinoFloris

Copy link
Copy Markdown
Contributor Author

@dhartglassMSFT PTAL

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