Skip to content

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Jul 11, 2025

ARR_LENGTH was (2,2) while IND(ADD(addr, 8)) is (4,4) while both are effectively the same.

Diffs - seems to be a big PerfScore improvement. Surprisingly, it's also a size improvement on arm64.

@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 Jul 11, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@EgorBo EgorBo marked this pull request as ready for review July 11, 2025 03:22
Copilot AI review requested due to automatic review settings July 11, 2025 03:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the evaluation cost of the GT_MDARR_LOWER_BOUND (array length) node so that it matches the cost of an IND(ADD(addr, smallCns)) sequence, improving both performance scoring and code size estimates.

  • Revised the explanatory comment to reference the IND(ADD(...)) pattern.
  • Increased costEx by 2 (from IND_COST_EX - 1 to IND_COST_EX + 1).
  • Updated costSz from 2 to 4 (2 * 2).

@EgorBo
Copy link
Member Author

EgorBo commented Jul 11, 2025

@dotnet/jit-contrib @jakobbotsch opinions on this? diffs imply it's a perfscore improvement.

@EgorBo EgorBo requested a review from jakobbotsch July 11, 2025 06:32
@jakobbotsch
Copy link
Member

@dotnet/jit-contrib @jakobbotsch opinions on this? diffs imply it's a perfscore improvement.

Can you spot check some of the size regressions that are perfscore improvements? What happens in them and do they look beneficial?

I am fine with this change.

@EgorBo
Copy link
Member Author

EgorBo commented Jul 14, 2025

Can you spot check some of the size regressions that are perfscore improvements? What happens in them and do they look beneficial?

@jakobbotsch so my motivation to was to use more of LCL_VAR because those support constant folding with help of assertions, e.g.:

if (arr.Length == 10)
{
    memcpy(,, arr.Length); // I want to unroll this one.
}

in this case if it gets CSE'd then the assert-prop kicks in, if it's not - it doesn't. I actually tried to fix assertprop by just supporting ARR_LENGTH folding, but diffs were not nice #117505

Many size regressions seem to be caused by extra push+pop instructions for callee-saved registers used for extra CSEs. e.g.:

image

@EgorBo EgorBo merged commit 5c17036 into dotnet:main Jul 14, 2025
112 checks passed
@EgorBo EgorBo deleted the change-cost-of-arr-len branch July 14, 2025 22:06
EgorBo added a commit to EgorBo/runtime-1 that referenced this pull request Aug 13, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Aug 14, 2025
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.

2 participants