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

Ensure Max/Min for floating-point on x86/x64 are not handled as commutative #75683

Merged
merged 3 commits into from
Sep 16, 2022

Conversation

tannergooding
Copy link
Member

This resolves the ImageSharp bug tracked by SixLabors/ImageSharp#2117

This is a decently old bug and was introduced about 5 years ago in: dotnet/coreclr@654a8d5

This means that it exists in .NET 3.1, .NET 5 (out of support), and .NET 6.

We should "at minimum" backport this to .NET 7 RTM. We should also consider backporting to .NET 6 since it is LTS and still has a couple years of support (until Dec 2024). I don't think this is needed for .NET Core 3.1 since it goes out of support in December.

@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 Sep 15, 2022
@ghost ghost assigned tannergooding Sep 15, 2022
@ghost
Copy link

ghost commented Sep 15, 2022

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

Issue Details

This resolves the ImageSharp bug tracked by SixLabors/ImageSharp#2117

This is a decently old bug and was introduced about 5 years ago in: dotnet/coreclr@654a8d5

This means that it exists in .NET 3.1, .NET 5 (out of support), and .NET 6.

We should "at minimum" backport this to .NET 7 RTM. We should also consider backporting to .NET 6 since it is LTS and still has a couple years of support (until Dec 2024). I don't think this is needed for .NET Core 3.1 since it goes out of support in December.

Author: tannergooding
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

Comment on lines +18670 to +18697
if (HWIntrinsicInfo::IsMaybeCommutative(id))
{
switch (id)
{
case NI_SSE_Max:
case NI_SSE_Min:
{
return false;
}

case NI_SSE2_Max:
case NI_SSE2_Min:
{
return !varTypeIsFloating(node->GetSimdBaseType());
}

case NI_AVX_Max:
case NI_AVX_Min:
{
return false;
}

default:
{
unreached();
}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I've kept this "simple" since we need to backport into .NET 7.

It isn't just a "return false", however, because we will want to specially handle the case in .NET 8 since certain scenarios can be commutative and this makes the follow up PR significantly simpler.

#endif // TARGET_XARCH

return false;
Copy link
Member Author

@tannergooding tannergooding Sep 15, 2022

Choose a reason for hiding this comment

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

Notably Arm64 is returning constant false and it shouldn't be. Given this needs to be backported to .NET 7, I didn't "fix" this (its not a correctness bug, just a case where we might generate "worse" codegen).

I plan on putting up a follow up PR to ensure Arm64 intrinsics are handled as commutative (they are already correctly marked as required, this function returning false is the blocker for them)

@tannergooding
Copy link
Member Author

superpmi is a failure to upload logs for the x86 job.
llvmaot is the known issue #75606

@tannergooding tannergooding merged commit 90ddd5e into dotnet:main Sep 16, 2022
@tannergooding
Copy link
Member Author

/backport to release/7.0-rc2

@github-actions
Copy link
Contributor

Started backporting to release/7.0-rc2: https://github.com/dotnet/runtime/actions/runs/3069189452

@tannergooding
Copy link
Member Author

/backport to release/6.0

@github-actions
Copy link
Contributor

Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/3070029740

@github-actions
Copy link
Contributor

@tannergooding backporting to release/6.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Adding a regression test for sixlabors/imagesharp#2117
Applying: Ensure Max/Min for floating-point on x86/x64 are not handled as commutative
Using index info to reconstruct a base tree...
M	src/coreclr/jit/gentree.cpp
M	src/coreclr/jit/hwintrinsic.h
M	src/coreclr/jit/hwintrinsiclistxarch.h
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/jit/hwintrinsiclistxarch.h
Auto-merging src/coreclr/jit/hwintrinsic.h
Auto-merging src/coreclr/jit/gentree.cpp
CONFLICT (content): Merge conflict in src/coreclr/jit/gentree.cpp
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0002 Ensure Max/Min for floating-point on x86/x64 are not handled as commutative
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

tannergooding added a commit to tannergooding/runtime that referenced this pull request Sep 16, 2022
…tative (dotnet#75683)

* Adding a regression test for SixLabors/ImageSharp#2117

* Ensure Max/Min for floating-point on x86/x64 are not handled as commutative

* Applying formatting patch
carlossanlop pushed a commit that referenced this pull request Oct 5, 2022
…ndled as commutative (#75772)

* Ensure Max/Min for floating-point on x86/x64 are not handled as commutative (#75683)

* Adding a regression test for SixLabors/ImageSharp#2117

* Ensure Max/Min for floating-point on x86/x64 are not handled as commutative

* Applying formatting patch

* Directly access the gtHWIntrinsicId field since the helper method doesn't exist in .NET 6

* Fixing a regression test to use the GetElement API available in .NET 6
@ghost ghost locked as resolved and limited conversation to collaborators Oct 16, 2022
@tannergooding tannergooding deleted the imagesharp-2117 branch November 11, 2022 15:11
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