Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit a321506

Browse files
authored
JIT: fix remorph assert in cast long shift optimization (#15386)
In some cases reachable from IL we may simplify the shift amount, which sets the MORPHED flag, and then later remorph, leading to an assert in DEBUG/CHECK builds. Fix is to clear the MORPHED flag. Added test case.
1 parent b13f13c commit a321506

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

src/jit/morph.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,11 @@ GenTreePtr Compiler::fgMorphCast(GenTreePtr tree)
490490
shiftAmount = gtFoldExpr(shiftAmount);
491491
oper->gtOp.gtOp2 = shiftAmount;
492492

493+
#if DEBUG
494+
// We may remorph the shift amount tree again later, so clear any morphed flag.
495+
shiftAmount->gtDebugFlags &= ~GTF_DEBUG_NODE_MORPHED;
496+
#endif // DEBUG
497+
493498
if (shiftAmount->IsIntegralConst())
494499
{
495500
const ssize_t shiftAmountValue = shiftAmount->AsIntCon()->IconValue();
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
// See the LICENSE file in the project root for more information.
4+
5+
// Test for remorphing subexpressions in casts of long shifts.
6+
7+
.assembly extern System.Private.CoreLib {}
8+
.assembly GitHub_15319_1 {}
9+
10+
.class private auto ansi beforefieldinit Q
11+
extends [System.Private.CoreLib]System.Object
12+
{
13+
.method public hidebysig static int32 P(int64 x) cil managed noinlining
14+
{
15+
ldarg.s 0x0
16+
dup
17+
ldarg.s 0x0
18+
clt
19+
shl
20+
ret
21+
}
22+
23+
.method public hidebysig static int32 Main(string[] args) cil managed
24+
{
25+
.entrypoint
26+
ldc.i4.s 100
27+
conv.i8
28+
call int32 Q::P(int64)
29+
ret
30+
}
31+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
8+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
11+
<CLRTestPriority>1</CLRTestPriority>
12+
</PropertyGroup>
13+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup>
14+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "></PropertyGroup>
15+
<PropertyGroup>
16+
<DebugType>None</DebugType>
17+
<Optimize>True</Optimize>
18+
</PropertyGroup>
19+
<ItemGroup>
20+
<Compile Include="GitHub_15319_1.il" />
21+
</ItemGroup>
22+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
23+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
24+
</Project>

0 commit comments

Comments
 (0)