Skip to content

Commit

Permalink
Handle direct addresses for statics in IsFieldAddr (#64846)
Browse files Browse the repository at this point in the history
* DEBUG-ONLY: FieldInfo

Allows this change to be tested via SPMI.

* Handle direct addresses in IsFieldAddr

* Always use NotAField in IsFieldAddr

No diffs.

* Revert "DEBUG-ONLY: FieldInfo"

This reverts commit b17817e0354a63319256a0fa0d21b74c2cfbf781.
  • Loading branch information
SingleAccretion committed Feb 24, 2022
1 parent 9212310 commit b3465af
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16061,10 +16061,11 @@ bool GenTreeIntConCommon::AddrNeedsReloc(Compiler* comp)
//------------------------------------------------------------------------
// IsFieldAddr: Is "this" a static or class field address?
//
// Recognizes the following three patterns:
// this: [Zero FldSeq]
// this: ADD(baseAddr, CONST FldSeq)
// this: ADD(CONST FldSeq, baseAddr)
// Recognizes the following patterns:
// this: ADD(baseAddr, CONST [FldSeq])
// this: ADD(CONST [FldSeq], baseAddr)
// this: CONST [FldSeq]
// this: Zero [FldSeq]
//
// Arguments:
// comp - the Compiler object
Expand All @@ -16089,7 +16090,7 @@ bool GenTree::IsFieldAddr(Compiler* comp, GenTree** pBaseAddr, FieldSeqNode** pF
*pFldSeq = FieldSeqStore::NotAField();

GenTree* baseAddr = nullptr;
FieldSeqNode* fldSeq = nullptr;
FieldSeqNode* fldSeq = FieldSeqStore::NotAField();

if (OperIs(GT_ADD))
{
Expand All @@ -16113,26 +16114,28 @@ bool GenTree::IsFieldAddr(Compiler* comp, GenTree** pBaseAddr, FieldSeqNode** pF
assert(!baseAddr->TypeIs(TYP_REF) || !comp->GetZeroOffsetFieldMap()->Lookup(baseAddr));
}
}
else if (IsCnsIntOrI() && IsIconHandle(GTF_ICON_STATIC_HDL))
{
assert(!comp->GetZeroOffsetFieldMap()->Lookup(this) && (AsIntCon()->gtFieldSeq != nullptr));
fldSeq = AsIntCon()->gtFieldSeq;
baseAddr = nullptr;
}
else if (comp->GetZeroOffsetFieldMap()->Lookup(this, &fldSeq))
{
baseAddr = this;
}
else
{
// TODO-VNTypes-CQ: recognize the simple GTF_ICON_STATIC_HDL case here. It
// is not recognized right now to preserve previous behavior of this method.
return false;
}

// If we don't have a valid sequence, bail. Note that above we have overloaded an empty
// ("nullptr") sequence as "NotAField", as that's the way it is treated on tree nodes.
if ((fldSeq == nullptr) || (fldSeq == FieldSeqStore::NotAField()) || fldSeq->IsPseudoField())
assert(fldSeq != nullptr);

if ((fldSeq == FieldSeqStore::NotAField()) || fldSeq->IsPseudoField())
{
return false;
}

assert(baseAddr != nullptr);

// The above screens out obviously invalid cases, but we have more checks to perform. The
// sequence returned from this method *must* start with either a class (NOT struct) field
// or a static field. To avoid the expense of calling "getFieldClass" here, we will instead
Expand Down

0 comments on commit b3465af

Please sign in to comment.