Skip to content

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Dec 1, 2025

Closes #121987
Closes #122042

Just an experiment, if dotnet/roslyn#81485 lands, we can delete/ignore this (or intrinsify Slice anyway since it's a popular operation in general)

@EgorBo
Copy link
Member Author

EgorBo commented Dec 1, 2025

@MihuBot

@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Dec 1, 2025
@dotnet-policy-service
Copy link
Contributor

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

@EgorBo
Copy link
Member Author

EgorBo commented Dec 1, 2025

@MihuBot

@En3Tho
Copy link
Contributor

En3Tho commented Dec 1, 2025

@EgorBo I do believe that Slice(x, y) should be quite common in the real world too. So I don't think it's entirely about Roslyn.
A quick example would be something like this I guess:

static ReadOnlySpan<byte> Foo(ReadOnlySpan<byte> data)
{
    if (data.Length < sizeof(ushort))
        throw new ArgumentException("Data is too short", nameof(data));

    var header = MemoryMarshal.Read<ushort>(data);

    if (data.Length < sizeof(ushort) + header)
    {
        throw new ArgumentException("Data is too short for header", nameof(data));
    }

    return data.Slice(sizeof(ushort), header);
}

Ideally there should be no bound checks inserted by the jit. This can be extrapolated further to include multiple data sections/slices

@En3Tho
Copy link
Contributor

En3Tho commented Dec 1, 2025

Top regression method is funny :) Reducing those throw calls to 1 could easily result in an improvement

@EgorBo
Copy link
Member Author

EgorBo commented Dec 1, 2025

@EgorBo I do believe that Slice(x, y) should be quite common in the real world too

It is, but this PR was targeting a very specific pattern emitted by span[X..] syntax as it was difficult to properly handle it downstream.

Top regression method is funny

No clue why those tails were not merged

@EgorBo
Copy link
Member Author

EgorBo commented Dec 1, 2025

@MihuBot

@En3Tho
Copy link
Contributor

En3Tho commented Dec 3, 2025

@EgorBo I wonder if results are much better now after your tail merge fix

@EgorBo
Copy link
Member Author

EgorBo commented Dec 3, 2025

@MihuBot

@En3Tho
Copy link
Contributor

En3Tho commented Dec 3, 2025

I wonder if there is a conceptual difference between
call [rax]System.ThrowHelper:ThrowArgumentOutOfRangeException()
and
call CORINFO_HELP_THROW_ARGUMENTOUTOFRANGEEXCEPTION
?

@EgorBo
Copy link
Member Author

EgorBo commented Dec 3, 2025

I wonder if there is a conceptual difference between call [rax]System.ThrowHelper:ThrowArgumentOutOfRangeException() and call CORINFO_HELP_THROW_ARGUMENTOUTOFRANGEEXCEPTION ?

Should be the same thing

@En3Tho
Copy link
Contributor

En3Tho commented Dec 3, 2025

Interesting. If you look at System.IO.Compression.ZipGenericExtraField:WriteBlockCore(System.Span1[byte]):this (top regression method) - this PR adds call CORINFO_HELP_THROW_ARGUMENTOUTOFRANGEEXCEPTION in addition to existing call [rax]System.ThrowHelper:ThrowArgumentOutOfRangeException()

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.Slice(X) vs .[X..] codegen [JIT] Unable to elide bound checks from Creating/Copying vectors from/to spans

2 participants