Skip to content

Commit

Permalink
JIT: optimize popped boxes in the importer (dotnet#101303)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyAyersMS authored and Ruihan-Yin committed May 30, 2024
1 parent cdc117e commit 42d9737
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7999,6 +7999,14 @@ void Compiler::impImportBlockCode(BasicBlock* block)
/* Append the value to the tree list */
goto SPILL_APPEND;
}
else
{
if (op1->IsBoxedValue())
{
JITDUMP("\n CEE_POP box...\n");
gtTryRemoveBoxUpstreamEffects(op1);
}
}

/* No side effects - just throw the <BEEP> thing away */
}
Expand Down
42 changes: 42 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_82291/Runtime_82291.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Runtime.CompilerServices;
using Xunit;

public class Runtime_82291
{
[MethodImpl(MethodImplOptions.NoInlining)]
static bool GetValueOrNull<T>()
{
if (default(T) != null)
return true;

return false;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static bool GetValueOrNullSlow<T>()
{
if (default(T) != null)
return false;

return false;
}


[MethodImpl(MethodImplOptions.NoInlining)]
static void GetValueOrNullSlow2<T>()
{
if (default(T) != null)
return;

return;
}

[Fact]
public static void Test()
{
GetValueOrNull<int>();
GetValueOrNullSlow<int>();
GetValueOrNullSlow2<int>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>

0 comments on commit 42d9737

Please sign in to comment.