-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional binary operations into the RangeCheck analysis. (#61662)
* Add additional binary operations into the RangeCheck analysis. GT_LSH and GT_MUL are now covered in the range analysis check. This allows to catch and eliminate the range check for cases like ``` ReadOnlySpan<byte> readOnlySpan => new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; byte byt = 0; for (int i = 0; i < 5; i++) { byt = readOnlySpan[i * 3]; // ... } ``` or ``` bool[] flags = new bool[Size + 1]; for (int i = 2; i <= Size; i++) { for (int k = i * 2; k <= Size; k += i) { flags[k] = false; } } ``` Note that without this change, the previous snippet would not eliminate the range check on `flags[k]`, but the equivalent snippet would ``` for (int i = 2; i <= Size; i++) { for (int k = i + i; k <= Size; k += i) { flags[k] = false; } } ``` as additional was implemented in the range check analysis, but multiply was not. * RangeCheck multiply overflow fix and tests. Tests catch some edge cases with multiplcation overflow IF the overflow detection isn't implemented correctly. * Use CheckedOps::Signed instead of false. * Reduced overflow test array size to more reasonable value. * Update src/coreclr/jit/rangecheck.cpp Co-authored-by: Egor Bogatov <egorbo@gmail.com> * Update src/coreclr/jit/rangecheck.cpp Co-authored-by: Egor Bogatov <egorbo@gmail.com> Co-authored-by: Egor Bogatov <egorbo@gmail.com>
- Loading branch information
1 parent
72e0da8
commit fd28c76
Showing
4 changed files
with
301 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.