Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception sets: debug checker & fixes #63539

Merged
merged 30 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4204c27
Add a simple exception sets checker
SingleAccretion Jan 6, 2022
11bc9ca
Add asserts to catch missing nodes
SingleAccretion Jan 7, 2022
2a55e6d
Fix normal VN printing
SingleAccretion Jan 7, 2022
619e3dd
Fix JTRUE VNs
SingleAccretion Jan 6, 2022
cf25d65
Fix PHI VNs
SingleAccretion Jan 6, 2022
22ea6f0
Update VNs for "this" ARGPLACE node
SingleAccretion Jan 6, 2022
e00348e
Tolerate missing VNs on PHI_ARGs
SingleAccretion Jan 6, 2022
4595f6e
Tolerate unreachable blocks
SingleAccretion Jan 6, 2022
d15e056
Fix exception sets for VNF_PtrTo VNFuncs
SingleAccretion Jan 6, 2022
cb819f3
Add VNUniqueWithExc
SingleAccretion Jan 7, 2022
f30effa
Add VNPUniqueWithExc
SingleAccretion Jan 7, 2022
cd68e04
Fix arrays
SingleAccretion Jan 7, 2022
4a3258d
Consistently give location nodes VNForVoid
SingleAccretion Jan 3, 2022
7d0d5a3
Fix CSE
SingleAccretion Jan 7, 2022
e81a5b1
Fix GT_RETURN
SingleAccretion Jan 6, 2022
51ab752
Fix LCLHEAP
SingleAccretion Jan 7, 2022
349c914
Fix GT_ARR_ELEM
SingleAccretion Jan 7, 2022
86f3dec
Fix unique HWI
SingleAccretion Jan 7, 2022
4e4ca06
Fix unique SIMD
SingleAccretion Jan 7, 2022
32931de
Fix GT_SWITCH
SingleAccretion Jan 7, 2022
191b309
Fix CKFINITE
SingleAccretion Jan 7, 2022
8acc1bd
Fix HWI loads
SingleAccretion Jan 7, 2022
9cf97cf
Fix fgValueNumberAddExceptionSetForIndirection
SingleAccretion Jan 7, 2022
fbd4528
Fix GT_RETFILT
SingleAccretion Jan 7, 2022
d512994
Fix INIT_VAL
SingleAccretion Jan 7, 2022
0213bc3
Fix DYN_BLK
SingleAccretion Jan 7, 2022
529a8dc
Fix FIELD_LIST
SingleAccretion Jan 7, 2022
98a061e
De-pessimize CkFinite
SingleAccretion Jan 7, 2022
02918a3
Add a test for HWIs
SingleAccretion Jan 8, 2022
6795663
Add a test for LCLHEAP
SingleAccretion Jan 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5432,7 +5432,7 @@ class Compiler

// Requires that "tree" is a GT_IND marked as an array index, and that its address argument
// has been parsed to yield the other input arguments. If evaluation of the address
// can raise exceptions, those should be captured in the exception set "excVN."
// can raise exceptions, those should be captured in the exception set "addrXvnp".
// Assumes that "elemTypeEq" is the (equivalence class rep) of the array element type.
// Marks "tree" with the VN for H[elemTypeEq][arrVN][inx][fldSeq] (for the liberal VN; a new unique
// VN for the conservative VN.) Also marks the tree's argument as the address of an array element.
Expand All @@ -5443,14 +5443,14 @@ class Compiler
CORINFO_CLASS_HANDLE elemTypeEq,
ValueNum arrVN,
ValueNum inxVN,
ValueNum excVN,
ValueNumPair addrXvnp,
FieldSeqNode* fldSeq);

// Requires "funcApp" to be a VNF_PtrToArrElem, and "addrXvn" to represent the exception set thrown
// Requires "funcApp" to be a VNF_PtrToArrElem, and "addrXvnp" to represent the exception set thrown
// by evaluating the array index expression "tree". Returns the value number resulting from
// dereferencing the array in the current GcHeap state. If "tree" is non-null, it must be the
// "GT_IND" that does the dereference, and it is given the returned value number.
ValueNum fgValueNumberArrIndexVal(GenTree* tree, struct VNFuncApp* funcApp, ValueNum addrXvn);
ValueNum fgValueNumberArrIndexVal(GenTree* tree, VNFuncApp* funcApp, ValueNumPair addrXvnp);

// Compute the value number for a byref-exposed load of the given type via the given pointerVN.
ValueNum fgValueNumberByrefExposedLoad(var_types type, ValueNum pointerVN);
Expand Down Expand Up @@ -5560,6 +5560,10 @@ class Compiler
// Adds the exception sets for the current tree node
void fgValueNumberAddExceptionSet(GenTree* tree);

#ifdef DEBUG
void fgDebugCheckExceptionSets();
#endif

// These are the current value number for the memory implicit variables while
// doing value numbering. These are the value numbers under the "liberal" interpretation
// of memory values; the "conservative" interpretation needs no VN, since every access of
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/jit/optcse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,8 @@ bool Compiler::optValnumCSE_Locate()
continue;
}

if (ValueNumStore::isReservedVN(tree->GetVN(VNK_Liberal)))
ValueNum valueVN = vnStore->VNNormalValue(tree->GetVN(VNK_Liberal));
if (ValueNumStore::isReservedVN(valueVN) && (valueVN != ValueNumStore::VNForNull()))
{
continue;
}
Expand Down
550 changes: 341 additions & 209 deletions src/coreclr/jit/valuenum.cpp

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/coreclr/jit/valuenum.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ class ValueNumStore
// Both arguments must be either VNForEmptyExcSet() or applications of VNF_ExcSetCons.
bool VNExcIsSubset(ValueNum vnFullSet, ValueNum vnCandidateSet);

bool VNPExcIsSubset(ValueNumPair vnpFullSet, ValueNumPair vnpCandidateSet);

// Returns "true" iff "vn" is an application of "VNF_ValWithExc".
bool VNHasExc(ValueNum vn)
{
Expand Down Expand Up @@ -528,6 +530,12 @@ class ValueNumStore
// Keeps any Exception set values
ValueNumPair VNPMakeNormalUniquePair(ValueNumPair vnp);

// A new unique value with the given exception set.
ValueNum VNUniqueWithExc(var_types type, ValueNum vnExcSet);

// A new unique VN pair with the given exception set pair.
ValueNumPair VNPUniqueWithExc(var_types type, ValueNumPair vnpExcSet);

// If "vn" is a "VNF_ValWithExc(norm, excSet)" value, returns the "norm" argument; otherwise,
// just returns "vn".
// The Normal value is the value number of the expression when no exceptions occurred
Expand Down
40 changes: 40 additions & 0 deletions src/tests/JIT/opt/ValueNumbering/ExceptionSetsPropagation_Hwi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.Intrinsics;
using System.Runtime.CompilerServices;

// We're testing whether HWI nodes with > 2 operands propagate exception sets correctly.
//
class ExceptionSetsPropagation_Hwi
{
public static int Main()
{
try
{
Problem(-1, false, false);
}
catch (OverflowException)
{
return 100;
}

return 101;
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static bool Problem(int a, bool c1, bool c2)
{
var zero = 0;
c1 = a == 0;
c2 = c1;

if ((Vector128.Create((int)checked((uint)a), a, a, a).GetElement(0) * zero) + a == 0)
{
return false;
}

return c2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<CLRTestPriority>1</CLRTestPriority>
</PropertyGroup>
<PropertyGroup>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

.assembly extern xunit.core { }
.assembly extern System.Runtime { }
.assembly extern System.Console { }

.assembly ExceptionSetsPropagation_LclHeap { }

.class ExceptionSetsPropagation_LclHeap extends [System.Runtime]System.Object
{
.method public static int32 Main()
{
.custom instance void [xunit.core]Xunit.FactAttribute::.ctor() = (01 00 00 00)
.entrypoint

.try
{
ldc.i4 300
conv.i
call bool ExceptionSetsPropagation_LclHeap::Problem(native int)
pop
leave FAIL
}
catch [System.Runtime]System.OverflowException
{
pop
leave SUCCESS
}

SUCCESS:
ldc.i4 100
ret

FAIL:
ldc.i4 101
ret
}

.method private static bool Problem(native int a)
{
.locals (bool c1, bool c2)

ldarg a
localloc
ldc.i4 0
conv.i
and
ldarg a
ceq
stloc c1

ldloc c1
stloc c2

ldarg a
conv.ovf.i1
conv.i
localloc
ldc.i4 0
conv.i
and
ldarg a
ceq
brtrue RET

ldstr "The expected OverflowException was not thrown!"
call void [System.Console]System.Console::WriteLine(string)

RET:
ldloc c2
ret
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.IL">
<PropertyGroup>
<OutputType>Exe</OutputType>
<CLRTestPriority>1</CLRTestPriority>
</PropertyGroup>
<PropertyGroup>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).il" />
</ItemGroup>
</Project>