From cb1de81e30c7385aa3616a25f99189bc8e275f44 Mon Sep 17 00:00:00 2001 From: Joseph Tremoulet Date: Wed, 18 Jan 2017 06:59:53 -0800 Subject: [PATCH] Refactor GT_IND value-numbering Method `fgValueNumberTree` had two pieces of code each attempting to assume responsibility for `GT_IND` and some block ops. The one later in the function wasn't reachable because those ops would always take the first path. This change moves the special logic for `GTF_IND_ARR_LEN`, which was only present in the unreachable code, up to the reachable code, and removes the unreachable code. Commit migrated from https://github.com/dotnet/coreclr/commit/f178e60b6c7d41698eeb4f04962307803f78137b --- src/coreclr/src/jit/valuenum.cpp | 76 +++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 43 deletions(-) diff --git a/src/coreclr/src/jit/valuenum.cpp b/src/coreclr/src/jit/valuenum.cpp index f31eef2..8b3e710 100644 --- a/src/coreclr/src/jit/valuenum.cpp +++ b/src/coreclr/src/jit/valuenum.cpp @@ -6226,6 +6226,39 @@ void Compiler::fgValueNumberTree(GenTreePtr tree, bool evalAsgLhsInd) fgValueNumberArrIndexVal(tree, elemTypeEq, arrVN, inxVN, addrXvnp.GetLiberal(), fldSeq); } } + else if (tree->gtFlags & GTF_IND_ARR_LEN) + { + // It's an array length. The argument is the sum of an array ref with some integer values... + ValueNum arrRefLib = vnStore->VNForRefInAddr(tree->gtOp.gtOp1->gtVNPair.GetLiberal()); + ValueNum arrRefCons = vnStore->VNForRefInAddr(tree->gtOp.gtOp1->gtVNPair.GetConservative()); + + assert(vnStore->TypeOfVN(arrRefLib) == TYP_REF || vnStore->TypeOfVN(arrRefLib) == TYP_BYREF); + if (vnStore->IsVNConstant(arrRefLib)) + { + // (or in weird cases, a REF or BYREF constant, in which case the result is an exception). + tree->gtVNPair.SetLiberal( + vnStore->VNWithExc(ValueNumStore::VNForVoid(), + vnStore->VNExcSetSingleton( + vnStore->VNForFunc(TYP_REF, VNF_NullPtrExc, arrRefLib)))); + } + else + { + tree->gtVNPair.SetLiberal(vnStore->VNForFunc(TYP_INT, VNFunc(GT_ARR_LENGTH), arrRefLib)); + } + assert(vnStore->TypeOfVN(arrRefCons) == TYP_REF || vnStore->TypeOfVN(arrRefCons) == TYP_BYREF); + if (vnStore->IsVNConstant(arrRefCons)) + { + // (or in weird cases, a REF or BYREF constant, in which case the result is an exception). + tree->gtVNPair.SetConservative( + vnStore->VNWithExc(ValueNumStore::VNForVoid(), + vnStore->VNExcSetSingleton( + vnStore->VNForFunc(TYP_REF, VNF_NullPtrExc, arrRefCons)))); + } + else + { + tree->gtVNPair.SetConservative(vnStore->VNForFunc(TYP_INT, VNFunc(GT_ARR_LENGTH), arrRefCons)); + } + } // In general we skip GT_IND nodes on that are the LHS of an assignment. (We labeled these earlier.) // We will "evaluate" this as part of the assignment. (Unless we're explicitly told by @@ -6506,49 +6539,6 @@ void Compiler::fgValueNumberTree(GenTreePtr tree, bool evalAsgLhsInd) tree->gtOp.gtOp1->gtVNPair))); break; - case GT_BLK: - case GT_OBJ: - case GT_IND: - if (tree->gtFlags & GTF_IND_ARR_LEN) - { - // It's an array length. The argument is the sum of an array ref with some integer values... - ValueNum arrRefLib = vnStore->VNForRefInAddr(tree->gtOp.gtOp1->gtVNPair.GetLiberal()); - ValueNum arrRefCons = vnStore->VNForRefInAddr(tree->gtOp.gtOp1->gtVNPair.GetConservative()); - - assert(vnStore->TypeOfVN(arrRefLib) == TYP_REF || vnStore->TypeOfVN(arrRefLib) == TYP_BYREF); - if (vnStore->IsVNConstant(arrRefLib)) - { - // (or in weird cases, a REF or BYREF constant, in which case the result is an exception). - tree->gtVNPair.SetLiberal( - vnStore->VNWithExc(ValueNumStore::VNForVoid(), - vnStore->VNExcSetSingleton( - vnStore->VNForFunc(TYP_REF, VNF_NullPtrExc, arrRefLib)))); - } - else - { - tree->gtVNPair.SetLiberal(vnStore->VNForFunc(TYP_INT, VNFunc(GT_ARR_LENGTH), arrRefLib)); - } - assert(vnStore->TypeOfVN(arrRefCons) == TYP_REF || vnStore->TypeOfVN(arrRefCons) == TYP_BYREF); - if (vnStore->IsVNConstant(arrRefCons)) - { - // (or in weird cases, a REF or BYREF constant, in which case the result is an exception). - tree->gtVNPair.SetConservative( - vnStore->VNWithExc(ValueNumStore::VNForVoid(), - vnStore->VNExcSetSingleton( - vnStore->VNForFunc(TYP_REF, VNF_NullPtrExc, arrRefCons)))); - } - else - { - tree->gtVNPair.SetConservative( - vnStore->VNForFunc(TYP_INT, VNFunc(GT_ARR_LENGTH), arrRefCons)); - } - } - else - { - tree->gtVNPair.SetBoth(vnStore->VNForExpr(compCurBB, tree->TypeGet())); - } - break; - case GT_LOCKADD: // Binop case GT_XADD: // Binop case GT_XCHG: // Binop -- 2.7.4