Skip to content
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

[JIT] - Fixed sub-optimal optimization for a % 1 to Zero #77760

Merged
merged 25 commits into from
Dec 8, 2022

Conversation

TIHan
Copy link
Contributor

@TIHan TIHan commented Nov 2, 2022

Description

Should resolve: #10956

We already did the transformation of a % 1, but we ignored it if op1 had any side effects. This PR should fix that.

X64 Diff:
image

Acceptance Criteria

  • Disasm tests

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Nov 2, 2022
@ghost ghost assigned TIHan Nov 2, 2022
@ghost
Copy link

ghost commented Nov 2, 2022

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

Issue Details

** Description **

Should resolve: #10956

Simple optimization. Will transform a % 1 to be 0.

** Acceptance Criteria **

  • Disasm tests
Author: TIHan
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

src/coreclr/jit/morph.cpp Outdated Show resolved Hide resolved
@TIHan TIHan changed the title Optimize a % 1 to Zero [JIT] - Optimize a % 1 to Zero Nov 2, 2022
@SingleAccretion
Copy link
Contributor

Note there is already an optimization that does this:

// For "val % 1", return 0 if op1 doesn't have any side effects
// and we are not in the CSE phase, we cannot discard 'tree'
// because it may contain CSE expressions that we haven't yet examined.
//
if (((op1->gtFlags & GTF_SIDE_EFFECT) == 0) && !optValnumCSE_phase)
{
if (op2->IsIntegralConst(1))
{
GenTree* zeroNode = gtNewZeroConNode(typ);
#ifdef DEBUG
zeroNode->gtDebugFlags |= GTF_DEBUG_NODE_MORPHED;
#endif
DEBUG_DESTROY_NODE(tree);
return zeroNode;
}
}
.

@TIHan
Copy link
Contributor Author

TIHan commented Nov 2, 2022

Good catch. Will probably remove it in favor of this since it expands it.

@TIHan TIHan changed the title [JIT] - Optimize a % 1 to Zero [JIT] - Fixed sub-optimal optimization for a % 1 to Zero Nov 2, 2022
@TIHan TIHan marked this pull request as ready for review November 2, 2022 22:24
@TIHan
Copy link
Contributor Author

TIHan commented Nov 3, 2022

@dotnet/jit-contrib This is ready.

@jakobbotsch
Copy link
Member

/azp run Fuzzlyn

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@build-analysis build-analysis bot mentioned this pull request Nov 4, 2022
2 tasks
@jakobbotsch
Copy link
Member

The failures look related

@TIHan TIHan changed the title [JIT] - Fixed sub-optimal optimization for a % 1 to Zero [JIT] - Fixed sub-optimal optimization for a % 1 and a % -1 to Zero Nov 5, 2022
@TIHan
Copy link
Contributor Author

TIHan commented Nov 5, 2022

@dotnet/jit-contrib @jakobbotsch This is ready again.

@TIHan TIHan changed the title [JIT] - Fixed sub-optimal optimization for a % 1 and a % -1 to Zero [JIT] - Fixed sub-optimal optimization for a % 1 to Zero Nov 7, 2022
@TIHan
Copy link
Contributor Author

TIHan commented Nov 14, 2022

@dotnet/jit-contrib @EgorBo This is ready for review again. We update the value number for the zero node, and we disable the optimization if we are not in global morph when there are side effects.

@TIHan
Copy link
Contributor Author

TIHan commented Nov 15, 2022

@dotnet/jit-contrib ready again

@TIHan
Copy link
Contributor Author

TIHan commented Nov 28, 2022

@dotnet/jit-contrib @jakobbotsch @EgorBo This is ready again too. Fixed a minor issue when setting the integral value for GT_CNS_LNG on x86/arm.

@TIHan
Copy link
Contributor Author

TIHan commented Dec 2, 2022

@dotnet/jit-contrib This is ready for another round of review, based on our internal discussion yesterday.

Comment on lines +14 to +15
<CLRTestEnvironmentVariable Include="DOTNET_TieredCompilation" Value="0" />
<CLRTestEnvironmentVariable Include="DOTNET_JITMinOpts" Value="0" />
Copy link
Member

Choose a reason for hiding this comment

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

One thing I don't remember:

If we have <HasDisasmCheck>true<...>, why do we need to clear TieredCompilation/JITMinOpts? Shouldn't the "HasDisasmCheck" logic do that for us?

Copy link
Contributor Author

@TIHan TIHan Dec 8, 2022

Choose a reason for hiding this comment

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

<HasDisasmCheck>true<...> does not force any environment variables that affect codegen - so it is up to the test itself to decide them.

@TIHan TIHan merged commit 932221d into dotnet:main Dec 8, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jan 9, 2023
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.

Sub-optimal code when the operation "% 1" on integers is met
5 participants