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
22 changes: 14 additions & 8 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8500,29 +8500,35 @@ void Compiler::fgValueNumberSsaVarDef(GenTreeLclVarCommon* lcl)
// tree where only one of the constants is expected to have a field sequence.
//
// Arguments:
// vnStore - ValueNumStore object
// tree - tree node to inspect
// pAddress - [Out] resulting address with all offsets combined
// pFseq - [Out] field sequence
//
// Return Value:
// true if the given tree is a static field address
//
static bool fgGetStaticFieldSeqAndAddress(GenTree* tree, ssize_t* pAddress, FieldSeq** pFseq)
static bool GetStaticFieldSeqAndAddress(ValueNumStore* vnStore, GenTree* tree, ssize_t* pAddress, FieldSeq** pFseq)
{
ssize_t val = 0;
// Accumulate final offset
while (tree->OperIs(GT_ADD))
{
GenTree* op1 = tree->gtGetOp1();
GenTree* op2 = tree->gtGetOp2();
if (op1->IsCnsIntOrI() && (op1->AsIntCon()->gtFieldSeq == nullptr))
GenTree* op1 = tree->gtGetOp1();
GenTree* op2 = tree->gtGetOp2();
ValueNum op1vn = op1->gtVNPair.GetLiberal();
ValueNum op2vn = op2->gtVNPair.GetLiberal();

if (!op1->IsIconHandle(GTF_ICON_STATIC_HDL) && op1->gtVNPair.BothEqual() && vnStore->IsVNConstant(op1vn) &&
varTypeIsIntegral(vnStore->TypeOfVN(op1vn)))
{
val += op1->AsIntCon()->IconValue();
val += vnStore->CoercedConstantValue<ssize_t>(op1vn);
tree = op2;
}
else if (op2->IsCnsIntOrI() && (op2->AsIntCon()->gtFieldSeq == nullptr))
else if (!op2->IsIconHandle(GTF_ICON_STATIC_HDL) && op2->gtVNPair.BothEqual() && vnStore->IsVNConstant(op2vn) &&
varTypeIsIntegral(vnStore->TypeOfVN(op2vn)))
{
val += op2->AsIntCon()->IconValue();
val += vnStore->CoercedConstantValue<ssize_t>(op2vn);
tree = op1;
}
else
Expand Down Expand Up @@ -8568,7 +8574,7 @@ bool Compiler::fgValueNumberConstLoad(GenTreeIndir* tree)
//
ssize_t address = 0;
FieldSeq* fieldSeq = nullptr;
if (fgGetStaticFieldSeqAndAddress(tree->gtGetOp1(), &address, &fieldSeq))
if (varTypeIsIntegral(tree) && GetStaticFieldSeqAndAddress(vnStore, tree->gtGetOp1(), &address, &fieldSeq))
{
assert(fieldSeq->GetKind() == FieldSeq::FieldKind::SimpleStaticKnownAddress);
CORINFO_FIELD_HANDLE fieldHandle = fieldSeq->GetFieldHandle();
Expand Down