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

Adding some constant folding support for basic floating-point operations #103206

Merged
merged 4 commits into from
Jun 13, 2024

Conversation

tannergooding
Copy link
Member

This covers operations where it is safe to do so in the face of NaN and +0 vs -0.

@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 Jun 9, 2024
Copy link
Contributor

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

@tannergooding tannergooding marked this pull request as ready for review June 9, 2024 19:16
@tannergooding
Copy link
Member Author

CC. @dotnet/jit-contrib, just as the title indicates this enables constant folding for floating-point where it's applicable to do. Namely this applies to NaN propagation and a few cases where operations with 0, -0, or 1 are safe for all inputs. It adds comments indicating which common scenarios we can't handle and why.

With the NaN propagation, it should be possible to also introduce (in a future PR) a minimal FloatingRange equivalent to IntegralRange and do some very basic optimizations in the space. For example, if the user has an if (float.IsNaN(x)) { return ...; } check, then there are other optimizations we can enable to reduce the total number of branches and other handling. -- I'm working on a prototype of this locally as it can have some meaningful impact to ML and other scenarios

src/coreclr/jit/gentree.cpp Outdated Show resolved Hide resolved

if (FloatingPointUtils::isNaN(val))
{
if (opHasSideEffects)
Copy link
Member

Choose a reason for hiding this comment

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

There is a convinient API that can help with side-effects, e.g. in this case it's:

gtWrapWithSideEffects(nanCns, op, GTF_ALL_EFFECT);

it's also fine to conservatively give up on them if it doesn't affect diffs I guess

Copy link
Member Author

Choose a reason for hiding this comment

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

👍, didn't realize we had a helper for this. I've updated it, might get a follow up PR that looks to do the same for the integer folding.

Copy link
Member

@EgorBo EgorBo left a comment

Choose a reason for hiding this comment

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

LGTM with a few comments in gtFoldExprSpecialFloating

@tannergooding tannergooding merged commit 2c540e5 into dotnet:main Jun 13, 2024
103 of 107 checks passed
@tannergooding tannergooding deleted the jit-nan branch June 13, 2024 02:12
@github-actions github-actions bot locked and limited conversation to collaborators Jul 13, 2024
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