Skip to content

Commit 74dc5d4

Browse files
jakobbotschpull[bot]
authored andcommitted
JIT: Expose top-level address computations in local morph (#106065)
Physical promotion relies on the invariant that we see no `LCL_ADDR` nodes for unexposed locals (except for retbuf definitions). However, local morph would not expose top level address computations with a note that morph would get rid of it. We could extract side effects for this case, but it does not seem frequent enough to warrant the special behavior.
1 parent b78f55f commit 74dc5d4

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed

src/coreclr/jit/lclmorph.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -665,12 +665,9 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>
665665

666666
WalkTree(stmt->GetRootNodePointer(), nullptr);
667667

668-
// If we have an address on the stack then we don't need to do anything.
669-
// The address tree isn't actually used and it will be discarded during
670-
// morphing. So just mark any value as consumed to keep PopValue happy.
671-
INDEBUG(TopValue(0).Consume());
672-
668+
EscapeValue(TopValue(0), nullptr);
673669
PopValue();
670+
674671
assert(m_valueStack.Empty());
675672
m_madeChanges |= m_stmtModified;
676673

@@ -1245,7 +1242,7 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>
12451242
LclVarDsc* varDsc = m_compiler->lvaGetDesc(lclNum);
12461243

12471244
GenTreeFlags defFlag = GTF_EMPTY;
1248-
GenTreeCall* callUser = user->IsCall() ? user->AsCall() : nullptr;
1245+
GenTreeCall* callUser = (user != nullptr) && user->IsCall() ? user->AsCall() : nullptr;
12491246
bool hasHiddenStructArg = false;
12501247
if (m_compiler->opts.compJitOptimizeStructHiddenBuffer && (callUser != nullptr) &&
12511248
m_compiler->IsValidLclAddr(lclNum, val.Offset()))
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Runtime.CompilerServices;
5+
using System.Runtime.Intrinsics;
6+
using Xunit;
7+
8+
public class Runtime_105952
9+
{
10+
[Fact]
11+
public static void TestEntryPoint()
12+
{
13+
new Runtime_105952().Foo();
14+
}
15+
16+
private readonly Vector128<ulong> _field;
17+
18+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
19+
private void Foo()
20+
{
21+
M2();
22+
M(Vector128<ulong>.Zero & _field, M2());
23+
}
24+
25+
[MethodImpl(MethodImplOptions.NoInlining)]
26+
private static void M(Vector128<ulong> v, int x)
27+
{
28+
}
29+
30+
[MethodImpl(MethodImplOptions.NoInlining)]
31+
private static int M2() => 0;
32+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Optimize>True</Optimize>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<Compile Include="$(MSBuildProjectName).cs" />
7+
</ItemGroup>
8+
</Project>

0 commit comments

Comments
 (0)