Skip to content
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
18 changes: 12 additions & 6 deletions src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4322,16 +4322,22 @@ void Compiler::optRecordLoopMemoryDependence(GenTree* tree, BasicBlock* block, V
return;
}

// If the update block is not the header of a loop containing
// block, we can also ignore the update.
// If the memory definition is part of an ancestor loop then 'tree' depends
// on memory defined in that ancestor loop. Otherwise we can also ignore
// the update.
//
if (!updateLoop->ContainsBlock(block))
while ((updateLoop != nullptr) && !updateLoop->ContainsBlock(block))
{
updateLoop = updateLoop->GetParent();
}

if (updateLoop == nullptr)
{
#ifdef DEBUG
FlowGraphNaturalLoop* blockLoop = m_blockToLoop->GetLoop(block);

JITDUMP(" ==> Not updating loop memory dependence of [%06u]/" FMT_LP ", memory " FMT_VN "/" FMT_LP
" is not defined in a contained block\n",
JITDUMP(" ==> Not updating loop memory dependence of [%06u]/" FMT_LP ", memory definition " FMT_VN
"/" FMT_LP " is not dependent on an ancestor loop\n",
dspTreeID(tree), blockLoop->GetIndex(), memoryVN, updateLoop->GetIndex());
#endif
return;
Expand All @@ -4355,7 +4361,7 @@ void Compiler::optRecordLoopMemoryDependence(GenTree* tree, BasicBlock* block, V
#ifdef DEBUG
FlowGraphNaturalLoop* mapLoop = m_blockToLoop->GetLoop(mapBlock);

JITDUMP(" ==> Not updating loop memory dependence of [%06u]; alrady constrained to " FMT_LP
JITDUMP(" ==> Not updating loop memory dependence of [%06u]; already constrained to " FMT_LP
" nested in " FMT_LP "\n",
dspTreeID(tree), mapLoop->GetIndex(), updateLoop->GetIndex());
#endif
Expand Down
41 changes: 41 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_105413/Runtime_105413.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;
using Xunit;

public class Runtime_105413
{
private static ushort[] s_field1;
private static bool s_field2;

[Fact]
public static void TestEntryPoint()
{
s_field2 = true;
Foo(2);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Foo(int n)
{
for (int i = 0; i < n; i++)
{
int j = 0;
do
{
s_field1 = [1];
j++;
} while (j < n);

s_field2 = false;
Bar(s_field2);
}
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Bar(bool value)
{
Assert.False(value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>