Eliminate bound checks for "% arr.Length" when possible#130156
Eliminate bound checks for "% arr.Length" when possible#130156henriquewr wants to merge 20 commits into
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
| return Range(Limit(Limit::keConstant, 0), Limit(Limit::keConstant, rightLimit)); | ||
| } | ||
|
|
||
| return Range(Limit(Limit::keConstant, 0), Limit(Limit::keUnknown)); |
There was a problem hiding this comment.
Is there a way of representing the maximum value possible? (limit is int32 in the ctor)
Im not sure how ranges above 32 bits are representable
There was a problem hiding this comment.
Rangecheck is 32bit limited.
|
CI failures are related |
| } | ||
|
|
||
| // "CheckedBnd <relop> X" | ||
| if (!isUnsignedRelop && vnStore->IsVNCheckedBound(op1VN)) |
There was a problem hiding this comment.
As far as I know adding asserts isn't free
these asserts might be taking the place of a more useful one ((uint)index <= (uint)arr.Length and (uint)arr.Length >= (uint)index)
Is doing this really a good idea?
(Also, I don't really know how often the asserts table gets full)
|
TBH, I am not sure I understand what you're doing, or rather this looks like a typical AI contribution given how AI loves to solve problems b in the jit codebase by introducing new loops over entites vs integrating into existing structures. I don't think "arr.Length % X" makes any sense in real code, "X % arrLen" does make sense, and it's supported but only for unsigned mods, it seems it should be possible to extend that logic to signed mods as well with the help of assertions, should be a very trivial change, not +300 LOC of very risky changes in an area that has a poor test coverage. |
I could be wrong, but i think you are talking about the (ugly) while loops, as far as I searched in the codebase, thats the only way of knowing if an assert is know to be applicable
Agree, i dont really think thats the mosty useful thing, but since signed operators already has all the assertions needed (<=, >=, >, <) I just implemented anyway
yeah, most of the code is the ugly loop for assertions to support the not so useful |
fixes #130155
Pattern
[index % arr.Length]:went from
to