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

JIT: Reimport full spill clique for I_IMPL<->BYREF mismatches #92307

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 8 additions & 10 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11387,19 +11387,17 @@ void Compiler::impImportBlock(BasicBlock* block)
{
GenTree* tree = verCurrentState.esStack[level].val;

/* VC generates code where it pushes a byref from one branch, and an int (ldc.i4 0) from
the other. This should merge to a byref in unverifiable code.
However, if the branch which leaves the TYP_I_IMPL on the stack is imported first, the
successor would be imported assuming there was a TYP_I_IMPL on
the stack. Thus the value would not get GC-tracked. Hence,
change the temp to TYP_BYREF and reimport the successors.
Note: We should only allow this in unverifiable code.
*/
// VC generates code where it pushes a byref from one branch, and an int (ldc.i4 0) from
// the other. This should merge to a byref in unverifiable code.
// However, if the branch which leaves the TYP_I_IMPL on the stack is imported first, the
// successor would be imported assuming there was a TYP_I_IMPL on
// the stack. Thus the value would not get GC-tracked. Hence,
// change the temp to TYP_BYREF and reimport the clique.
// Note: We should only allow this in unverifiable code.
jakobbotsch marked this conversation as resolved.
Show resolved Hide resolved
if (tree->gtType == TYP_BYREF && lvaTable[tempNum].lvType == TYP_I_IMPL)
{
lvaTable[tempNum].lvType = TYP_BYREF;
impReimportMarkSuccessors(block);
markImport = true;
reimportSpillClique = true;
}

#ifdef TARGET_64BIT
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/jit/lclvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4146,7 +4146,6 @@ void Compiler::lvaMarkLclRefs(GenTree* tree, BasicBlock* block, Statement* stmt,

// Check that the LCL_VAR node has the same type as the underlying variable, save a few mismatches we allow.
assert(tree->TypeIs(varDsc->TypeGet(), genActualType(varDsc)) ||
(tree->TypeIs(TYP_I_IMPL) && (varDsc->TypeGet() == TYP_BYREF)) || // Created for spill clique import.
(tree->TypeIs(TYP_BYREF) && (varDsc->TypeGet() == TYP_I_IMPL)) || // Created by inliner substitution.
(tree->TypeIs(TYP_INT) && (varDsc->TypeGet() == TYP_LONG))); // Created by "optNarrowTree".
}
Expand Down
10 changes: 7 additions & 3 deletions src/coreclr/jit/morphblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1183,8 +1183,7 @@ GenTree* MorphCopyBlockHelper::CopyFieldByField()
addrSpillTemp = m_comp->lvaGrabTemp(true DEBUGARG("BlockOp address local"));

LclVarDsc* addrSpillDsc = m_comp->lvaGetDesc(addrSpillTemp);
addrSpillDsc->lvType = addrSpill->TypeIs(TYP_REF) ? TYP_REF : TYP_BYREF; // TODO-ASG: zero-diff quirk, delete.
addrSpillStore = m_comp->gtNewTempStore(addrSpillTemp, addrSpill);
addrSpillStore = m_comp->gtNewTempStore(addrSpillTemp, addrSpill);
}

auto grabAddr = [=, &result](unsigned offs) {
Expand Down Expand Up @@ -1227,7 +1226,12 @@ GenTree* MorphCopyBlockHelper::CopyFieldByField()
// handling.
GenTreeIntCon* fldOffsetNode = m_comp->gtNewIconNode(fullOffs, TYP_I_IMPL);
fldOffsetNode->gtFieldSeq = addrBaseOffsFldSeq;
addrClone = m_comp->gtNewOperNode(GT_ADD, TYP_BYREF, addrClone, fldOffsetNode);
addrClone = m_comp->gtNewOperNode(GT_ADD, varTypeIsGC(addrClone) ? TYP_BYREF : TYP_I_IMPL, addrClone,
fldOffsetNode);
// Avoid constant prop propagating each field access with a large
// constant address. TODO-Cleanup: We should tune constant prop to
// have better heuristics around this.
addrClone->gtFlags |= GTF_DONT_CSE;
}

return addrClone;
Expand Down
Loading