Skip to content
Merged
Changes from all commits
Commits
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
JIT: enable GDV when static class deduction fails.
Update the early bailout in impDevirtualizeCall that gives up if
the object class cannot not be determined to check if we can do
GDV (guarded devirtualization) based on profile data.

Fixes one of the cases noted in #55079.
  • Loading branch information
AndyAyersMS committed Jul 14, 2021
commit 57733bc8b4012bfd728d9d998e72039626272534
28 changes: 20 additions & 8 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20935,25 +20935,37 @@ void Compiler::impDevirtualizeCall(GenTreeCall* call,
return;
}

// Fetch information about the class that introduced the virtual method.
CORINFO_CLASS_HANDLE baseClass = info.compCompHnd->getMethodClass(baseMethod);
const DWORD baseClassAttribs = info.compCompHnd->getClassAttribs(baseClass);

// Is the call an interface call?
const bool isInterface = (baseClassAttribs & CORINFO_FLG_INTERFACE) != 0;

// See what we know about the type of 'this' in the call.
GenTree* thisObj = call->gtCallThisArg->GetNode()->gtEffectiveVal(false);
bool isExact = false;
bool objIsNonNull = false;
CORINFO_CLASS_HANDLE objClass = gtGetClassHandle(thisObj, &isExact, &objIsNonNull);

// Bail if we know nothing.
if (objClass == nullptr)
if (objClass == NO_CLASS_HANDLE)
{
JITDUMP("\nimpDevirtualizeCall: no type available (op=%s)\n", GenTree::OpName(thisObj->OperGet()));
return;
}

// Fetch information about the class that introduced the virtual method.
CORINFO_CLASS_HANDLE baseClass = info.compCompHnd->getMethodClass(baseMethod);
const DWORD baseClassAttribs = info.compCompHnd->getClassAttribs(baseClass);
// Don't try guarded devirtualiztion when we're doing late devirtualization.
//
if (isLateDevirtualization)
{
JITDUMP("No guarded devirt during late devirtualization\n");
return;
}

// Is the call an interface call?
const bool isInterface = (baseClassAttribs & CORINFO_FLG_INTERFACE) != 0;
considerGuardedDevirtualization(call, ilOffset, isInterface, baseMethod, baseClass,
pContextHandle DEBUGARG(objClass) DEBUGARG("unknown"));

return;
}

// If the objClass is sealed (final), then we may be able to devirtualize.
const DWORD objClassAttribs = info.compCompHnd->getClassAttribs(objClass);
Expand Down