Skip to content
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 fails to treat expression as non-negative after range check #112765

Open
MihaZupan opened this issue Feb 20, 2025 · 1 comment
Open

JIT fails to treat expression as non-negative after range check #112765

MihaZupan opened this issue Feb 20, 2025 · 1 comment
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@MihaZupan
Copy link
Member

https://godbolt.org/z/Wv5bv99bb

public static short Test1(ref short searchSpace, int searchSpaceLength)
{
    if (searchSpaceLength < Vector128<short>.Count)
        return 42;
    
    return Unsafe.Add(ref searchSpace, searchSpaceLength - Vector128<short>.Count);
}

public static short Test2(ref short searchSpace, int searchSpaceLength)
{
    if (searchSpaceLength < Vector128<short>.Count)
        return 42;
    
    return Unsafe.Add(ref searchSpace, (uint)searchSpaceLength - (nuint)Vector128<short>.Count);
}
-add      esi, -8
-movsxd   rax, esi
-movsx    rax, word  ptr [rdi+2*rax]
+mov      eax, esi
+movsx    rax, word  ptr [rdi+2*rax-0x10]

This occurs in practice in a bunch of places throughput our IndexOf-like logic, e.g.

ref short oneVectorAwayFromEnd = ref Unsafe.Add(ref searchSpace, length - Vector256<short>.Count);

ref short oneVectorAwayFromEnd = ref Unsafe.Add(ref searchSpace, searchSpaceLength - Vector256<short>.Count);

@MihaZupan MihaZupan added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 20, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Feb 20, 2025
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@EgorBo EgorBo self-assigned this Feb 20, 2025
@EgorBo EgorBo removed the untriaged New issue has not been triaged by the area owner label Feb 20, 2025
@EgorBo EgorBo added this to the 10.0.0 milestone Feb 20, 2025
@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI in-pr There is an active PR which will close this issue when it is merged
Projects
None yet
Development

No branches or pull requests

2 participants