Skip to content

Commit 09ad892

Browse files
Fix an SSA bug from the ASG refactoring (#86108)
* Add a test * Fix an SSA bug from the GT_ASG refactoring Recording PHIs from analyzable stores is a correctness requirement.
1 parent 43d6cb0 commit 09ad892

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

src/coreclr/jit/gentree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,7 @@ struct GenTree
16341634

16351635
bool OperIsSsaDef() const
16361636
{
1637-
return OperIs(GT_CALL) || OperIsLocalStore();
1637+
return OperIsLocalStore() || OperIs(GT_CALL);
16381638
}
16391639

16401640
static bool OperIsHWIntrinsic(genTreeOps gtOper)

src/coreclr/jit/ssabuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ void SsaBuilder::InsertPhiFunctions(BasicBlock** postOrder, int count)
743743
//
744744
void SsaBuilder::RenameDef(GenTree* defNode, BasicBlock* block)
745745
{
746-
assert(defNode->OperIsSsaDef());
746+
assert(defNode->OperIsStore() || defNode->OperIs(GT_CALL));
747747

748748
GenTreeLclVarCommon* lclNode;
749749
bool isFullDef = false;
@@ -1114,7 +1114,7 @@ void SsaBuilder::BlockRenameVariables(BasicBlock* block)
11141114
{
11151115
for (GenTree* const tree : stmt->TreeList())
11161116
{
1117-
if (tree->OperIsSsaDef())
1117+
if (tree->OperIsStore() || tree->OperIs(GT_CALL))
11181118
{
11191119
RenameDef(tree, block);
11201120
}

src/tests/JIT/opt/SSA/MemorySsa.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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;
5+
using System.Runtime.CompilerServices;
6+
7+
public class MemorySsaTests
8+
{
9+
private static int _intStatic;
10+
11+
public static int Main()
12+
{
13+
return ProblemWithHandlerPhis(new int[0]) ? 101 : 100;
14+
}
15+
16+
[MethodImpl(MethodImplOptions.NoInlining)]
17+
private static bool ProblemWithHandlerPhis(int[] x)
18+
{
19+
_intStatic = 2;
20+
21+
try
22+
{
23+
_intStatic = 1;
24+
_ = x[0];
25+
_intStatic = 2;
26+
}
27+
catch (Exception)
28+
{
29+
// Memory PHIs in handlers must consider all intermediate states
30+
// that might arise from stores between throwing expressions.
31+
if (_intStatic == 2)
32+
{
33+
return true;
34+
}
35+
}
36+
37+
return false;
38+
}
39+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
</PropertyGroup>
5+
<PropertyGroup>
6+
<DebugType>None</DebugType>
7+
<Optimize>True</Optimize>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<Compile Include="$(MSBuildProjectName).cs" />
11+
</ItemGroup>
12+
</Project>

0 commit comments

Comments
 (0)