Open MineCake147E opened 6 months ago
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch See info in area-owners.md if you want to be subscribed.
Are these some real-world patterns?
The code below subtracts the first element from the last element, both from the span-like object (but not actual ReadOnlySpan<T>
) span
, where the index and Length
are both nuint
.
The indexer introduces some unsigned range checks, despite the length is already checked by span.Length != 0
.
if (span.Length != 0)
{
return span[span.Length - 1] - span[0];
}
Description
I noticed that RyuJIT doesn't even optimize some simple comparison against unsigned integers.
Case 1:
value - N < value
is equivalent tovalue > N - 1
for anyN
Consider this code:
The
QTest0
could just bebut it is:
And the
QTest1
could just bebut it is:
Case 2:
(value - N) != value
is equivalent toN != 0
Consider this code:
The RyuJIT currently generates the code below:
In this case,
RTest0
andRTest1
could just returntrue
without checking anything.Configuration
SharpLab
Regression?
Unknown
Data
Analysis