Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Сhange children order in GenTreeBoundsChk. Fix #8077 #8806

Merged
merged 1 commit into from
Jan 12, 2017
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
8 changes: 4 additions & 4 deletions src/jit/codegenarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,11 +885,14 @@ void CodeGen::genRangeCheck(GenTreePtr oper)
noway_assert(oper->OperGet() == GT_ARR_BOUNDS_CHECK);
GenTreeBoundsChk* bndsChk = oper->AsBoundsChk();

GenTreePtr arrLen = bndsChk->gtArrLen->gtEffectiveVal();
GenTreePtr arrIdx = bndsChk->gtIndex->gtEffectiveVal();
GenTreePtr arrLen = bndsChk->gtArrLen->gtEffectiveVal();
GenTreePtr arrRef = NULL;
int lenOffset = 0;

genConsumeIfReg(arrIdx);
genConsumeIfReg(arrLen);

GenTree * src1, *src2;
emitJumpKind jmpKind;

Expand All @@ -908,9 +911,6 @@ void CodeGen::genRangeCheck(GenTreePtr oper)
jmpKind = genJumpKindForOper(GT_GE, CK_UNSIGNED);
}

genConsumeIfReg(src1);
genConsumeIfReg(src2);

getEmitter()->emitInsBinary(INS_cmp, emitAttr(TYP_INT), src1, src2);
genJumpToThrowHlpBlk(jmpKind, SCK_RNGCHK_FAIL, bndsChk->gtIndRngFailBB);
}
Expand Down
2 changes: 1 addition & 1 deletion src/jit/codegenarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3798,8 +3798,8 @@ void CodeGen::genRangeCheck(GenTreePtr oper)
GenTree * src1, *src2;
emitJumpKind jmpKind;

genConsumeRegs(arrLen);
genConsumeRegs(arrIndex);
genConsumeRegs(arrLen);

if (arrIndex->isContainedIntOrIImmed())
{
Expand Down
25 changes: 14 additions & 11 deletions src/jit/codegenlegacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1837,6 +1837,15 @@ void CodeGen::genRangeCheck(GenTreePtr oper)
GenTreePtr arrRef = NULL;
int lenOffset = 0;

/* Is the array index a constant value? */
GenTreePtr index = bndsChk->gtIndex;
if (!index->IsCnsIntOrI())
{
// No, it's not a constant.
genCodeForTree(index, RBM_ALLINT);
regSet.rsMarkRegUsed(index);
}

// If "arrLen" is a ARR_LENGTH operation, get the array whose length that takes in a register.
// Otherwise, if the length is not a constant, get it (the length, not the arr reference) in
// a register.
Expand Down Expand Up @@ -1884,14 +1893,8 @@ void CodeGen::genRangeCheck(GenTreePtr oper)
}
}

/* Is the array index a constant value? */
GenTreePtr index = bndsChk->gtIndex;
if (!index->IsCnsIntOrI())
{
// No, it's not a constant.
genCodeForTree(index, RBM_ALLINT);
regSet.rsMarkRegUsed(index);

// If we need "arrRef" or "arrLen", and evaluating "index" displaced whichever of them we're using
// from its register, get it back in a register.
if (arrRef != NULL)
Expand Down Expand Up @@ -1983,6 +1986,11 @@ void CodeGen::genRangeCheck(GenTreePtr oper)
}

// Free the registers that were used.
if (!index->IsCnsIntOrI())
{
regSet.rsMarkRegFree(index->gtRegNum, index);
}

if (arrRef != NULL)
{
regSet.rsMarkRegFree(arrRef->gtRegNum, arrRef);
Expand All @@ -1991,11 +1999,6 @@ void CodeGen::genRangeCheck(GenTreePtr oper)
{
regSet.rsMarkRegFree(arrLen->gtRegNum, arrLen);
}

if (!index->IsCnsIntOrI())
{
regSet.rsMarkRegFree(index->gtRegNum, index);
}
}

/*****************************************************************************
Expand Down
4 changes: 2 additions & 2 deletions src/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3863,16 +3863,16 @@ void CodeGen::genRangeCheck(GenTreePtr oper)

GenTreeBoundsChk* bndsChk = oper->AsBoundsChk();

GenTreePtr arrLen = bndsChk->gtArrLen;
GenTreePtr arrIndex = bndsChk->gtIndex;
GenTreePtr arrLen = bndsChk->gtArrLen;
GenTreePtr arrRef = nullptr;
int lenOffset = 0;

GenTree * src1, *src2;
emitJumpKind jmpKind;

genConsumeRegs(arrLen);
genConsumeRegs(arrIndex);
genConsumeRegs(arrLen);

if (arrIndex->isContainedIntOrIImmed())
{
Expand Down
2 changes: 1 addition & 1 deletion src/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6850,8 +6850,8 @@ void Compiler::CopyTestDataToCloneTree(GenTreePtr from, GenTreePtr to)
#ifdef FEATURE_SIMD
case GT_SIMD_CHK:
#endif // FEATURE_SIMD
CopyTestDataToCloneTree(from->gtBoundsChk.gtArrLen, to->gtBoundsChk.gtArrLen);
CopyTestDataToCloneTree(from->gtBoundsChk.gtIndex, to->gtBoundsChk.gtIndex);
CopyTestDataToCloneTree(from->gtBoundsChk.gtArrLen, to->gtBoundsChk.gtArrLen);
return;

default:
Expand Down
2 changes: 1 addition & 1 deletion src/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18004,8 +18004,8 @@ void Compiler::fgSetTreeSeqHelper(GenTreePtr tree, bool isLIR)
case GT_SIMD_CHK:
#endif // FEATURE_SIMD
// Evaluate the trees left to right
fgSetTreeSeqHelper(tree->gtBoundsChk.gtArrLen, isLIR);
fgSetTreeSeqHelper(tree->gtBoundsChk.gtIndex, isLIR);
fgSetTreeSeqHelper(tree->gtBoundsChk.gtArrLen, isLIR);
break;

case GT_STORE_DYN_BLK:
Expand Down
64 changes: 32 additions & 32 deletions src/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,12 +847,12 @@ Compiler::fgWalkResult Compiler::fgWalkTreePreRec(GenTreePtr* pTree, fgWalkData*
#ifdef FEATURE_SIMD
case GT_SIMD_CHK:
#endif // FEATURE_SIMD
result = fgWalkTreePreRec<computeStack>(&tree->gtBoundsChk.gtArrLen, fgWalkData);
result = fgWalkTreePreRec<computeStack>(&tree->gtBoundsChk.gtIndex, fgWalkData);
if (result == WALK_ABORT)
{
return result;
}
result = fgWalkTreePreRec<computeStack>(&tree->gtBoundsChk.gtIndex, fgWalkData);
result = fgWalkTreePreRec<computeStack>(&tree->gtBoundsChk.gtArrLen, fgWalkData);
if (result == WALK_ABORT)
{
return result;
Expand Down Expand Up @@ -1102,12 +1102,12 @@ Compiler::fgWalkResult Compiler::fgWalkTreePostRec(GenTreePtr* pTree, fgWalkData
#ifdef FEATURE_SIMD
case GT_SIMD_CHK:
#endif // FEATURE_SIMD
result = fgWalkTreePostRec<computeStack>(&tree->gtBoundsChk.gtArrLen, fgWalkData);
result = fgWalkTreePostRec<computeStack>(&tree->gtBoundsChk.gtIndex, fgWalkData);
if (result == WALK_ABORT)
{
return result;
}
result = fgWalkTreePostRec<computeStack>(&tree->gtBoundsChk.gtIndex, fgWalkData);
result = fgWalkTreePostRec<computeStack>(&tree->gtBoundsChk.gtArrLen, fgWalkData);
if (result == WALK_ABORT)
{
return result;
Expand Down Expand Up @@ -1446,12 +1446,12 @@ Compiler::fgWalkResult Compiler::fgWalkTreeRec(GenTreePtr* pTree, fgWalkData* fg
#ifdef FEATURE_SIMD
case GT_SIMD_CHK:
#endif // FEATURE_SIMD
result = fgWalkTreeRec<doPreOrder, doPostOrder>(&tree->gtBoundsChk.gtArrLen, fgWalkData);
result = fgWalkTreeRec<doPreOrder, doPostOrder>(&tree->gtBoundsChk.gtIndex, fgWalkData);
if (result == WALK_ABORT)
{
return result;
}
result = fgWalkTreeRec<doPreOrder, doPostOrder>(&tree->gtBoundsChk.gtIndex, fgWalkData);
result = fgWalkTreeRec<doPreOrder, doPostOrder>(&tree->gtBoundsChk.gtArrLen, fgWalkData);
if (result == WALK_ABORT)
{
return result;
Expand Down Expand Up @@ -2378,8 +2378,8 @@ bool GenTree::Compare(GenTreePtr op1, GenTreePtr op2, bool swapOK)
#ifdef FEATURE_SIMD
case GT_SIMD_CHK:
#endif // FEATURE_SIMD
return Compare(op1->gtBoundsChk.gtArrLen, op2->gtBoundsChk.gtArrLen) &&
Compare(op1->gtBoundsChk.gtIndex, op2->gtBoundsChk.gtIndex) &&
return Compare(op1->gtBoundsChk.gtIndex, op2->gtBoundsChk.gtIndex) &&
Compare(op1->gtBoundsChk.gtArrLen, op2->gtBoundsChk.gtArrLen) &&
(op1->gtBoundsChk.gtThrowKind == op2->gtBoundsChk.gtThrowKind);

case GT_STORE_DYN_BLK:
Expand Down Expand Up @@ -2604,11 +2604,11 @@ bool Compiler::gtHasRef(GenTreePtr tree, ssize_t lclNum, bool defOnly)
#ifdef FEATURE_SIMD
case GT_SIMD_CHK:
#endif // FEATURE_SIMD
if (gtHasRef(tree->gtBoundsChk.gtArrLen, lclNum, defOnly))
if (gtHasRef(tree->gtBoundsChk.gtIndex, lclNum, defOnly))
{
return true;
}
if (gtHasRef(tree->gtBoundsChk.gtIndex, lclNum, defOnly))
if (gtHasRef(tree->gtBoundsChk.gtArrLen, lclNum, defOnly))
{
return true;
}
Expand Down Expand Up @@ -3001,8 +3001,8 @@ unsigned Compiler::gtHashValue(GenTree* tree)
#ifdef FEATURE_SIMD
case GT_SIMD_CHK:
#endif // FEATURE_SIMD
hash = genTreeHashAdd(hash, gtHashValue(tree->gtBoundsChk.gtArrLen));
hash = genTreeHashAdd(hash, gtHashValue(tree->gtBoundsChk.gtIndex));
hash = genTreeHashAdd(hash, gtHashValue(tree->gtBoundsChk.gtArrLen));
hash = genTreeHashAdd(hash, tree->gtBoundsChk.gtThrowKind);
break;

Expand Down Expand Up @@ -3265,12 +3265,12 @@ bool Compiler::lvaLclVarRefs(GenTreePtr tree, GenTreePtr* findPtr, varRefKinds*
case GT_SIMD_CHK:
#endif // FEATURE_SIMD
{
if (!lvaLclVarRefsAccum(tree->gtBoundsChk.gtArrLen, findPtr, refsPtr, &allVars, &trkdVars))
if (!lvaLclVarRefsAccum(tree->gtBoundsChk.gtIndex, findPtr, refsPtr, &allVars, &trkdVars))
{
return false;
}
// Otherwise...
if (!lvaLclVarRefsAccum(tree->gtBoundsChk.gtIndex, findPtr, refsPtr, &allVars, &trkdVars))
if (!lvaLclVarRefsAccum(tree->gtBoundsChk.gtArrLen, findPtr, refsPtr, &allVars, &trkdVars))
{
return false;
}
Expand Down Expand Up @@ -5622,17 +5622,17 @@ unsigned Compiler::gtSetEvalOrder(GenTree* tree)
costEx = 4; // cmp reg,reg and jae throw (not taken)
costSz = 7; // jump to cold section

level = gtSetEvalOrder(tree->gtBoundsChk.gtArrLen);
costEx += tree->gtBoundsChk.gtArrLen->gtCostEx;
costSz += tree->gtBoundsChk.gtArrLen->gtCostSz;
level = gtSetEvalOrder(tree->gtBoundsChk.gtIndex);
costEx += tree->gtBoundsChk.gtIndex->gtCostEx;
costSz += tree->gtBoundsChk.gtIndex->gtCostSz;

lvl2 = gtSetEvalOrder(tree->gtBoundsChk.gtIndex);
lvl2 = gtSetEvalOrder(tree->gtBoundsChk.gtArrLen);
if (level < lvl2)
{
level = lvl2;
}
costEx += tree->gtBoundsChk.gtIndex->gtCostEx;
costSz += tree->gtBoundsChk.gtIndex->gtCostSz;
costEx += tree->gtBoundsChk.gtArrLen->gtCostEx;
costSz += tree->gtBoundsChk.gtArrLen->gtCostSz;

break;

Expand Down Expand Up @@ -5954,8 +5954,8 @@ void Compiler::gtComputeFPlvls(GenTreePtr tree)
break;

case GT_ARR_BOUNDS_CHECK:
gtComputeFPlvls(tree->gtBoundsChk.gtArrLen);
gtComputeFPlvls(tree->gtBoundsChk.gtIndex);
gtComputeFPlvls(tree->gtBoundsChk.gtArrLen);
noway_assert(!isflt);
break;

Expand Down Expand Up @@ -6134,14 +6134,14 @@ GenTreePtr* GenTree::gtGetChildPointer(GenTreePtr parent)
#ifdef FEATURE_SIMD
case GT_SIMD_CHK:
#endif // FEATURE_SIMD
if (this == parent->gtBoundsChk.gtArrLen)
{
return &(parent->gtBoundsChk.gtArrLen);
}
if (this == parent->gtBoundsChk.gtIndex)
{
return &(parent->gtBoundsChk.gtIndex);
}
if (this == parent->gtBoundsChk.gtArrLen)
{
return &(parent->gtBoundsChk.gtArrLen);
}
if (this == parent->gtBoundsChk.gtIndRngFailBB)
{
return &(parent->gtBoundsChk.gtIndRngFailBB);
Expand Down Expand Up @@ -8341,8 +8341,8 @@ GenTreePtr Compiler::gtCloneExpr(
#endif // FEATURE_SIMD
copy = new (this, oper)
GenTreeBoundsChk(oper, tree->TypeGet(),
gtCloneExpr(tree->gtBoundsChk.gtArrLen, addFlags, deepVarNum, deepVarVal),
gtCloneExpr(tree->gtBoundsChk.gtIndex, addFlags, deepVarNum, deepVarVal),
gtCloneExpr(tree->gtBoundsChk.gtArrLen, addFlags, deepVarNum, deepVarVal),
tree->gtBoundsChk.gtThrowKind);
break;

Expand Down Expand Up @@ -9051,9 +9051,9 @@ GenTreePtr GenTree::GetChild(unsigned childNum)
switch (childNum)
{
case 0:
return AsBoundsChk()->gtArrLen;
case 1:
return AsBoundsChk()->gtIndex;
case 1:
return AsBoundsChk()->gtArrLen;
default:
unreached();
}
Expand Down Expand Up @@ -9227,9 +9227,9 @@ GenTree** GenTreeUseEdgeIterator::GetNextUseEdge() const
switch (m_state)
{
case 0:
return &m_node->AsBoundsChk()->gtArrLen;
case 1:
return &m_node->AsBoundsChk()->gtIndex;
case 1:
return &m_node->AsBoundsChk()->gtArrLen;
default:
return nullptr;
}
Expand Down Expand Up @@ -11721,8 +11721,8 @@ void Compiler::gtDispTree(GenTreePtr tree,
printf("\n");
if (!topOnly)
{
gtDispChild(tree->gtBoundsChk.gtArrLen, indentStack, IIArc, nullptr, topOnly);
gtDispChild(tree->gtBoundsChk.gtIndex, indentStack, IIArcBottom, nullptr, topOnly);
gtDispChild(tree->gtBoundsChk.gtIndex, indentStack, IIArc, nullptr, topOnly);
gtDispChild(tree->gtBoundsChk.gtArrLen, indentStack, IIArcBottom, nullptr, topOnly);
}
break;

Expand Down Expand Up @@ -14642,8 +14642,8 @@ void Compiler::gtExtractSideEffList(GenTreePtr expr,
#endif // FEATURE_SIMD
)
{
gtExtractSideEffList(expr->AsBoundsChk()->gtArrLen, pList, flags);
gtExtractSideEffList(expr->AsBoundsChk()->gtIndex, pList, flags);
gtExtractSideEffList(expr->AsBoundsChk()->gtArrLen, pList, flags);
}

if (expr->OperGet() == GT_DYN_BLK || expr->OperGet() == GT_STORE_DYN_BLK)
Expand Down
6 changes: 3 additions & 3 deletions src/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -3764,8 +3764,8 @@ struct GenTreeArrLen : public GenTreeUnOp

struct GenTreeBoundsChk : public GenTree
{
GenTreePtr gtArrLen; // An expression for the length of the array being indexed.
GenTreePtr gtIndex; // The index expression.
GenTreePtr gtArrLen; // An expression for the length of the array being indexed.

GenTreePtr gtIndRngFailBB; // Label to jump to for array-index-out-of-range
SpecialCodeKind gtThrowKind; // Kind of throw block to branch to on failure
Expand All @@ -3775,10 +3775,10 @@ struct GenTreeBoundsChk : public GenTree
optimizer has a chance of eliminating some of the rng checks */
unsigned gtStkDepth;

GenTreeBoundsChk(genTreeOps oper, var_types type, GenTreePtr arrLen, GenTreePtr index, SpecialCodeKind kind)
GenTreeBoundsChk(genTreeOps oper, var_types type, GenTreePtr index, GenTreePtr arrLen, SpecialCodeKind kind)
: GenTree(oper, type)
, gtArrLen(arrLen)
, gtIndex(index)
, gtArrLen(arrLen)
, gtIndRngFailBB(nullptr)
, gtThrowKind(kind)
, gtStkDepth(0)
Expand Down
6 changes: 3 additions & 3 deletions src/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5683,7 +5683,7 @@ GenTreePtr Compiler::fgMorphArrayIndex(GenTreePtr tree)
}

GenTreeBoundsChk* arrBndsChk = new (this, GT_ARR_BOUNDS_CHECK)
GenTreeBoundsChk(GT_ARR_BOUNDS_CHECK, TYP_VOID, arrLen, index, SCK_RNGCHK_FAIL);
GenTreeBoundsChk(GT_ARR_BOUNDS_CHECK, TYP_VOID, index, arrLen, SCK_RNGCHK_FAIL);

bndsChk = arrBndsChk;

Expand Down Expand Up @@ -14696,17 +14696,17 @@ GenTreePtr Compiler::fgMorphTree(GenTreePtr tree, MorphAddrContext* mac)
fgSetRngChkTarget(tree);

GenTreeBoundsChk* bndsChk = tree->AsBoundsChk();
bndsChk->gtArrLen = fgMorphTree(bndsChk->gtArrLen);
bndsChk->gtIndex = fgMorphTree(bndsChk->gtIndex);
bndsChk->gtArrLen = fgMorphTree(bndsChk->gtArrLen);
// If the index is a comma(throw, x), just return that.
if (!optValnumCSE_phase && fgIsCommaThrow(bndsChk->gtIndex))
{
tree = bndsChk->gtIndex;
}

// Propagate effects flags upwards
bndsChk->gtFlags |= (bndsChk->gtArrLen->gtFlags & GTF_ALL_EFFECT);
bndsChk->gtFlags |= (bndsChk->gtIndex->gtFlags & GTF_ALL_EFFECT);
bndsChk->gtFlags |= (bndsChk->gtArrLen->gtFlags & GTF_ALL_EFFECT);

// Otherwise, we don't change the tree.
}
Expand Down
4 changes: 2 additions & 2 deletions src/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7662,11 +7662,11 @@ bool Compiler::optExtractArrIndex(GenTreePtr tree, ArrIndex* result, unsigned lh
return false;
}
GenTreeBoundsChk* arrBndsChk = before->AsBoundsChk();
if (arrBndsChk->gtArrLen->gtGetOp1()->gtOper != GT_LCL_VAR)
if (arrBndsChk->gtIndex->gtOper != GT_LCL_VAR)
{
return false;
}
if (arrBndsChk->gtIndex->gtOper != GT_LCL_VAR)
if (arrBndsChk->gtArrLen->gtGetOp1()->gtOper != GT_LCL_VAR)
{
return false;
}
Expand Down
Loading