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

Commit 0c95349

Browse files
authored
An UnusedValue still requires a target reg (#18561)
* An UnusedValue still requires a target reg The BuildSimple method wasn't creating a def for an unused value. Although (in this case) the code is dead, the code generator must still be able to generate code for it. * Add test case for #18295 to arm/arm64 tests.lst
1 parent 1c0c5ac commit 0c95349

File tree

5 files changed

+116
-1
lines changed

5 files changed

+116
-1
lines changed

src/jit/lsrabuild.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2901,7 +2901,7 @@ int LinearScan::BuildSimple(GenTree* tree)
29012901
assert((kind & GTK_SMPOP) != 0);
29022902
srcCount = BuildBinaryUses(tree->AsOp());
29032903
}
2904-
if (tree->IsValue() && !tree->IsUnusedValue())
2904+
if (tree->IsValue())
29052905
{
29062906
BuildDef(tree);
29072907
}

tests/arm/Tests.lst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94716,3 +94716,11 @@ MaxAllowedDurationSeconds=600
9471694716
Categories=EXPECTED_PASS
9471794717
HostStyle=0
9471894718

94719+
[GitHub_18295.cmd_11900]
94720+
RelativePath=JIT\Regression\JitBlue\GitHub_18295\GitHub_18295\GitHub_18295.cmd
94721+
WorkingDir=JIT\Regression\JitBlue\GitHub_18295\GitHub_18295
94722+
Expected=0
94723+
MaxAllowedDurationSeconds=600
94724+
Categories=EXPECTED_PASS
94725+
HostStyle=0
94726+

tests/arm64/Tests.lst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94740,3 +94740,11 @@ MaxAllowedDurationSeconds=600
9474094740
Categories=EXPECTED_PASS
9474194741
HostStyle=0
9474294742

94743+
[GitHub_18295.cmd_12220]
94744+
RelativePath=JIT\Regression\JitBlue\GitHub_18295\GitHub_18295\GitHub_18295.cmd
94745+
WorkingDir=JIT\Regression\JitBlue\GitHub_18295\GitHub_18295
94746+
Expected=0
94747+
MaxAllowedDurationSeconds=600
94748+
Categories=EXPECTED_PASS
94749+
HostStyle=0
94750+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
.assembly extern mscorlib { auto }
6+
.assembly extern System.Console {auto}
7+
.assembly UnusedValueBug { }
8+
9+
// This bug was found on desktop CLR using ILGEN.
10+
// The expression ending in the 'mul' below is all dead, but not all the dead code
11+
// gets eliminated. On ARM, there is a SETCC resulting from the first 'cgt' that remains,
12+
// and it is marked as an 'UnusedValue', but the BuildSimple method wasn't creating a def
13+
// for an unused value. This led to an assert in the code generator.
14+
//
15+
.class private auto ansi beforefieldinit GitHub_18295
16+
extends [mscorlib]System.Object
17+
{
18+
.method private hidebysig static int32 Test(int64 l, int32 i) cil managed
19+
{
20+
.locals init ([0] int32 loc6,
21+
[1] float32 loc8)
22+
23+
ldloc 0
24+
ldloc 1
25+
conv.ovf.i8.un
26+
ldarg 0
27+
not
28+
cgt
29+
cgt.un
30+
ldloc 0
31+
nop
32+
not
33+
not
34+
mul
35+
ret
36+
}
37+
38+
.method private hidebysig static int32 Main() cil managed
39+
{
40+
.entrypoint
41+
.vtentry 11 : 1
42+
// Code size 131 (0x83)
43+
.maxstack 4
44+
.locals ([0] int32 returnVal)
45+
46+
// returnVal = 100;
47+
ldc.i4.s 100
48+
stloc returnVal
49+
50+
// if (Test(1,1) != 1) goto F1
51+
ldc.i4 1
52+
ldc.i8 1
53+
call int32 GitHub_18295::Test(int64, int32)
54+
55+
ldc.i4.0
56+
beq.s L2
57+
58+
F1:
59+
// Console.WriteLine("FAIL");
60+
ldstr "FAIL"
61+
call void [System.Console]System.Console::WriteLine(string)
62+
// returnVal = -1;
63+
ldc.i4.m1
64+
stloc returnVal
65+
br L3
66+
67+
L2:
68+
// Console.WriteLine("PASS");
69+
ldstr "PASS"
70+
call void [System.Console]System.Console::WriteLine(string)
71+
72+
L3:
73+
ldloc returnVal
74+
ret
75+
}
76+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
</PropertyGroup>
12+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup>
13+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "></PropertyGroup>
14+
<PropertyGroup>
15+
<DebugType>None</DebugType>
16+
<Optimize>True</Optimize>
17+
</PropertyGroup>
18+
<ItemGroup>
19+
<Compile Include="$(MSBuildProjectName).il" />
20+
</ItemGroup>
21+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
22+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
23+
</Project>

0 commit comments

Comments
 (0)