-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Assist JIT in eliminating bounds checks #81036
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -44,7 +44,7 @@ private static bool TryParseNumber(ReadOnlySpan<byte> source, ref Number.NumberB | |||
|
|
||||
| case Utf8Constants.Plus: | ||||
| srcIndex++; | ||||
| if (srcIndex == source.Length) | ||||
| if (srcIndex >= source.Length) | ||||
| { | ||||
| bytesConsumed = 0; | ||||
| return false; | ||||
|
|
@@ -61,7 +61,7 @@ private static bool TryParseNumber(ReadOnlySpan<byte> source, ref Number.NumberB | |||
| int maxDigitCount = digits.Length - 1; | ||||
|
|
||||
| // Throw away any leading zeroes | ||||
| while (srcIndex != source.Length) | ||||
| while (srcIndex < source.Length) | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do these need
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case casts appear to regress bounds check elimination. Perhaps this is unnecessary because runtime/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Parser/Utf8Parser.Number.cs Line 34 in ce18ccf
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can you elaborate? I wouldn't expect this to remove the bounds check on
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already do checks on
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still don't understand what you mean. Can you share a sharplab.io example?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@tannergooding For future reference, does the codegen from Compiler Explorer have the same optimizations as a local disassembly using .NET 8 nightly build. Currently, .e.g. https://csharp.godbolt.org/z/cKhTfjvqd, seems to be using:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xtqqczze for godbolt you need to pass
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@EgorBo Not seeing any differeences in codegen for this example: https://csharp.godbolt.org/z/cKhTfjvqd, is this expected?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. However, its showing the crossgen code and so isn't strictly the same as what sharplab shows or what a user will see for Tier 1 codegen. You can customize the instruction set targeted and I'd recommend using You can customize the OS: and in general pass in other options supported by crossgen (such as
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tannergooding Great help with your tips, I knew about the parameters but couldn't find a useful reference with a search engine. |
||||
| { | ||||
| c = source[srcIndex]; | ||||
| if (c != '0') | ||||
|
|
@@ -79,7 +79,7 @@ private static bool TryParseNumber(ReadOnlySpan<byte> source, ref Number.NumberB | |||
| int startIndexNonLeadingDigitsBeforeDecimal = srcIndex; | ||||
|
|
||||
| int hasNonZeroTail = 0; | ||||
| while (srcIndex != source.Length) | ||||
| while (srcIndex < source.Length) | ||||
| { | ||||
| c = source[srcIndex]; | ||||
| int value = (byte)(c - (byte)('0')); | ||||
|
|
@@ -134,7 +134,7 @@ private static bool TryParseNumber(ReadOnlySpan<byte> source, ref Number.NumberB | |||
| srcIndex++; | ||||
| int startIndexDigitsAfterDecimal = srcIndex; | ||||
|
|
||||
| while (srcIndex != source.Length) | ||||
| while (srcIndex < source.Length) | ||||
| { | ||||
| c = source[srcIndex]; | ||||
| int value = (byte)(c - (byte)('0')); | ||||
|
|
@@ -268,7 +268,7 @@ private static bool TryParseNumber(ReadOnlySpan<byte> source, ref Number.NumberB | |||
| // continue eating digits from there | ||||
| srcIndex += 10; | ||||
|
|
||||
| while (srcIndex != source.Length) | ||||
| while (srcIndex < source.Length) | ||||
| { | ||||
| c = source[srcIndex]; | ||||
| int value = (byte)(c - (byte)('0')); | ||||
|
|
||||
Uh oh!
There was an error while loading. Please reload this page.