Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add an optimization
It was confusing in the dumps to look at unused results of VNForMapSelect,
so just avoid looking for the first field's value if we do not need it.
  • Loading branch information
SingleAccretion committed Nov 6, 2021
commit 0a4c6aebebe56130b8cdc1d7b883a5cdd02a99e0
32 changes: 21 additions & 11 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7808,22 +7808,32 @@ void Compiler::fgValueNumberAssignment(GenTreeOp* tree)
firstFieldValueSelectorVN = vnStore->VNLiberalNormalValue(staticOffset->gtVNPair);
}

// Construct the ValueNumber for fldMap[obj/offset]. This
// map represents the specific field we're looking to store to.
ValueNum firstFieldValueVN = vnStore->VNForMapSelect(VNK_Liberal, firstFieldType, fldMapVN,
firstFieldValueSelectorVN);

// Now construct the maps updating the rest of the
// fields in the sequence (of which there could be none).
ValueNum newFirstFieldValueVN = vnStore->VNApplySelectorsAssign(VNK_Liberal,
firstFieldValueVN,
fldSeq->m_next,
storeVal, indType);
ValueNum newFirstFieldValueVN = ValueNumStore::NoVN;
// Optimization: avoid traversting the maps for the value of the first field if
// we do not need it, which is the case if the rest of the field sequence is empty.
if (fldSeq->m_next == nullptr)
{
newFirstFieldValueVN = vnStore->VNApplySelectorsAssignTypeCoerce(storeVal, indType);
}
else
{
// Construct the ValueNumber for fldMap[obj/offset]. This (struct)
// map represents the specific field we're looking to store to.
ValueNum firstFieldValueVN = vnStore->VNForMapSelect(VNK_Liberal, firstFieldType,
fldMapVN,
firstFieldValueSelectorVN);

// Construct the maps updating the rest of the fields in the sequence.
newFirstFieldValueVN = vnStore->VNApplySelectorsAssign(VNK_Liberal, firstFieldValueVN,
fldSeq->m_next, storeVal,
indType);
}

// Finally, construct the new field map...
ValueNum newFldMapVN = vnStore->VNForMapStore(vnStore->TypeOfVN(fldMapVN), fldMapVN,
firstFieldValueSelectorVN,
newFirstFieldValueVN);

// ...and a new value for the heap.
newHeapVN = vnStore->VNForMapStore(TYP_REF, fgCurMemoryVN[GcHeap],
firstFieldSelectorVN, newFldMapVN);
Expand Down