JIT is missing a common case to track the IsNeverNegative assertion #102088
Labels
area-CodeGen-coreclr
CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
tenet-performance
Performance related issue
Milestone
Given the following code:
We currently generate the same assembly:
This is due to the
if (y < 0) { return y; }
check inM1
allowing the JIT to determine thaty
isnever negative
when it comes to they % 8
expression.However, in the case of the the following:
We instead generate the following for the
y % 8
:This is unexpected since
x[y]
for bothSpan<T>
andT[]
is known to require a positive index and to throw if the index is not positive or greater thanLength
(i.e the bounds check fails). As such, it should be possible for the JIT to assert thaty
is never negative after it is successfully used as an index into a span or array.While the code example given above is minimal and not necessarily representative of real world code, there are many places where such an index is used for latter indexing or computation and thus tracking the fact can lead to other downstream codegen improvements (whether that be simplified bounds checks elsewhere or optimizations such as is done for
%
).The text was updated successfully, but these errors were encountered: