Skip to content

JIT: also check gc-ness of layout for GT_BLK during escape analysis #115844

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

Merged
merged 1 commit into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/coreclr/jit/objectalloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,19 @@ void ObjectAllocator::AnalyzeParentStack(ArrayStack<GenTree*>* parentStack, unsi
break;
}

// For structs we need to check the layout as well
//
if (parent->OperIs(GT_BLK))
{
ClassLayout* const layout = parent->AsBlk()->GetLayout();

if (!layout->HasGCPtr())
{
canLclVarEscapeViaParentStack = false;
break;
}
}

GenTree* const addr = parent->AsIndir()->Addr();

// For loads from local structs we may be tracking the underlying fields.
Expand Down
43 changes: 43 additions & 0 deletions src/tests/JIT/opt/ObjectStackAllocation/Runtime_115831.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Generated by Fuzzlyn v3.0 on 2025-05-20 21:40:51
// Run on X64 Windows
// Seed: 11262416476118799467-vectort,vector128,vector256,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86avx512fx64,x86bmi1,x86bmi1x64,x86bmi2,x86bmi2x64,x86fma,x86lzcnt,x86lzcntx64,x86pclmulqdq,x86popcnt,x86popcntx64,x86sse,x86ssex64,x86sse2,x86sse2x64,x86sse3,x86sse41,x86sse41x64,x86sse42,x86sse42x64,x86ssse3,x86x86base
// Reduced from 52.0 KiB to 0.5 KiB in 00:03:45
// Hits JIT assert in Release:
// Assertion failed 'newType == TYP_I_IMPL' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Allocate Objects' (IL size 47; hash 0xade6b36b; FullOpts)
//
// File: D:\a\_work\1\s\src\coreclr\jit\objectalloc.cpp Line: 2427
//
using System;
using System.Numerics;
using Xunit;

public class C1
{
}

public struct S2
{
public Vector<ushort> F0;
}

public struct S3
{
public S2 F3;
public C1 F5;
}

public class Runtime_115831
{
public static S3 s_1;
[Fact]
public static void Problem()
{
S3 vr0 = s_1;
S2 vr1 = vr0.F3;
vr0.F5 = new C1();
System.Console.WriteLine(vr1.F0);
}
}
9 changes: 9 additions & 0 deletions src/tests/JIT/opt/ObjectStackAllocation/Runtime_115831.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>
Loading