Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -1099,14 +1099,14 @@ class LclVarDsc
{
return varTypeIsSmall(TypeGet()) &&
// lvIsStructField is treated the same as the aliased local, see fgDoNormalizeOnStore.
(lvIsParam || m_addrExposed || lvIsStructField);
(lvIsParam || m_addrExposed || lvIsStructField || lvIsOSRLocal);
}

bool lvNormalizeOnStore() const
{
return varTypeIsSmall(TypeGet()) &&
// lvIsStructField is treated the same as the aliased local, see fgDoNormalizeOnStore.
!(lvIsParam || m_addrExposed || lvIsStructField);
!(lvIsParam || m_addrExposed || lvIsStructField || lvIsOSRLocal);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a while to guess that the reason is that the local could have been marked normalize-on-load in tier-0 due to the more conservative address exposure there. Maybe add a comment to that effect?

Also, I guess if we wanted to we could scope this down to just OSR locals that were address exposed in tier 0, since we have that information available.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about scoping it down, so let me do that (will need a new bit on lclvar dsc).

}

void incRefCnts(weight_t weight, Compiler* pComp, RefCountState state = RCS_NORMAL, bool propagate = true);
Expand Down
52 changes: 52 additions & 0 deletions src/tests/JIT/opt/OSR/normalizeonload.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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;

// Ensure small OSR locals are marked as normalize on load

class Runtime_83959
{
static bool B(out byte b)
{
b = 1;
return true;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static void F() {}

[MethodImpl(MethodImplOptions.NoInlining)]
[SkipLocalsInit]
static void WithOSR(int n, out char c)
{
c = (char) 0;
B(out byte b);
for (int i = 0; i < n; i++)
{
F();
}
// This load of `b` must be a single byte
c = (char) b;
c += (char) 99;
}

// Ensure stack is filled with nonzero data
static void FillStack(int n)
{
Span<int> s = stackalloc int[n];
for (int i = 0; i < n; i++)
{
s[i] = -1;
}
}

public static int Main()
{
char c = (char) 0;
FillStack(100);
WithOSR(50000, out c);
return (int) c;
}
}
15 changes: 15 additions & 0 deletions src/tests/JIT/opt/OSR/normalizeonload.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<DebugType />
<Optimize>True</Optimize>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />

<CLRTestEnvironmentVariable Include="DOTNET_TieredCompilation" Value="1" />
<CLRTestEnvironmentVariable Include="DOTNET_TC_QuickJitForLoops" Value="1" />
<CLRTestEnvironmentVariable Include="DOTNET_TC_OnStackReplacement" Value="1" />
</ItemGroup>
</Project>