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: Unspecialize handle types after arithmetic ops in VN #70452

Merged
merged 1 commit into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
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
41 changes: 37 additions & 4 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2869,13 +2869,15 @@ ValueNum ValueNumStore::EvalFuncForConstantArgs(var_types typ, VNFunc func, Valu
{
int resVal = EvalOp<int>(func, ConstantValue<int>(arg0VN));
// Unary op on a handle results in a handle.
return IsVNHandle(arg0VN) ? VNForHandle(ssize_t(resVal), GetHandleFlags(arg0VN)) : VNForIntCon(resVal);
return IsVNHandle(arg0VN) ? VNForHandle(ssize_t(resVal), GetFoldedArithOpResultHandleFlags(arg0VN))
: VNForIntCon(resVal);
}
case TYP_LONG:
{
INT64 resVal = EvalOp<INT64>(func, ConstantValue<INT64>(arg0VN));
// Unary op on a handle results in a handle.
return IsVNHandle(arg0VN) ? VNForHandle(ssize_t(resVal), GetHandleFlags(arg0VN)) : VNForLongCon(resVal);
return IsVNHandle(arg0VN) ? VNForHandle(ssize_t(resVal), GetFoldedArithOpResultHandleFlags(arg0VN))
: VNForLongCon(resVal);
}
case TYP_FLOAT:
{
Expand Down Expand Up @@ -3106,7 +3108,7 @@ ValueNum ValueNumStore::EvalFuncForConstantArgs(var_types typ, VNFunc func, Valu
ValueNum handleVN = IsVNHandle(arg0VN) ? arg0VN : IsVNHandle(arg1VN) ? arg1VN : NoVN;
if (handleVN != NoVN)
{
result = VNForHandle(ssize_t(resultVal), GetHandleFlags(handleVN)); // Use VN for Handle
result = VNForHandle(ssize_t(resultVal), GetFoldedArithOpResultHandleFlags(handleVN));
}
else
{
Expand All @@ -3132,7 +3134,7 @@ ValueNum ValueNumStore::EvalFuncForConstantArgs(var_types typ, VNFunc func, Valu

if (handleVN != NoVN)
{
result = VNForHandle(ssize_t(resultVal), GetHandleFlags(handleVN)); // Use VN for Handle
result = VNForHandle(ssize_t(resultVal), GetFoldedArithOpResultHandleFlags(handleVN));
}
else
{
Expand Down Expand Up @@ -5119,6 +5121,37 @@ GenTreeFlags ValueNumStore::GetHandleFlags(ValueNum vn)
return handle->m_flags;
}

GenTreeFlags ValueNumStore::GetFoldedArithOpResultHandleFlags(ValueNum vn)
{
GenTreeFlags flags = GetHandleFlags(vn);
assert((flags & GTF_ICON_HDL_MASK) == flags);

switch (flags)
{
case GTF_ICON_SCOPE_HDL:
case GTF_ICON_CLASS_HDL:
case GTF_ICON_METHOD_HDL:
case GTF_ICON_FIELD_HDL:
case GTF_ICON_TOKEN_HDL:
case GTF_ICON_STR_HDL:
case GTF_ICON_CONST_PTR:
case GTF_ICON_VARG_HDL:
case GTF_ICON_PINVKI_HDL:
case GTF_ICON_FTN_ADDR:
case GTF_ICON_CIDMID_HDL:
case GTF_ICON_TLS_HDL:
case GTF_ICON_STATIC_BOX_PTR:
return GTF_ICON_CONST_PTR;
case GTF_ICON_STATIC_HDL:
case GTF_ICON_GLOBAL_PTR:
case GTF_ICON_BBC_PTR:
return GTF_ICON_GLOBAL_PTR;
default:
assert(!"Unexpected handle type");
return flags;
}
}

bool ValueNumStore::IsVNHandle(ValueNum vn)
{
if (vn == NoVN)
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/valuenum.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ class ValueNumStore
// returns true iff vn is known to be a constant int32 that is > 0
bool IsVNPositiveInt32Constant(ValueNum vn);

GenTreeFlags GetFoldedArithOpResultHandleFlags(ValueNum vn);

public:
// Initializes any static variables of ValueNumStore.
static void InitValueNumStoreStatics();
Expand Down