Skip to content

Commit 32b7be7

Browse files
Fix issue with hoisting and copy prop interaction (#85493)
* Fix issue with hoisting and copy prop interaction After hoisting creates a tree copy, it morphs it. That morph might lose the value numbers on LCL_VAR uses, but leave the SSA numbers. Copy prop was assuming that such a use had a VN. Instead, check this dynamically instead of asserting. Fixes #84619 * Further optimize cast in fgOptimizeCastOnStore() If we optimize the cast, call `fgOptimizeCast` to see if it can be optimized further. * Add regression test * Feedback
1 parent 7b0d8fe commit 32b7be7

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

src/coreclr/jit/copyprop.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ int Compiler::optCopyProp_LclVarScore(const LclVarDsc* lclVarDsc, const LclVarDs
158158
bool Compiler::optCopyProp(
159159
BasicBlock* block, Statement* stmt, GenTreeLclVarCommon* tree, unsigned lclNum, LclNumToLiveDefsMap* curSsaName)
160160
{
161-
assert(((tree->gtFlags & GTF_VAR_DEF) == 0) && (tree->GetLclNum() == lclNum) && tree->gtVNPair.BothDefined());
161+
assert((tree->gtFlags & GTF_VAR_DEF) == 0);
162+
assert(tree->GetLclNum() == lclNum);
162163

163164
bool madeChanges = false;
164165
LclVarDsc* varDsc = lvaGetDesc(lclNum);

src/coreclr/jit/morph.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10196,6 +10196,9 @@ GenTree* Compiler::fgOptimizeCastOnStore(GenTree* store)
1019610196
{
1019710197
// This is a type-changing cast so we cannot remove it entirely.
1019810198
cast->gtCastType = genActualType(castToType);
10199+
10200+
// See if we can optimize the new cast.
10201+
store->Data() = fgOptimizeCast(cast);
1019910202
}
1020010203

1020110204
return store;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 Xunit;
5+
6+
// Generated by Fuzzlyn v1.5 on 2023-04-09 16:37:03
7+
// Run on X64 Windows
8+
// Seed: 6230188300048624105
9+
// Reduced from 155.1 KiB to 0.2 KiB in 00:01:48
10+
// Hits JIT assert in Release:
11+
// Assertion failed '((tree->gtFlags & GTF_VAR_DEF) == 0) && (tree->GetLclNum() == lclNum) && tree->gtVNPair.BothDefined()' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'VN based copy prop' (IL size 25; hash 0xade6b36b; FullOpts)
12+
//
13+
// File: D:\a\_work\1\s\src\coreclr\jit\copyprop.cpp Line: 161
14+
//
15+
public class Runtime_84619
16+
{
17+
public static sbyte s_27;
18+
[Fact]
19+
public static int TestEntryPoint()
20+
{
21+
long vr1 = 0;
22+
for (int vr3 = 0; vr3 < -1; vr3++)
23+
{
24+
s_27 = (sbyte)(vr1 | vr1);
25+
}
26+
return 100;
27+
}
28+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Optimize>True</Optimize>
4+
<DebugType>None</DebugType>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<Compile Include="$(MSBuildProjectName).cs" />
8+
</ItemGroup>
9+
</Project>

0 commit comments

Comments
 (0)