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

Optimize GDV checks for objects with known type #84661

Merged
merged 26 commits into from
Apr 22, 2023
Merged
Changes from 4 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f31dd26
Optimize GDV check
EgorBo Apr 11, 2023
7a754d6
Improve
EgorBo Apr 11, 2023
0246f11
move to VN
EgorBo Apr 11, 2023
3e5d5d6
use handle
EgorBo Apr 11, 2023
4934611
Add in Morph too
EgorBo Apr 12, 2023
ef2ef49
Merge branch 'main' of github.com:dotnet/runtime into improve-gdv-check
EgorBo Apr 12, 2023
4446e6d
add comments
EgorBo Apr 12, 2023
846e7d7
Update morph.cpp
EgorBo Apr 12, 2023
349e77a
fix build
EgorBo Apr 12, 2023
036f431
remove morph part
EgorBo Apr 12, 2023
67aa3e5
Merge branch 'main' of github.com:dotnet/runtime into improve-gdv-check
EgorBo Apr 12, 2023
b4a898d
Merge branch 'main' of github.com:dotnet/runtime into improve-gdv-check
EgorBo Apr 12, 2023
30855af
fix naot
EgorBo Apr 13, 2023
38b63db
Merge branch 'main' of github.com:dotnet/runtime into improve-gdv-check
EgorBo Apr 13, 2023
be87146
test
EgorBo Apr 13, 2023
38eea8a
more coservative fix
EgorBo Apr 13, 2023
4e802a9
Merge branch 'main' of github.com:dotnet/runtime into improve-gdv-check
EgorBo Apr 13, 2023
f41fe83
test2
EgorBo Apr 13, 2023
2477124
fix cg?
EgorBo Apr 14, 2023
e55663c
Merge branch 'main' of github.com:dotnet/runtime into improve-gdv-check
EgorBo Apr 14, 2023
70e5e38
skip indirect handles
EgorBo Apr 14, 2023
3b18809
Address feedback
EgorBo Apr 14, 2023
602a2ba
Update src/coreclr/jit/valuenum.cpp
EgorBo Apr 14, 2023
737b3a4
Merge branch 'main' of github.com:dotnet/runtime into improve-gdv-check
EgorBo Apr 21, 2023
beb3ab9
fix naot assert
EgorBo Apr 21, 2023
166e900
Apply Jan's suggestion
EgorBo Apr 21, 2023
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
41 changes: 29 additions & 12 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10606,23 +10606,40 @@ void Compiler::fgValueNumberTree(GenTree* tree)
{
assert(!isVolatile); // We don't expect both volatile and invariant

// Are we dereferencing the method table slot of some newly allocated object?
//
bool wasNewobj = false;
if ((oper == GT_IND) && (addr->TypeGet() == TYP_REF) && (tree->TypeGet() == TYP_I_IMPL))
bool returnsTypeHandle = false;
if ((oper == GT_IND) && addr->TypeIs(TYP_REF) && tree->TypeIs(TYP_I_IMPL))
{
VNFuncApp funcApp;
const bool addrIsVNFunc = vnStore->GetVNFunc(addrNvnp.GetLiberal(), &funcApp);

if (addrIsVNFunc && (funcApp.m_func == VNF_JitNew) && addrNvnp.BothEqual())
GenTreeIndir* indir = tree->AsIndir();
if (!indir->HasIndex() && (indir->Offset() == 0))
{
tree->gtVNPair =
vnStore->VNPWithExc(ValueNumPair(funcApp.m_args[0], funcApp.m_args[0]), addrXvnp);
wasNewobj = true;
// We try to access GC object's type, let's see if we know the exact type already
// First, we're trying to do that via gtGetClassHandle.
//
bool isExact = false;
bool isNonNull = false;
CORINFO_CLASS_HANDLE handle = gtGetClassHandle(addr, &isExact, &isNonNull);
if (isExact && (handle != NO_CLASS_HANDLE))
{
ValueNum handleVN = vnStore->VNForHandle((ssize_t)handle, GTF_ICON_CLASS_HDL);
tree->gtVNPair = vnStore->VNPWithExc(ValueNumPair(handleVN, handleVN), addrXvnp);
returnsTypeHandle = true;
}
else
{
// Then, let's see if we can find JitNew at least
VNFuncApp funcApp;
const bool addrIsVNFunc = vnStore->GetVNFunc(addrNvnp.GetLiberal(), &funcApp);
if (addrIsVNFunc && (funcApp.m_func == VNF_JitNew) && addrNvnp.BothEqual())
{
tree->gtVNPair =
vnStore->VNPWithExc(ValueNumPair(funcApp.m_args[0], funcApp.m_args[0]), addrXvnp);
returnsTypeHandle = true;
}
}
}
}

if (!wasNewobj)
if (!returnsTypeHandle)
{
// Indirections off of addresses for boxed statics represent bases for
// the address of the static itself. Here we will use "nullptr" for the
Expand Down