Skip to content

Commit 79c85d9

Browse files
BruceForstallpull[bot]
authored andcommitted
Remove GetFoldedArithOpResultHandleFlags (#100060)
For any constant arithmetic on a handle, lose the handle type: it's unreliable. Eliminates problems seen in #100059
1 parent 3a8fab6 commit 79c85d9

File tree

2 files changed

+5
-62
lines changed

2 files changed

+5
-62
lines changed

src/coreclr/jit/valuenum.cpp

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3593,16 +3593,12 @@ ValueNum ValueNumStore::EvalFuncForConstantArgs(var_types typ, VNFunc func, Valu
35933593
case TYP_INT:
35943594
{
35953595
int resVal = EvalOp<int>(func, ConstantValue<int>(arg0VN));
3596-
// Unary op on a handle results in a handle.
3597-
return IsVNHandle(arg0VN) ? VNForHandle(ssize_t(resVal), GetFoldedArithOpResultHandleFlags(arg0VN))
3598-
: VNForIntCon(resVal);
3596+
return VNForIntCon(resVal);
35993597
}
36003598
case TYP_LONG:
36013599
{
36023600
INT64 resVal = EvalOp<INT64>(func, ConstantValue<INT64>(arg0VN));
3603-
// Unary op on a handle results in a handle.
3604-
return IsVNHandle(arg0VN) ? VNForHandle(ssize_t(resVal), GetFoldedArithOpResultHandleFlags(arg0VN))
3605-
: VNForLongCon(resVal);
3601+
return VNForLongCon(resVal);
36063602
}
36073603
case TYP_FLOAT:
36083604
{
@@ -3854,16 +3850,7 @@ ValueNum ValueNumStore::EvalFuncForConstantArgs(var_types typ, VNFunc func, Valu
38543850
{
38553851
assert(typ == TYP_INT);
38563852
int resultVal = EvalOp<int>(func, arg0Val, arg1Val);
3857-
// Bin op on a handle results in a handle.
3858-
ValueNum handleVN = IsVNHandle(arg0VN) ? arg0VN : IsVNHandle(arg1VN) ? arg1VN : NoVN;
3859-
if (handleVN != NoVN)
3860-
{
3861-
result = VNForHandle(ssize_t(resultVal), GetFoldedArithOpResultHandleFlags(handleVN));
3862-
}
3863-
else
3864-
{
3865-
result = VNForIntCon(resultVal);
3866-
}
3853+
result = VNForIntCon(resultVal);
38673854
}
38683855
}
38693856
else if (arg0VNtyp == TYP_LONG)
@@ -3879,17 +3866,8 @@ ValueNum ValueNumStore::EvalFuncForConstantArgs(var_types typ, VNFunc func, Valu
38793866
else
38803867
{
38813868
assert(typ == TYP_LONG);
3882-
INT64 resultVal = EvalOp<INT64>(func, arg0Val, arg1Val);
3883-
ValueNum handleVN = IsVNHandle(arg0VN) ? arg0VN : IsVNHandle(arg1VN) ? arg1VN : NoVN;
3884-
3885-
if (handleVN != NoVN)
3886-
{
3887-
result = VNForHandle(ssize_t(resultVal), GetFoldedArithOpResultHandleFlags(handleVN));
3888-
}
3889-
else
3890-
{
3891-
result = VNForLongCon(resultVal);
3892-
}
3869+
INT64 resultVal = EvalOp<INT64>(func, arg0Val, arg1Val);
3870+
result = VNForLongCon(resultVal);
38933871
}
38943872
}
38953873
else // both args are TYP_REF or both args are TYP_BYREF
@@ -6191,39 +6169,6 @@ GenTreeFlags ValueNumStore::GetHandleFlags(ValueNum vn)
61916169
return handleFlags;
61926170
}
61936171

6194-
GenTreeFlags ValueNumStore::GetFoldedArithOpResultHandleFlags(ValueNum vn)
6195-
{
6196-
GenTreeFlags flags = GetHandleFlags(vn);
6197-
assert((flags & GTF_ICON_HDL_MASK) == flags);
6198-
6199-
switch (flags)
6200-
{
6201-
case GTF_ICON_SCOPE_HDL:
6202-
case GTF_ICON_CLASS_HDL:
6203-
case GTF_ICON_METHOD_HDL:
6204-
case GTF_ICON_FIELD_HDL:
6205-
case GTF_ICON_TOKEN_HDL:
6206-
case GTF_ICON_STR_HDL:
6207-
case GTF_ICON_OBJ_HDL:
6208-
case GTF_ICON_CONST_PTR:
6209-
case GTF_ICON_VARG_HDL:
6210-
case GTF_ICON_PINVKI_HDL:
6211-
case GTF_ICON_FTN_ADDR:
6212-
case GTF_ICON_CIDMID_HDL:
6213-
case GTF_ICON_TLS_HDL:
6214-
case GTF_ICON_STATIC_BOX_PTR:
6215-
case GTF_ICON_STATIC_ADDR_PTR:
6216-
return GTF_ICON_CONST_PTR;
6217-
case GTF_ICON_STATIC_HDL:
6218-
case GTF_ICON_GLOBAL_PTR:
6219-
case GTF_ICON_BBC_PTR:
6220-
return GTF_ICON_GLOBAL_PTR;
6221-
default:
6222-
assert(!"Unexpected handle type");
6223-
return flags;
6224-
}
6225-
}
6226-
62276172
bool ValueNumStore::IsVNHandle(ValueNum vn)
62286173
{
62296174
if (vn == NoVN)

src/coreclr/jit/valuenum.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,6 @@ class ValueNumStore
404404
// returns true iff vn is known to be a constant int32 that is > 0
405405
bool IsVNPositiveInt32Constant(ValueNum vn);
406406

407-
GenTreeFlags GetFoldedArithOpResultHandleFlags(ValueNum vn);
408-
409407
public:
410408
// Validate that the new initializer for s_vnfOpAttribs matches the old code.
411409
static void ValidateValueNumStoreStatics();

0 commit comments

Comments
 (0)