-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Open
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIuntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
Description
https://godbolt.org/z/KMPGzdnv5
public static string? TryUnwrapPrefix(string prefix, string path)
{
if (prefix == "/")
return path;
if (path == prefix)
return "/";
if ((uint)prefix.Length < (uint)path.Length)
if (path.StartsWith(prefix, StringComparison.Ordinal))
if (path[prefix.Length] == '/')
return new string(path.AsSpan(prefix.Length));
return null;
}Compiled with an unnecessary range check.
If one of the initial if statements is removed or the (uint)prefix.Length < (uint)path.Length check is moved after path.StartsWith then the JIT correctly eliminates the redundant bounds check.
This optimization works as expected in .NET 8-10
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIuntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner