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

[JIT] Do not force creation of a new IG if the current IG has no instructions #89876

Merged
merged 17 commits into from
Aug 8, 2023
17 changes: 16 additions & 1 deletion src/coreclr/jit/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1654,7 +1654,22 @@ void* emitter::emitAllocAnyInstr(size_t sz, emitAttr opsz)
if ((emitCurIGfreeNext + fullSize >= emitCurIGfreeEndp) || emitForceNewIG ||
(emitCurIGinsCnt >= (EMIT_MAX_IG_INS_COUNT - 1)))
{
emitNxtIG(true);
// If the current IG has instructions, then we need to create a new one.
if (emitCurIGnonEmpty())
{
emitNxtIG(true);
}
else
{
if (emitNoGCIG)
{
emitCurIG->igFlags |= IGF_NOGCINTERRUPT;
}
else
{
emitCurIG->igFlags &= ~IGF_NOGCINTERRUPT;
}
}
}

/* Grab the space for the instruction */
Expand Down
59 changes: 59 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_78891/Runtime_78891.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;
using Xunit;

// This test is to ensure that an assertion does not occur in the JIT.
public class Runtime_78891
{
class C0
{
public long F1;
}

struct S5
{
public bool F1;
public int F2;
public C0 F4;
public short F5;
public ulong F6;
public uint F7;
}

static S5 s_48;

[MethodImpl(MethodImplOptions.NoInlining)]
static void Consume(short x)
{

}

static void M59(S5 arg0, S5 arg1)
{
try
{
arg0 = arg1;
arg0 = arg1;
short var3 = arg1.F5;
Consume(var3);
}
finally
{
if (s_48.F4.F1 > arg0.F7)
{
arg0.F1 |= false;
}
}
}

[Fact]
public static void TestEntryPoint()
{
var vr2 = new S5();
var vr3 = new S5();
Assert.Throws<NullReferenceException>(() => M59(vr2, vr3));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Needed for CLRTestEnvironmentVariable -->
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
<ItemGroup>
<CLRTestEnvironmentVariable Include="DOTNET_JitDoVNBasedDeadStoreRemoval" Value="0" />
<CLRTestEnvironmentVariable Include="DOTNET_JitEnableEarlyLivenessRange" Value="0" />
<CLRTestEnvironmentVariable Include="DOTNET_JitEnablePhysicalPromotion" Value="0" />
<CLRTestEnvironmentVariable Include="DOTNET_EnableAVX2" Value="0" />
<CLRTestEnvironmentVariable Include="DOTNET_TieredCompilation" Value="0" />
</ItemGroup>
</Project>