未验证 提交 0e8efce0 编写于 作者: B Bruce Forstall 提交者: GitHub

Support loop cloning of byte array accesses (#48894)

* Support loop cloning of byte array accesses

Cloning pattern matches morphed array index expressions, looking
for expressions that include bounds checks that can potentially
be removed. It wasn't matching array index expressions for byte arrays,
which don't have an index scaling expression. This change simply
matches that pattern.

* Formatting
上级 0c2a8808
......@@ -8453,24 +8453,38 @@ bool Compiler::optIdentifyLoopOptInfo(unsigned loopNum, LoopCloneContext* contex
//
// TODO-CQ: CLONE: After morph make sure this method extracts values before morph.
//
// STMT void(IL 0x007...0x00C)
// [000023] -A-XG+------ * ASG int
// [000022] D----+-N---- +--* LCL_VAR int V06 tmp1
// [000048] ---XG+------ \--* COMMA int
// [000041] ---X-+------ +--* ARR_BOUNDS_CHECK_Rng void
// [000020] -----+------ | +--* LCL_VAR int V04 loc0
// [000040] ---X-+------ | \--* ARR_LENGTH int
// [000019] -----+------ | \--* LCL_VAR ref V00 arg0
// [000021] a--XG+------ \--* IND int
// [000047] -----+------ \--* ADD byref
// [000038] -----+------ +--* LCL_VAR ref V00 arg0
// [000046] -----+------ \--* ADD long
// [000044] -----+------ +--* LSH long
// [000042] -----+------ | +--* CAST long < -int
// [000039] i----+------ | | \--* LCL_VAR int V04 loc0
// [000043] -----+-N---- | \--* CNS_INT long 2
// [000045] -----+------ \--* CNS_INT long 16 Fseq[#FirstElem]
// Example tree to pattern match:
//
// * COMMA int
// +--* ARR_BOUNDS_CHECK_Rng void
// | +--* LCL_VAR int V02 loc1
// | \--* ARR_LENGTH int
// | \--* LCL_VAR ref V00 arg0
// \--* IND int
// \--* ADD byref
// +--* LCL_VAR ref V00 arg0
// \--* ADD long
// +--* LSH long
// | +--* CAST long <- int
// | | \--* LCL_VAR int V02 loc1
// | \--* CNS_INT long 2
// \--* CNS_INT long 16 Fseq[#FirstElem]
//
// Note that byte arrays don't require the LSH to scale the index, so look like this:
//
// * COMMA ubyte
// +--* ARR_BOUNDS_CHECK_Rng void
// | +--* LCL_VAR int V03 loc2
// | \--* ARR_LENGTH int
// | \--* LCL_VAR ref V00 arg0
// \--* IND ubyte
// \--* ADD byref
// +--* LCL_VAR ref V00 arg0
// \--* ADD long
// +--* CAST long <- int
// | \--* LCL_VAR int V03 loc2
// \--* CNS_INT long 16 Fseq[#FirstElem]
//
bool Compiler::optExtractArrIndex(GenTree* tree, ArrIndex* result, unsigned lhsNum)
{
if (tree->gtOper != GT_COMMA)
......@@ -8544,15 +8558,20 @@ bool Compiler::optExtractArrIndex(GenTree* tree, ArrIndex* result, unsigned lhsN
{
return false;
}
if (si->gtOper != GT_LSH)
GenTree* index;
if (si->gtOper == GT_LSH)
{
return false;
GenTree* scale = si->gtGetOp2();
index = si->gtGetOp1();
if (scale->gtOper != GT_CNS_INT)
{
return false;
}
}
GenTree* scale = si->gtGetOp2();
GenTree* index = si->gtGetOp1();
if (scale->gtOper != GT_CNS_INT)
else
{
return false;
// No scale (e.g., byte array).
index = si;
}
#ifdef TARGET_64BIT
if (index->gtOper != GT_CAST)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册