Skip to content

Preserve ARM64 flags dependencies during indirection reordering - #135575

Merged
EgorBo merged 2 commits into
mainfrom
copilot/fix-arm64-jit-stale-flags
Oct 14, 2026
Merged

EgorBo merged 2 commits into
mainfrom
copilot/fix-arm64-jit-stale-flags

Conversation

Copilot AI commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

ARM64 store-pair reordering can move cneg before its cmp, causing k % 2 to read stale allocation-helper flags. On .NET 10, non-negative odd inputs can consequently produce -1.

  • Lowering: Reject moving marked flags consumers or producers in store-pair and post-indexed-addressing optimizations; MarkTree tracks only explicit operands.
  • Regression coverage: Exercise signed int and long remainder with negative, zero, and boundary inputs.
  • Codegen trade-off: The repro retains two scalar stores instead of stp: one additional instruction and four bytes per method.

@azure-pipelines

azure-pipelines Bot commented Oct 10, 2026 •

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.

@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 10, 2026
@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 changed the title [WIP] Fix ARM64 JIT stale flags issue for k % 2 Preserve ARM64 flags dependencies during indirection reordering Oct 10, 2026
Copilot AI requested a review from EgorBo October 10, 2026 17:19
@EgorBo
EgorBo marked this pull request as ready for review October 10, 2026 21:20
@EgorBo

EgorBo commented Oct 12, 2026

Copy link
Copy Markdown
Member

PTAL @dotnet/jit-contrib no diffs

@EgorBo
EgorBo requested a review from a team October 12, 2026 12:04
@EgorBo

EgorBo commented Oct 13, 2026

Copy link
Copy Markdown
Member

PTAL @adamperlin

@EgorBo
EgorBo requested a review from adamperlin October 13, 2026 17:46
@EgorBo
EgorBo enabled auto-merge (squash) October 14, 2026 02:17
@EgorBo
EgorBo merged commit 929e677 into main Oct 14, 2026
130 of 132 checks passed
@EgorBo
EgorBo deleted the copilot/fix-arm64-jit-stale-flags branch October 14, 2026 02:17
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 19, 2026
JulieLeeMSFT pushed a commit that referenced this pull request Oct 19, 2026
…eordering (#136083)

Fixes Issue #135521 <!-- Issue Number -->

main PR #135575 <!-- Link to PR if any that fixed this in the main
branch. -->

# Description

<!-- Give a brief summary of the issue and how the pull request is
fixing it. -->

Backport of #135575 to release/11.0. Preserve implicit flags
dependencies when reordering ARM64 stores and post-indexed addressing.
The regression test is adapted to the release branch's existing merged
runner.

# Customer Impact

<!-- What is the impact to customers of not taking this fix? -->

- [x] Customer reported
- [ ] Found internally

ARM64 code can compute incorrect signed remainder results after an
allocation. For example, `k % 2` can return `-1` for a non-negative odd
value.

# Regression

<!-- Is this fixing a problem that was introduced in the most recent
release, ie., fixing a regression? -->

- [ ] Yes
- [x] No

Not introduced in .NET 11. Wrong results are reported on .NET 10; the
underlying instruction-ordering bug is also present in .NET 9.

# Testing

<!-- What kind of testing has been done with the fix. -->

Test is added.

# Risk

<!-- Please assess the risk of taking this fix. Provide details backing
up your assessment. -->

Low. Only prevents reordering across implicit flags dependencies.

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 293a4931-e666-4c2c-bf85-571092949275
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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 JIT: k % 2 reads stale flags after an allocation (cneg emitted before its cmp), wrong results on .NET 10

3 participants