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

[Testing] stackalloc arrays contain gcrefs #110925

Closed
wants to merge 83 commits into from

Conversation

hez2010
Copy link
Contributor

@hez2010 hez2010 commented Dec 24, 2024

Testing stackalloc arrays contain gcrefs.
We can allocate an array of pointers instead of flatting the whole content on the stack. Not sure about the gc report issue here.

The analysis is not correct currently, but I'm opening a PR to check the diff we can potentially have.

hez2010 and others added 30 commits July 15, 2024 20:23
These flags are strictly optimizations. Having them required to be set
for certain indirs based on context of the operand introduces IR
invariants that are annoying to work with since it suddenly becomes
necessary for all transformations to consider "did we just introduce
this IR shape?". Instead, handle these patterns during morph as the
optimization it is and remove the strict flags checking from
`fgDebugCheckFlags`.
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Dec 24, 2024
@hez2010 hez2010 changed the title [Testing] stackalloc arrays contains gcrefs [Testing] stackalloc arrays contain gcrefs Dec 24, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Dec 24, 2024
@hez2010
Copy link
Contributor Author

hez2010 commented Dec 24, 2024

@MihuBot

@hez2010
Copy link
Contributor Author

hez2010 commented Dec 24, 2024

@EgorBot -amd -arm -profiler

using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
public class Benchmark
{
    [Benchmark]
    public void Bench()
    {
        var points = new[]
        {
            new Point(1, 2, 3),
            new Point(5, 4, 6),
            new Point(9, 8, 7),
        };
        double area = 0.5 * Math.Abs(
            points[0].X * (points[1].Y - points[2].Y) +
            points[1].X * (points[2].Y - points[0].Y) +
            points[2].X * (points[0].Y - points[1].Y));
        Use(area);
    }
    [MethodImpl(MethodImplOptions.NoInlining)]
    static void Use(double value) { }
    record Point(double X, double Y, double Z);
}

@hez2010
Copy link
Contributor Author

hez2010 commented Dec 24, 2024

This shares the same issue with field-wise analysis: we need to be careful with ind/blk load/store when field/index address is involved, which makes the analysis more conservative so that there will be fewer opportunities.
We need to make the analysis more precise.

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 community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants