-
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] Recognize when length is never negative for Span<T>::.ctor(void*, int32)
#83248
Comments
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch, @kunalspathak Issue DetailsI noticed this for unsafe Span<byte> M0(byte* p, byte b) => new(p, b);
unsafe Span<byte> M2(byte* p, int b) => new(p, (byte)b);
unsafe Span<byte> M3(byte* p, uint mask) => new(p, BitOperations.PopCount(mask));
unsafe Span<byte> M4(byte* p, uint mask) => new(p, (byte)BitOperations.PopCount(mask)); // crossgen2 8.0.0-preview.3.23159.99+1b2eb12a711410a358bdfa93af017a34a929d4cf
C:M0(ulong,ubyte):System.Span`1[ubyte]:this:
; Emitting BLENDED_CODE for X64 CPU with AVX - Unix
push rax
;; size=1 bbWeight=1 PerfScore 1.00
mov rax, rsi
movzx rdx, dl
;; size=6 bbWeight=1 PerfScore 0.50
add rsp, 8
ret
;; size=5 bbWeight=1 PerfScore 1.25
C:M02(ulong,int):System.Span`1[ubyte]:this:
; Emitting BLENDED_CODE for X64 CPU with AVX - Unix
push rax
;; size=1 bbWeight=1 PerfScore 1.00
movzx rdx, dl
test edx, edx
jl SHORT G_M62596_IG04
mov rax, rsi
;; size=10 bbWeight=1 PerfScore 1.75
add rsp, 8
ret
;; size=5 bbWeight=1 PerfScore 1.25
G_M62596_IG04:
call [System.ThrowHelper:ThrowArgumentOutOfRangeException()]
int3
;; size=7 bbWeight=0 PerfScore 0.00
C:M1(ulong,uint):System.Span`1[ubyte]:this:
; Emitting BLENDED_CODE for X64 CPU with AVX - Unix
push rax
;; size=1 bbWeight=1 PerfScore 1.00
popcnt edx, edx
jl SHORT G_M53218_IG04
mov rax, rsi
;; size=9 bbWeight=1 PerfScore 3.25
add rsp, 8
ret
;; size=5 bbWeight=1 PerfScore 1.25
G_M53218_IG04:
call [System.ThrowHelper:ThrowArgumentOutOfRangeException()]
int3
;; size=7 bbWeight=0 PerfScore 0.00
C:M2(ulong,uint):System.Span`1[ubyte]:this:
; Emitting BLENDED_CODE for X64 CPU with AVX - Unix
push rax
;; size=1 bbWeight=1 PerfScore 1.00
popcnt edx, edx
jl SHORT G_M40097_IG04
mov rax, rsi
;; size=9 bbWeight=1 PerfScore 3.25
add rsp, 8
ret
;; size=5 bbWeight=1 PerfScore 1.25
G_M40097_IG04:
call [System.ThrowHelper:ThrowArgumentOutOfRangeException()]
int3
;; size=7 bbWeight=0 PerfScore 0.00
``
<table>
<tr>
<th align="left">Author:</th>
<td>xtqqczze</td>
</tr>
<tr>
<th align="left">Assignees:</th>
<td>-</td>
</tr>
<tr>
<th align="left">Labels:</th>
<td>
`tenet-performance`, `area-CodeGen-coreclr`, `untriaged`
</td>
</tr>
<tr>
<th align="left">Milestone:</th>
<td>-</td>
</tr>
</table>
</details> |
Reproduces for |
@TIHan PTAL. |
Span<T>::.ctor(void*, int32)
Span<T>::.ctor(void*, int32)
Did a quick investigation, The problem may have something to do with value numbering with assertion prop or redundant branch opt. Will look into it further. |
Confirmed fixed for // crossgen2 8.0.0-preview.4.23206.99+18e2c5fd9e2239a8b06fe49dbb6492d40f5e5e19
C:M0(ulong,ubyte):System.Span`1[ubyte]:this:
; Emitting BLENDED_CODE for X64 CPU with SSE2 - Unix
push rax
;; size=1 bbWeight=1 PerfScore 1.00
mov rax, rsi
movzx rdx, dl
;; size=6 bbWeight=1 PerfScore 0.50
add rsp, 8
ret
;; size=5 bbWeight=1 PerfScore 1.25
C:M2(ulong,int):System.Span`1[ubyte]:this:
; Emitting BLENDED_CODE for X64 CPU with SSE2 - Unix
push rax
;; size=1 bbWeight=1 PerfScore 1.00
movzx rdx, dl
test edx, edx
jl SHORT G_M26260_IG04
mov rax, rsi
;; size=10 bbWeight=1 PerfScore 1.75
add rsp, 8
ret
;; size=5 bbWeight=1 PerfScore 1.25
G_M26260_IG04:
call [System.ThrowHelper:ThrowArgumentOutOfRangeException()]
int3
;; size=7 bbWeight=0 PerfScore 0.00
C:M3(ulong,uint):System.Span`1[ubyte]:this:
; Emitting BLENDED_CODE for X64 CPU with SSE2 - Unix
push rax
;; size=1 bbWeight=1 PerfScore 1.00
popcnt edx, edx
mov rax, rsi
;; size=7 bbWeight=1 PerfScore 2.25
add rsp, 8
ret
;; size=5 bbWeight=1 PerfScore 1.25
C:M4(ulong,uint):System.Span`1[ubyte]:this:
; Emitting BLENDED_CODE for X64 CPU with SSE2 - Unix
push rax
;; size=1 bbWeight=1 PerfScore 1.00
popcnt edx, edx
mov rax, rsi
;; size=7 bbWeight=1 PerfScore 2.25
add rsp, 8
ret
;; size=5 bbWeight=1 PerfScore 1.25
C:.ctor():this:
; Emitting BLENDED_CODE for X64 CPU with SSE2 - Unix
;; size=0 bbWeight=1 PerfScore 0.00
ret
;; size=1 bbWeight=1 PerfScore 1.00 |
However, there is still a range check for: unsafe Span<byte> M2(byte* p, int b) => new(p, (byte)b); |
I noticed this for the JIT intrinsic
BitOperations.PopCount
, for which the return value should be treated as never negative (since #64951).The text was updated successfully, but these errors were encountered: