From b311010828ff9436beab4b6f7e3bcee3bf1fbefe Mon Sep 17 00:00:00 2001 From: Bruce Forstall Date: Wed, 20 Mar 2024 23:13:50 -0700 Subject: [PATCH] Remove GetFoldedArithOpResultHandleFlags For any constant arithmetic on a handle, lose the handle type: it's unreliable. Eliminates problems seen in https://github.com/dotnet/runtime/issues/100059 --- src/coreclr/jit/valuenum.cpp | 65 +++--------------------------------- src/coreclr/jit/valuenum.h | 2 -- 2 files changed, 5 insertions(+), 62 deletions(-) diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 4922e1f3da0a6..fe61b1e810823 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -3593,16 +3593,12 @@ ValueNum ValueNumStore::EvalFuncForConstantArgs(var_types typ, VNFunc func, Valu case TYP_INT: { int resVal = EvalOp(func, ConstantValue(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(func, ConstantValue(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: { @@ -3854,16 +3850,7 @@ ValueNum ValueNumStore::EvalFuncForConstantArgs(var_types typ, VNFunc func, Valu { assert(typ == TYP_INT); int resultVal = EvalOp(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) @@ -3879,17 +3866,8 @@ ValueNum ValueNumStore::EvalFuncForConstantArgs(var_types typ, VNFunc func, Valu else { assert(typ == TYP_LONG); - INT64 resultVal = EvalOp(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(func, arg0Val, arg1Val); + result = VNForLongCon(resultVal); } } else // both args are TYP_REF or both args are TYP_BYREF @@ -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) diff --git a/src/coreclr/jit/valuenum.h b/src/coreclr/jit/valuenum.h index ef8bd48229a15..a976893a06581 100644 --- a/src/coreclr/jit/valuenum.h +++ b/src/coreclr/jit/valuenum.h @@ -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();