Skip to content

Conversation

@dhartglassMSFT
Copy link
Contributor

@dhartglassMSFT dhartglassMSFT commented Jan 9, 2026

The increment of lzcnt (*) wasn't getting transformed to a conditional increment, because an earlier phase folds the "add local, 1" into a constant based on assertion information.

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int RuneLength(in byte value)
{
    var lzcnt = (uint)BitOperations.LeadingZeroCount(~((uint)value << 24));
    if (lzcnt is 0) lzcnt++; //*

    return (int)lzcnt;
}

Fix to allow TryLowerCnsIntCselToCinc to look cases similar to if (myvar==0)myvar=1;

fixes #96441

@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 Jan 9, 2026
@dhartglassMSFT
Copy link
Contributor Author

@dotnet-policy-service agree company="Microsoft"

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

Expands ARM64 lowering to produce more conditional-increment (cinc/csinc) patterns, especially for assignments derived from constants compared against a local.

Changes:

  • Extend TryLowerCnsIntCselToCinc to also recognize SELECTCC patterns where the “+1” value is constant relative to a CMP local/constant comparison, and rewrite to GT_SELECT_INCCC.
  • Broaden LowerSelect’s trigger to attempt this lowering when either select operand is an integer constant (not only when both are).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/coreclr/jit/lowerarmarch.cpp Adds a new lowering path to convert certain SELECTCC + CMP patterns into GT_SELECT_INCCC by substituting a local read for the constVal+1 constant.
src/coreclr/jit/lower.cpp Calls the CINC lowering helper when either select operand is an integer constant, enabling the new pattern matching.

Copy link
Member

@jakobbotsch jakobbotsch left a comment

Choose a reason for hiding this comment

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

LGTM! I will kick off Fuzzlyn which is good at testing stuff like this (it may have failures in it unrelated to this PR)

@jakobbotsch
Copy link
Member

/azp run Fuzzlyn

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jakobbotsch
Copy link
Member

I went through the Fuzzlyn failures (https://dev.azure.com/dnceng-public/public/_build/results?buildId=1268916&view=ms.vss-build-web.run-extensions-tab) and I don't see anything that obviously looks to be caused by this PR. I think you can bypass the infra issues and merge this.

@dhartglassMSFT dhartglassMSFT changed the title Arm64: Fix for 96441 Arm64: fixes #96441 Jan 28, 2026
@dhartglassMSFT dhartglassMSFT changed the title Arm64: fixes #96441 Arm64: Fix for 96441 Jan 28, 2026
@dhartglassMSFT dhartglassMSFT enabled auto-merge (squash) January 28, 2026 19:40
@dhartglassMSFT
Copy link
Contributor Author

/ba-g Known arm64 infra issues

@dhartglassMSFT dhartglassMSFT merged commit f2fa58d into dotnet:main Feb 2, 2026
116 of 125 checks passed
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.

[ARM64] CINC or CSINC is not emitted for conditional increment

2 participants