Skip to content

Commit

Permalink
Remove GetFoldedArithOpResultHandleFlags
Browse files Browse the repository at this point in the history
For any constant arithmetic on a handle, lose the handle type: it's unreliable.

Eliminates problems seen in dotnet#100059
  • Loading branch information
BruceForstall committed Mar 21, 2024
1 parent 67f113c commit 72224f5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 62 deletions.
65 changes: 5 additions & 60 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3593,16 +3593,12 @@ ValueNum ValueNumStore::EvalFuncForConstantArgs(var_types typ, VNFunc func, Valu
case TYP_INT:
{
int resVal = EvalOp<int>(func, ConstantValue<int>(arg0VN));
// Unary op on a handle results in a handle.
return IsVNHandle(arg0VN) ? VNForHandle(ssize_t(resVal), GetFoldedArithOpResultHandleFlags(arg0VN))
: VNForIntCon(resVal);
return 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), GetFoldedArithOpResultHandleFlags(arg0VN))
: VNForLongCon(resVal);
return VNForLongCon(resVal);
}
case TYP_FLOAT:
{
Expand Down Expand Up @@ -3854,16 +3850,7 @@ ValueNum ValueNumStore::EvalFuncForConstantArgs(var_types typ, VNFunc func, Valu
{
assert(typ == TYP_INT);
int resultVal = EvalOp<int>(func, arg0Val, arg1Val);
// Bin op on a handle results in a handle.
ValueNum handleVN = IsVNHandle(arg0VN) ? arg0VN : IsVNHandle(arg1VN) ? arg1VN : NoVN;
if (handleVN != NoVN)
{
result = VNForHandle(ssize_t(resultVal), GetFoldedArithOpResultHandleFlags(handleVN));
}
else
{
result = VNForIntCon(resultVal);
}
result = VNForIntCon(resultVal);
}
}
else if (arg0VNtyp == TYP_LONG)
Expand All @@ -3879,17 +3866,8 @@ ValueNum ValueNumStore::EvalFuncForConstantArgs(var_types typ, VNFunc func, Valu
else
{
assert(typ == TYP_LONG);
INT64 resultVal = EvalOp<INT64>(func, arg0Val, arg1Val);
ValueNum handleVN = IsVNHandle(arg0VN) ? arg0VN : IsVNHandle(arg1VN) ? arg1VN : NoVN;

if (handleVN != NoVN)
{
result = VNForHandle(ssize_t(resultVal), GetFoldedArithOpResultHandleFlags(handleVN));
}
else
{
result = VNForLongCon(resultVal);
}
INT64 resultVal = EvalOp<INT64>(func, arg0Val, arg1Val);
result = VNForLongCon(resultVal);
}
}
else // both args are TYP_REF or both args are TYP_BYREF
Expand Down Expand Up @@ -6191,39 +6169,6 @@ GenTreeFlags ValueNumStore::GetHandleFlags(ValueNum vn)
return handleFlags;
}

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_OBJ_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:
case GTF_ICON_STATIC_ADDR_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: 0 additions & 2 deletions src/coreclr/jit/valuenum.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,6 @@ 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:
// Validate that the new initializer for s_vnfOpAttribs matches the old code.
static void ValidateValueNumStoreStatics();
Expand Down

0 comments on commit 72224f5

Please sign in to comment.