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: Handle GT_CNS_LNG and GT_CNS_DBL in GenTree::Compare #102137

Merged
merged 1 commit into from May 13, 2024

Conversation

jakobbotsch
Copy link
Member

No description provided.

@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 May 12, 2024
Copy link
Contributor

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

@jakobbotsch jakobbotsch marked this pull request as ready for review May 13, 2024 07:59
@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib

Diffs

@jakobbotsch jakobbotsch merged commit 2cf4431 into dotnet:main May 13, 2024
107 checks passed
@jakobbotsch jakobbotsch deleted the gentree-compare-cns branch May 13, 2024 08:01

case GT_CNS_DBL:
{
if (op1->AsDblCon()->isBitwiseEqual(op2->AsDblCon()))
Copy link
Member

Choose a reason for hiding this comment

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

What’s the intent of GenTree::Compare here?

I feel like having an explanatory comment around why this type of comparison is fine for double is really necessary to elaborate on why NaN == NaN is okay for bitwise equivalent.

Such a comment would also help clarify if this could be updated to be more or less inclusive based on IEEE 754/ECMA 335 rules and whether or not this needs to ensure that float vs double typing for CNS_DBL needs to be considered since we only have the one node

Copy link
Member Author

Choose a reason for hiding this comment

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

GenTree::Compare returns true if two trees are identical. This comment already exists on the function itself.

Copy link
Member

Choose a reason for hiding this comment

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

There seems to be a lot of potentially dangerous nuance here.

Just looking at many of the callers, many (but not all) are having to explicitly skip handling of floating-point or NaNs/etc themselves when considering GenTree::Compare. It seems like one of those cases where it might be applicable to simply say that two floating-point nodes containing NaN are not equal ever and otherwise only if bitwise equal; just to help avoid potential problems.

Copy link
Member

Choose a reason for hiding this comment

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

gtFoldExprCompare for example uses this to see "if two trees are identical, then folding is possible"

but of course it has to manually account for floating-point and skip it today, when in practice it could do it for everything except NaN (although even NaN can be folded in many cases in practice since we know such comparisons always produce false)

Copy link
Member Author

Choose a reason for hiding this comment

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

GenTree::Compare is a syntactic equality check. It does not say anything about whether two trees compute to the same value under any form of comparison. This is a fundamental property of syntax vs semantics that callers need to take into account when they make use of it. For example, two syntactically identical calls for obvious reasons are not guaranteed to evaluate to the same value, even though GenTree::Compare returns true for them.

I do not see a good reason to pessimize GenTree::Compare for the callers that do use it correctly (like tail/head merging) to account for other callers potentially using it incorrectly. Those other callers should be fixed to realize that fundamentally GenTree::Compare cannot be used to guarantee in general that two trees produce the same value under any form of comparison.

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.

None yet

3 participants