}
rp->lastUse = (rp->refType != RefTypeExpUse) && (rp->refType != RefTypeParamDef) &&
- (rp->refType != RefTypeZeroInit);
+ (rp->refType != RefTypeZeroInit) && !extendLifetimes();
}
else if (RefTypeIsUse(rp->refType))
{
if (!VarSetOps::IsMember(compiler, temp, varIndex) && varNum != keepAliveVarNum)
{
// There was no exposed use, so this is a "last use" (and we mark it thus even if it's a def)
- if (!currentRefPosition->lastUse)
+
+ if (extendLifetimes())
+ {
+ // NOTE: this is a bit of a hack. When extending lifetimes, the "last use" bit will be clear.
+ // This bit, however, would normally be used during resolveLocalRef to set the value of
+ // GTF_VAR_DEATH on the node for a ref position. If this bit is not set correctly even when
+ // extending lifetimes, the code generator will assert as it expects to have accurate last
+ // use information. To avoid these asserts, set the GTF_VAR_DEATH bit here.
+ if (tree != nullptr)
+ {
+ tree->gtFlags |= GTF_VAR_DEATH;
+ }
+ }
+ else if (!currentRefPosition->lastUse)
{
JITDUMP("missing expected last use of V%02u @%u\n", compiler->lvaTrackedToVarNum[varIndex], loc);
foundDiff = true;
JITDUMP("unexpected last use of V%02u @%u\n", compiler->lvaTrackedToVarNum[varIndex], loc);
foundDiff = true;
}
+ else if (extendLifetimes() && tree != nullptr)
+ {
+ // NOTE: see the comment above re: the extendLifetimes hack.
+ tree->gtFlags &= ~GTF_VAR_DEATH;
+ }
if (currentRefPosition->refType == RefTypeDef || currentRefPosition->refType == RefTypeDummyDef)
{
interval->recentRefPosition = currentRefPosition;
LclVarDsc* varDsc = interval->getLocalVar(compiler);
- if ((treeNode != nullptr))
+ // NOTE: we set the GTF_VAR_DEATH flag here unless we are extending lifetimes, in which case we write
+ // this bit in checkLastUses. This is a bit of a hack, but is necessary because codegen requires
+ // accurate last use info that is not reflected in the lastUse bit on ref positions when we are extending
+ // lifetimes. See also the comments in checkLastUses.
+ if ((treeNode != nullptr) && !extendLifetimes())
{
if (currentRefPosition->lastUse)
{