-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 doesn't eliminate bounds checks on const strings #1343
Comments
Related: dotnet/coreclr#26000 |
Slightly modified version does eliminate bound check for this case: private static bool M(int pos) {
const string Str = "hello";
var tmp = Str; // temp var (should not be needed - needs a fix in JIT)
return (uint)pos < (uint)tmp.Length && tmp[pos] == 'e'; // uint cast
} |
For reference, this came up as part of my look into making our regexes go faster. We create lookup bitmaps for character sets to make it fast to check whether an ASCII character is part of a set, and we currently store that bitmap in a const string. |
Curious, what is a "gword"? Surely this must be a qword. |
The jit tracks which pointers might point into the GC heap.
|
@AndyAyersMS Thank you. I was not aware of that. That is good to know. |
Consider a method like:
The JIT is currently generating code like:
In theory it seems the JIT should be able to both a) remove the redundant bounds check (and the corresponding fallback to rngchkfail), and b) encode the string length as a constant rather than reading it from the object.
cc: @AndyAyersMS
category:cq
theme:bounds-checks
skill-level:intermediate
cost:medium
The text was updated successfully, but these errors were encountered: