Skip to content

Comments

[Testing] stackalloc arrays contain gcrefs#110925

Closed
hez2010 wants to merge 83 commits intodotnet:mainfrom
hez2010:array-stack-alloc
Closed

[Testing] stackalloc arrays contain gcrefs#110925
hez2010 wants to merge 83 commits intodotnet:mainfrom
hez2010:array-stack-alloc

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`.
@ghost ghost 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.

@hez2010 hez2010 closed this Dec 24, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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