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

Undo the Const < (uint)span.Length hacks in the BCL #49450

Conversation

SingleAccretion
Copy link
Contributor

With #40180 having been merged for some time (many thanks to @nathan-moore!), the if (Const < (uint)span.Length) pattern and its permutations can now be get rid of in the BCL. A quick regex search found the following places:

System.Private.CoreLib\src\System\Buffers\Text\Utf8Parser\Utf8Parser.Boolean.cs:44:    if (4 < (uint)source.Length)
System.Private.CoreLib\src\System\Text\Unicode\Utf8.cs:105:                            if (2 >= (uint)destination.Length)
System.Private.CoreLib\src\System\Text\EncoderFallback.cs:137:                         if (1 < (uint)chars.Length)
System.Private.CoreLib\src\System\Text\Rune.cs:319:                                    if (1 < (uint)source.Length)
System.Private.CoreLib\src\System\Text\Rune.cs:820:                                    if (1 >= (uint)input.Length)

I have manually verified that the codegen for them and the equivalent "natural" versions is the same on the main branch (even without the casts).

cc @GrabYourPitchforks

Do we know of any other places that may have similar things lying around?

@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 10, 2021
@SingleAccretion SingleAccretion force-pushed the Undo-Unnatural-Comparisons-With-Length branch from 3be8d15 to b7be1d2 Compare March 10, 2021 21:03
@benaadams
Copy link
Member

Do we know of any other places that may have similar things lying around?

https://github.com/dotnet/aspnetcore

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Nice!

@GrabYourPitchforks
Copy link
Member

Huh, I'm still getting the bad codegen in sharplab (see here). Did the JIT fix miss the 5.0 RTM cutoff?

That said, the change LGTM. But we do need to be mindful that we're not going to regress performance if we change code that's being cross-compiled for many different runtimes: some of which have the fix and some of which don't. It's relevant here because just the other day I started an internal thread asking if we should make an OOB System.Text.Rune package.

Copy link
Member

@GrabYourPitchforks GrabYourPitchforks left a comment

Choose a reason for hiding this comment

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

LGTM, but see comment at #49450 (comment).

@benaadams
Copy link
Member

Huh, I'm still getting the bad codegen in sharplab (see here). Did the JIT fix miss the 5.0 RTM cutoff?

#40180 was milestoned 6.0 and the last improvement was merged 28 days ago #43568 so I assume so?

@benaadams
Copy link
Member

benaadams commented Mar 10, 2021

Using @EgorBo's Disasmo with current dotnet/runtime; it looks like the only difference between the two is jbe vs jle

image

@GrabYourPitchforks
Copy link
Member

Argh, I completely forgot about Egor's Disasmo tool! Thank you for the timely reminder. 🚀

@GrabYourPitchforks
Copy link
Member

Networking unit test failures are described at #48758 (comment).

@SingleAccretion SingleAccretion force-pushed the Undo-Unnatural-Comparisons-With-Length branch from b7be1d2 to 5a3674f Compare March 11, 2021 10:37
@stephentoub stephentoub merged commit 2f2614f into dotnet:main Mar 11, 2021
@SingleAccretion SingleAccretion deleted the Undo-Unnatural-Comparisons-With-Length branch March 12, 2021 15:20
@ghost ghost locked as resolved and limited conversation to collaborators Apr 11, 2021
@JulieLeeMSFT JulieLeeMSFT added this to the 6.0.0 milestone Apr 15, 2021
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.

6 participants