Navigation Menu

Skip to content

Commit

Permalink
JIT: enable GDV when static class deduction fails. (#55660)
Browse files Browse the repository at this point in the history
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 15, 2021
1 parent 2e93fab commit bd9d4e0
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/coreclr/jit/importer.cpp
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

0 comments on commit bd9d4e0

Please sign in to comment.