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

Fold "FrozenObjectHandle(REF) + CNS" to a byref constant #85888

Merged
merged 7 commits into from
May 9, 2023
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
16 changes: 16 additions & 0 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6247,6 +6247,22 @@ GenTree* Lowering::LowerAdd(GenTreeOp* node)
return next;
}

// Fold "FrozenObjectHandle(REF) + CNS" to a byref constant:
//
// * ADD byref
// +--* CNS_INT(h) ref
// \--* CNS_INT long
//
// We can do this earlier but that will need some efforts (e.g. to restore original object from a
// byref constant for optimizations, be careful with "base constant" CSEs, etc). Also, it can't be
// just enabled for AOT, it needs some way to use reloc + offset then.
if (!comp->opts.IsReadyToRun() && op1->IsIconHandle(GTF_ICON_OBJ_HDL) && op2->IsCnsIntOrI())
EgorBo marked this conversation as resolved.
Show resolved Hide resolved
{
BlockRange().Remove(op1);
BlockRange().Remove(op2);
node->BashToConst(op1->AsIntCon()->IconValue() + op2->AsIntCon()->IconValue(), TYP_BYREF);
}

#ifdef TARGET_XARCH
if (BlockRange().TryGetUse(node, &use))
{
Expand Down