Skip to content

JIT: Add morphing to LE_UN/GT_UN(expr, uint.MaxValue) (dotnet#76525) #113037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 19, 2025

Conversation

shunkino
Copy link
Contributor

@shunkino shunkino commented Mar 2, 2025

Add morphing for comparison between uint.MaxValue and a ulong value.

Contribute to: #76525

@Copilot Copilot AI review requested due to automatic review settings March 2, 2025 00:09
@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 2, 2025
Copy link
Contributor

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 2, 2025
Copy link
Contributor

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

@shunkino
Copy link
Contributor Author

shunkino commented Mar 2, 2025

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

@EgorBo
Copy link
Member

EgorBo commented Mar 2, 2025

Seems like CI failed with

 ISSUE: <ASSERT> #263216 D:\a\_work\1\s\src\coreclr\jit\codegenxarch.cpp (4912) - Assertion failed 'operandReg != REG_RCX' in 'bug.Program:TestEntryPoint():int' during 'Generate code' (IL size 42; hash 0x8feb9733; FullOpts)

@jakobbotsch
Copy link
Member

Seems like CI failed with

 ISSUE: <ASSERT> #263216 D:\a\_work\1\s\src\coreclr\jit\codegenxarch.cpp (4912) - Assertion failed 'operandReg != REG_RCX' in 'bug.Program:TestEntryPoint():int' during 'Generate code' (IL size 42; hash 0x8feb9733; FullOpts)

That's probably because this PR isn't handling the things pointed out here: #76525 (comment)

@shunkino
Copy link
Contributor Author

Seems like CI failed with

 ISSUE: <ASSERT> #263216 D:\a\_work\1\s\src\coreclr\jit\codegenxarch.cpp (4912) - Assertion failed 'operandReg != REG_RCX' in 'bug.Program:TestEntryPoint():int' during 'Generate code' (IL size 42; hash 0x8feb9733; FullOpts)

That's probably because this PR isn't handling the things pointed out here: #76525 (comment)

Thank you for pointing it out. Will check the issue comment and fix.

@shunkino shunkino force-pushed the jit-uint-maxvalue-compare-76525 branch 2 times, most recently from 4fe1edc to 907e97c Compare March 25, 2025 05:09
@jakobbotsch
Copy link
Member

There are some cases in the diffs where the optimization is not kicking in:
image

Can you check why?

@jakobbotsch
Copy link
Member

I just noticed that the above was a tier 0 method. It looks like fgOptimizeRelationalComparisonWithConst runs even in tier 0.
Can you add an OptimizationEnabled check to the case you are introducing in fgOptimizeRelationalComparisonWithConst since it relies on further optimizations in the backend to happen?

* Add morphing for comparison between uint.MaxValue and a ulong value.
* Remove assertions, which no longer is relevant.
* Add a check to lsra to only use BMI2 if zero flag will not be set.
* Add a profitability check to optimize EQ/NE(op, 0) only if op has constant operand.
@shunkino shunkino force-pushed the jit-uint-maxvalue-compare-76525 branch from 907e97c to 440adf9 Compare March 31, 2025 15:58
@jakobbotsch
Copy link
Member

/azp run Fuzzlyn

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@shunkino
Copy link
Contributor Author

Hi @jakobbotsch, I tried to review the Fuzzlyn results, but there are many errors that I’m having trouble interpreting. Sorry to bother you, but could you help me understand what they mean or guide me on how to proceed? Thanks in advance!

@jakobbotsch
Copy link
Member

I think the Fuzzlyn found issues are unrelated to this PR. I need to take another look, but I don't think anything more is needed from your side.

@jakobbotsch jakobbotsch self-requested a review April 17, 2025 09:43
@jakobbotsch jakobbotsch reopened this May 13, 2025
@shunkino
Copy link
Contributor Author

@jakobbotsch
Updated the code as in this comment, which I believe will stop rorx to be emitted when the flag is set.
However, CI is failing with following error, and I am not sure if this is caused by the same issue as the previous one. Maybe it's better to !tree->gtSetFlags() put on line 4866?

D:\a\_work\1\s\.packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\download-results\DownloadFromResultsContainer.targets(24,5): warning : Work item windows-arm64-5 in Job 7939f69d-64e1-4a53-9cdd-a225d06233b7 did not upload a result file with path 'superpmi_final_windows_arm64_5.log'  [D:\a\_work\1\s\src\coreclr\scripts\superpmi-replay.proj]
##[warning].packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\download-results\DownloadFromResultsContainer.targets(24,5): warning : (NETCORE_ENGINEERING_TELEMETRY=Build) Work item windows-arm64-5 in Job 7939f69d-64e1-4a53-9cdd-a225d06233b7 did not upload a result file with path 'superpmi_final_windows_arm64_5.log' 
D:\a\_work\1\s\.packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\download-results\DownloadFromResultsContainer.targets(24,5): warning : Work item linux-x64-5 in Job 7939f69d-64e1-4a53-9cdd-a225d06233b7 did not upload a result file with path 'superpmi_final_linux_x64_5.log'  [D:\a\_work\1\s\src\coreclr\scripts\superpmi-replay.proj]
##[warning].packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\download-results\DownloadFromResultsContainer.targets(24,5): warning : (NETCORE_ENGINEERING_TELEMETRY=Build) Work item linux-x64-5 in Job 7939f69d-64e1-4a53-9cdd-a225d06233b7 did not upload a result file with path 'superpmi_final_linux_x64_5.log' 
D:\a\_work\1\s\.packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\download-results\DownloadFromResultsContainer.targets(24,5): warning : Work item linux-arm64-1 in Job 7939f69d-64e1-4a53-9cdd-a225d06233b7 did not upload a result file with path 'superpmi_final_linux_arm64_1.log'  [D:\a\_work\1\s\src\coreclr\scripts\superpmi-replay.proj]
##[warning].packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\download-results\DownloadFromResultsContainer.targets(24,5): warning : (NETCORE_ENGINEERING_TELEMETRY=Build) Work item linux-arm64-1 in Job 7939f69d-64e1-4a53-9cdd-a225d06233b7 did not upload a result file with path 'superpmi_final_linux_arm64_1.log' 
D:\a\_work\1\s\.packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\Microsoft.DotNet.Helix.Sdk.MultiQueue.targets(91,5): error : Work item windows-arm64-5 in job 7939f69d-64e1-4a53-9cdd-a225d06233b7 has failed. [D:\a\_work\1\s\src\coreclr\scripts\superpmi-replay.proj]
D:\a\_work\1\s\.packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\Microsoft.DotNet.Helix.Sdk.MultiQueue.targets(91,5): error : Failure log: https://helix.dot.net/api/2019-06-17/jobs/7939f69d-64e1-4a53-9cdd-a225d06233b7/workitems/windows-arm64-5/console [D:\a\_work\1\s\src\coreclr\scripts\superpmi-replay.proj]
##[error].packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\Microsoft.DotNet.Helix.Sdk.MultiQueue.targets(91,5): error : (NETCORE_ENGINEERING_TELEMETRY=Test) Work item windows-arm64-5 in job 7939f69d-64e1-4a53-9cdd-a225d06233b7 has failed.
Failure log: https://helix.dot.net/api/2019-06-17/jobs/7939f69d-64e1-4a53-9cdd-a225d06233b7/workitems/windows-arm64-5/console
D:\a\_work\1\s\.packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\Microsoft.DotNet.Helix.Sdk.MultiQueue.targets(91,5): error : Work item linux-x64-5 in job 7939f69d-64e1-4a53-9cdd-a225d06233b7 has failed. [D:\a\_work\1\s\src\coreclr\scripts\superpmi-replay.proj]
D:\a\_work\1\s\.packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\Microsoft.DotNet.Helix.Sdk.MultiQueue.targets(91,5): error : Failure log: https://helix.dot.net/api/2019-06-17/jobs/7939f69d-64e1-4a53-9cdd-a225d06233b7/workitems/linux-x64-5/console [D:\a\_work\1\s\src\coreclr\scripts\superpmi-replay.proj]
##[error].packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\Microsoft.DotNet.Helix.Sdk.MultiQueue.targets(91,5): error : (NETCORE_ENGINEERING_TELEMETRY=Test) Work item linux-x64-5 in job 7939f69d-64e1-4a53-9cdd-a225d06233b7 has failed.
Failure log: https://helix.dot.net/api/2019-06-17/jobs/7939f69d-64e1-4a53-9cdd-a225d06233b7/workitems/linux-x64-5/console
D:\a\_work\1\s\.packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\Microsoft.DotNet.Helix.Sdk.MultiQueue.targets(91,5): error : Work item linux-arm64-1 in job 7939f69d-64e1-4a53-9cdd-a225d06233b7 has failed. [D:\a\_work\1\s\src\coreclr\scripts\superpmi-replay.proj]
D:\a\_work\1\s\.packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\Microsoft.DotNet.Helix.Sdk.MultiQueue.targets(91,5): error : Failure log: https://helix.dot.net/api/2019-06-17/jobs/7939f69d-64e1-4a53-9cdd-a225d06233b7/workitems/linux-arm64-1/console [D:\a\_work\1\s\src\coreclr\scripts\superpmi-replay.proj]
##[error].packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\Microsoft.DotNet.Helix.Sdk.MultiQueue.targets(91,5): error : (NETCORE_ENGINEERING_TELEMETRY=Test) Work item linux-arm64-1 in job 7939f69d-64e1-4a53-9cdd-a225d06233b7 has failed.
Failure log: https://helix.dot.net/api/2019-06-17/jobs/7939f69d-64e1-4a53-9cdd-a225d06233b7/workitems/linux-arm64-1/console

Build FAILED.

D:\a\_work\1\s\.packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\Microsoft.DotNet.Helix.Sdk.MultiQueue.targets(91,5): error : Work item windows-x86-2 in job 0a2adfdf-7c7c-4448-aec1-9542581eb56e has failed. [D:\a\_work\1\s\src\coreclr\scripts\superpmi-replay.proj]
D:\a\_work\1\s\.packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\Microsoft.DotNet.Helix.Sdk.MultiQueue.targets(91,5): error : Failure log: https://helix.dot.net/api/2019-06-17/jobs/0a2adfdf-7c7c-4448-aec1-9542581eb56e/workitems/windows-x86-2/console [D:\a\_work\1\s\src\coreclr\scripts\superpmi-replay.proj]
##[error].packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\Microsoft.DotNet.Helix.Sdk.MultiQueue.targets(91,5): error : (NETCORE_ENGINEERING_TELEMETRY=Test) Work item windows-x86-2 in job 0a2adfdf-7c7c-4448-aec1-9542581eb56e has failed.
Failure log: https://helix.dot.net/api/2019-06-17/jobs/0a2adfdf-7c7c-4448-aec1-9542581eb56e/workitems/windows-x86-2/console
D:\a\_work\1\s\.packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\Microsoft.DotNet.Helix.Sdk.MultiQueue.targets(91,5): error : Work item windows-x86-6 in job 0a2adfdf-7c7c-4448-aec1-9542581eb56e has failed. [D:\a\_work\1\s\src\coreclr\scripts\superpmi-replay.proj]
D:\a\_work\1\s\.packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\Microsoft.DotNet.Helix.Sdk.MultiQueue.targets(91,5): error : Failure log: https://helix.dot.net/api/2019-06-17/jobs/0a2adfdf-7c7c-4448-aec1-9542581eb56e/workitems/windows-x86-6/console [D:\a\_work\1\s\src\coreclr\scripts\superpmi-replay.proj]
##[error].packages\microsoft.dotnet.helix.sdk\10.0.0-beta.25260.104\tools\Microsoft.DotNet.Helix.Sdk.MultiQueue.targets(91,5): error : (NETCORE_ENGINEERING_TELEMETRY=Test) Work item windows-x86-6 in job 0a2adfdf-7c7c-4448-aec1-9542581eb56e has failed.
Failure log: https://helix.dot.net/api/2019-06-17/jobs/0a2adfdf-7c7c-4448-aec1-9542581eb56e/workitems/windows-x86-6/console

Build FAILED.

@shunkino
Copy link
Contributor Author

Try moving !tree->gtSetFlags() to line 4866...

@jakobbotsch
Copy link
Member

@shunkino No, I think your other fix was better. I think the failures were #115644, unrelated to your change.

@shunkino
Copy link
Contributor Author

@jakobbotsch Thanks for checking. Reverted the change to the one I commented here.

@jakobbotsch
Copy link
Member

/azp run runtime-coreclr superpmi-replay

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jakobbotsch
Copy link
Member

The failure is #115070, not sure why it is not being picked up automatically.

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.

Thank you for your work on this!

@jakobbotsch
Copy link
Member

/ba-g Failure is #115070

@jakobbotsch jakobbotsch merged commit d94ebe0 into dotnet:main May 19, 2025
109 of 113 checks passed
@AndyAyersMS
Copy link
Member

FYI jit-format failed here. I will fix as part of #115731.

@jakobbotsch
Copy link
Member

jakobbotsch commented May 19, 2025

Weird, looks like it failed 7 minutes after I merged this. Not sure why the failure wasn't there before that.

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.

5 participants