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] ARM64 - Overflow check optimizations for division #82924

Merged
merged 29 commits into from
Mar 10, 2023

Conversation

TIHan
Copy link
Contributor

@TIHan TIHan commented Mar 3, 2023

Description

Resolves #46010

This PR will not emit an arithmetic exception block if we know the dividend of a division operation is constant and not a MinValue.

This PR will also shorten the emitted code when testing for an overflow of a division operation.

Acceptance Criteria

  • CI passes

@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 Mar 3, 2023
@ghost ghost assigned TIHan Mar 3, 2023
@ghost
Copy link

ghost commented Mar 3, 2023

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

Issue Details

Will resolve #46010

At the moment, I haven't got rid of the redundant branch operations yet.

Author: TIHan
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@TIHan TIHan changed the title [ARM64] Overflow check optimizations [JIT] ARM64 - Overflow check optimizations Mar 3, 2023
@TIHan TIHan changed the title [JIT] ARM64 - Overflow check optimizations [JIT] ARM64 - Overflow check optimizations for division Mar 3, 2023
@TIHan TIHan marked this pull request as ready for review March 6, 2023 20:51
@TIHan
Copy link
Contributor Author

TIHan commented Mar 6, 2023

@dotnet/jit-contrib @kunalspathak This is ready. Straight-forward change, should be an easy review. Diffs

src/coreclr/jit/morph.cpp Outdated Show resolved Hide resolved
}
}

if (checkDividend)
Copy link
Member

Choose a reason for hiding this comment

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

NOTE: this still leaves overflow block alive if it's unused but presumably it's a different issue

Copy link
Member

Choose a reason for hiding this comment

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

Hhm, won't it be dead code eliminated?

Copy link
Contributor

@SingleAccretion SingleAccretion Mar 6, 2023

Choose a reason for hiding this comment

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

Throw helper blocks are marked as no-remove. This is because they aren't rooted in the normal flowgraph (the edges from the throwing nodes to the throw helper blocks are implicit).

Copy link
Member

Choose a reason for hiding this comment

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

Hhm, won't it be dead code eliminated?

these blocks are special, they have BBF_DONT_REMOVE or something like that. We spawn them early in importer/morph and then tie to corresponding divisions if needed, it's too late to remove them in codegen

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm hopeful that this PR will resolve those cases as it's already happening today.

// Return Value:
// true if the given tree is known to never be negative one
//
bool GenTree::IsNeverNegativeOne(Compiler* comp) const
Copy link
Member

@EgorBo EgorBo Mar 6, 2023

Choose a reason for hiding this comment

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

this helper is only needed for division in one place it seems?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's only in one place, but it does help make things clean.

src/coreclr/jit/gentree.cpp Outdated Show resolved Hide resolved
src/coreclr/jit/emitarm64.cpp Outdated Show resolved Hide resolved
@ghost ghost added the needs-author-action An issue or pull request that requires more info or actions from the author. label Mar 7, 2023
@ghost ghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Mar 7, 2023
src/coreclr/jit/morph.cpp Outdated Show resolved Hide resolved
@TIHan
Copy link
Contributor Author

TIHan commented Mar 8, 2023

@dotnet/jit-contrib @BruceForstall This is ready again. Diffs

src/coreclr/jit/gentree.h Outdated Show resolved Hide resolved
src/coreclr/jit/morph.cpp Outdated Show resolved Hide resolved
src/coreclr/jit/gentree.cpp Outdated Show resolved Hide resolved
TIHan and others added 3 commits March 8, 2023 09:43
…Flags. Use GetExceptionSetFlags to determine to add div-by-zero or overflow blocks for arm64.
@TIHan
Copy link
Contributor Author

TIHan commented Mar 8, 2023

Thank you all for the feedback. The PR feels a lot better.

Since @SingleAccretion pointed me to OperExceptions, I realized we had another duplicate check.

I wonder if there are any more duplicate checks.

@TIHan
Copy link
Contributor Author

TIHan commented Mar 8, 2023

@dotnet/jit-contrib ready again. Got more wins in full-opts compared to before: diffs
Current failure is not related.

Copy link
Member

@BruceForstall BruceForstall left a comment

Choose a reason for hiding this comment

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

Wouldn't be a bad idea to run outerloop and/or jitstress

src/coreclr/jit/gentree.cpp Outdated Show resolved Hide resolved
@TIHan
Copy link
Contributor Author

TIHan commented Mar 9, 2023

/azp run runtime-coreclr jitstress gcstress

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@TIHan
Copy link
Contributor Author

TIHan commented Mar 9, 2023

/azp run runtime-coreclr jitstress

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@TIHan
Copy link
Contributor Author

TIHan commented Mar 9, 2023

/azp run runtime-coreclr gcstress

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@TIHan
Copy link
Contributor Author

TIHan commented Mar 9, 2023

/azp run fuzzlyn

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@TIHan
Copy link
Contributor Author

TIHan commented Mar 10, 2023

@jakobbotsch - I think it's fine that we do this optimization in min-opts, we were already doing it before. It's not going to hurt the debugging experience for users as its all generated internally; I don't see how this would impact anyone.

@TIHan TIHan merged commit 9364575 into dotnet:main Mar 10, 2023
@TIHan TIHan deleted the redundant-overflow-branch-opt branch March 10, 2023 00:42
@ghost ghost locked as resolved and limited conversation to collaborators Apr 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.

[RyuJIT][ARM] Redundant overflow check in "C / X"
6 participants