-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JIT: don't inline methods with small stackallocs if the call site is … (
#43516) The logic in `fgInlinePrependStatements` that zero-initializes locals doesn't kick in for jit temps introduced when small stackallocs are optimized. So if we inline a method with a small stackalloc into a loop, the memory for the stackalloc doesn't get properly re-zeroed on each iteration. Fix by disallowing such inlines by adding an extra check: the call site must not be in a loop. Closes #43391.
- Loading branch information
1 parent
466e4b7
commit f8fb84c
Showing
4 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/tests/JIT/Regression/JitBlue/Runtime_43391/Runtime_43391.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
// Block inlining of small localloc callee if call site is in a loop. | ||
|
||
using System; | ||
|
||
class Runtime_43391 | ||
{ | ||
static int Main() | ||
{ | ||
int r = 58; | ||
for (int i = 1; i >= 0; i--) | ||
{ | ||
r += Test(i); | ||
} | ||
return r; | ||
} | ||
|
||
public static unsafe byte Test(int i) | ||
{ | ||
byte* p = stackalloc byte[8]; | ||
p[i] = 42; | ||
return p[1]; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/tests/JIT/Regression/JitBlue/Runtime_43391/Runtime_43391.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<CLRTestPriority>0</CLRTestPriority> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<DebugType>None</DebugType> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="Runtime_43391.cs" /> | ||
</ItemGroup> | ||
</Project> |