Skip to content

ARM64 reenable IsRedundantLdStr - #137952

Merged
dhartglassMSFT merged 4 commits into
dotnet:mainfrom
dhartglassMSFT:enable_IsRedundantLdStr
Nov 23, 2026
Merged

dhartglassMSFT merged 4 commits into
dotnet:mainfrom
dhartglassMSFT:enable_IsRedundantLdStr

Conversation

@dhartglassMSFT

Copy link
Copy Markdown
Contributor

Peep to look for redundant ldr+str/str+ldr pairs won't fire currently, because its blocked by a check that previous instr and current instr are the same.

Fix is to move the emitLastIns->idIns() != ins check later in the function. Also needed to add a check to not perform removal if the pair has mismatching gc info. This was needed for some unsafe code, though I wasn't able to build a repro that required this to pass.

Sample diff:

             ldapur  x0, [x0, #-0x10]
             ; byrRegs +[x0]
             str     x0, [fp, #0x18]    // [V05 tmp4]
-            ldr     x0, [fp, #0x18]    // [V05 tmp4]
             and     x0, x0, #-2
             ; byrRegs -[x0]
             str     xzr, [fp, #0x18]   // [V05 tmp4]
-                       ;; size=48 bbWeight=1 PerfScore 16.50
+                       ;; size=44 bbWeight=1 PerfScore 14.50

Diffs look good. 127,948 bytes saved across 1,388,596 FullOpts contexts. No regressions. There's some +0 diffs like ldp changing to ldr. This is due to a now-removed ldr now stopping a "combine-ldr-into-ldp" peep from firing. This won't regress performance.

fixes #137871

@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 19, 2026
@azure-pipelines

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

🟡 Changes recommended

The optimization can eliminate a required ARM64 volatile read, reusing the stored value instead of allowing the load to observe another thread’s write.

2 open issues
What changed in this PR

This PR re-enables redundant load/store elimination in the ARM64 JIT emitter, addressing #137871 and reducing generated code size.

Changes:

  • Moves the same-instruction check after redundant load/store detection.
  • Requires matching garbage-collection metadata before eliminating an instruction.
  • Allows sub-64-bit vector loads to qualify while preserving zero-extension checks for general-purpose registers.
File Description
src/​coreclr/​jit/​emitarm64.cpp Re-enables load/store elimination and adjusts register-size and GC-metadata guards.

Review effort: Balanced

Comment thread src/coreclr/jit/emitarm64.cpp Resolved
Comment thread src/coreclr/jit/emitarm64.cpp Resolved
@AndyAyersMS

Copy link
Copy Markdown
Member

I didn't see anything worth noting beyond what copilot found. Ping me again when you've pushed more changes.

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.

🟡 Changes recommended

The disassembly tests do not verify removal of nonvolatile ARM64 store/load pairs, including the newly permitted floating-point case, so they would miss a regression that disables the optimization.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment thread src/coreclr/jit/emitarm64.cpp Resolved
@dhartglassMSFT

Copy link
Copy Markdown
Contributor Author

@AndyAyersMS should be ready for review. Addressed the copilot PR feedback. The volatile-issue it pointed out was also an issue with one of the other peeps in this routine. Also accepted the SpToZR change, that didn't get extra diffs though.

@dhartglassMSFT
dhartglassMSFT merged commit 7711ca8 into dotnet:main Nov 23, 2026
129 of 131 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 24, 2026
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: Fix IsRedundantLdStr for arm64

3 participants