Skip to content

Commit 735dcde

Browse files
committed
remove non-promoted span
1 parent 3905663 commit 735dcde

File tree

2 files changed

+14
-49
lines changed

2 files changed

+14
-49
lines changed

src/coreclr/jit/loopcloning.cpp

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ GenTree* LC_Array::ToGenTree(Compiler* comp, BasicBlock* bb)
7171
int rank = GetDimRank();
7272

7373
// rank is always 0 for spans
74-
assert(!arrIndex->IsSpan() || (rank == 0));
74+
assert(!arrIndex->isSpan || (rank == 0));
7575

7676
for (int i = 0; i < rank; ++i)
7777
{
@@ -93,14 +93,7 @@ GenTree* LC_Array::ToGenTree(Compiler* comp, BasicBlock* bb)
9393
if (oper == ArrLen)
9494
{
9595
GenTree* arrLen;
96-
if (arrIndex->isNonPromotedSpan)
97-
{
98-
// For non-promoted spans, we emit IND(ADD(arr, sizeof(ptr)))
99-
GenTreeIntCon* offset = comp->gtNewIconNode(OFFSETOF__CORINFO_Span__length, TYP_I_IMPL);
100-
GenTreeOp* addOffset = comp->gtNewOperNode(GT_ADD, TYP_BYREF, arr, offset);
101-
arrLen = comp->gtNewIndir(TYP_INT, addOffset);
102-
}
103-
else if (arrIndex->isPromotedSpan)
96+
if (arrIndex->isSpan)
10497
{
10598
// For promoted spans, arr is already our length.
10699
assert(arr->OperIs(GT_LCL_VAR));
@@ -979,10 +972,10 @@ void LC_ArrayDeref::DeriveLevelConditions(JitExpandArrayStack<JitExpandArrayStac
979972
{
980973
if (level == 0)
981974
{
982-
if (this->array.arrIndex->isPromotedSpan)
975+
if (this->array.arrIndex->isSpan)
983976
{
984-
// For Spans (at least, for the promoted ones) we don't need "array != null" check
985-
// but since the current algorithm doesn't expect that this condition might not be
977+
// For promoted Spans we don't need the "array != null" check.
978+
// However, the current algorithm doesn't expect that this condition might not be
986979
// needed, we insert a dummy always-true condition.
987980
//
988981
(*conds)[level]->Push(
@@ -997,7 +990,7 @@ void LC_ArrayDeref::DeriveLevelConditions(JitExpandArrayStack<JitExpandArrayStac
997990
}
998991
else
999992
{
1000-
assert(!this->array.arrIndex->IsSpan());
993+
assert(!this->array.arrIndex->isSpan);
1001994

1002995
// Adjust for level0 having just 1 condition and push conditions (i >= 0) && (i < a.len).
1003996
// We fold the two compares into one using unsigned compare, since we know a.len is non-negative.
@@ -1129,7 +1122,7 @@ bool Compiler::optDeriveLoopCloningConditions(FlowGraphNaturalLoop* loop, LoopCl
11291122
{
11301123
case LcOptInfo::LcJaggedArray:
11311124
// Keep a note that we might be dealing with a Span
1132-
spanInvolved |= optInfo->AsLcJaggedArrayOptInfo()->arrIndex.IsSpan();
1125+
spanInvolved |= optInfo->AsLcJaggedArrayOptInfo()->arrIndex.isSpan;
11331126
checkIterationBehavior = true;
11341127
break;
11351128

@@ -2285,43 +2278,23 @@ bool Compiler::optExtractArrIndex(GenTree* tree, ArrIndex* result, unsigned lhsN
22852278
return false;
22862279
}
22872280

2288-
bool isPromotedSpan = false;
2289-
bool isNonPromotedSpan = false;
2281+
bool isSpan = false;
22902282
unsigned arrLcl;
22912283
GenTree* arrLen = arrBndsChk->GetArrayLength();
22922284
if (arrLen->OperIsArrLength() && arrLen->gtGetOp1()->OperIs(GT_LCL_VAR))
22932285
{
22942286
// Case 1: Arrays (jagged or multi-dimensional), Strings
22952287
arrLcl = arrLen->gtGetOp1()->AsLclVarCommon()->GetLclNum();
22962288
}
2297-
else if (arrLen->OperIs(GT_IND) && arrLen->AsIndir()->Addr()->OperIs(GT_ADD))
2298-
{
2299-
// Case 2: Non-promoted spans (rare case)
2300-
GenTree* add = arrLen->AsIndir()->Addr();
2301-
if (add->gtGetOp1()->OperIs(GT_LCL_VAR) && add->gtGetOp2()->IsIntegralConst(OFFSETOF__CORINFO_Span__length))
2302-
{
2303-
arrLcl = add->gtGetOp1()->AsLclVarCommon()->GetLclNum();
2304-
if (!lvaGetDesc(arrLcl)->IsSpan())
2305-
{
2306-
return false;
2307-
}
2308-
isNonPromotedSpan = true;
2309-
assert(arrLen->TypeIs(TYP_INT));
2310-
}
2311-
else
2312-
{
2313-
return false;
2314-
}
2315-
}
23162289
else if (arrLen->OperIs(GT_LCL_VAR))
23172290
{
2318-
// Case 3: Promoted spans
2291+
// Case 2: Promoted spans
23192292
arrLcl = arrLen->AsLclVarCommon()->GetLclNum();
23202293
if (!lvaGetDesc(arrLcl)->IsSpanLength())
23212294
{
23222295
return false;
23232296
}
2324-
isPromotedSpan = true;
2297+
isSpan = true;
23252298
assert(arrLen->TypeIs(TYP_INT));
23262299
}
23272300
else
@@ -2338,10 +2311,9 @@ bool Compiler::optExtractArrIndex(GenTree* tree, ArrIndex* result, unsigned lhsN
23382311

23392312
if (lhsNum == BAD_VAR_NUM)
23402313
{
2341-
result->arrLcl = arrLcl;
2342-
result->isPromotedSpan = isPromotedSpan;
2343-
result->isNonPromotedSpan = isNonPromotedSpan;
2314+
result->arrLcl = arrLcl;
23442315
}
2316+
result->isSpan = isSpan;
23452317
result->indLcls.Push(indLcl);
23462318
result->bndsChks.Push(tree);
23472319
result->useBlock = compCurBB;

src/coreclr/jit/loopcloning.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,25 +195,18 @@ struct ArrIndex
195195
JitExpandArrayStack<GenTree*> bndsChks; // The bounds checks nodes along each dimension.
196196
unsigned rank; // Rank of the array
197197
BasicBlock* useBlock; // Block where the [] occurs
198-
bool isPromotedSpan;
199-
bool isNonPromotedSpan;
198+
bool isSpan;
200199

201200
ArrIndex(CompAllocator alloc)
202201
: arrLcl(BAD_VAR_NUM)
203202
, indLcls(alloc)
204203
, bndsChks(alloc)
205204
, rank(0)
206205
, useBlock(nullptr)
207-
, isPromotedSpan(false)
208-
, isNonPromotedSpan(false)
206+
, isSpan(false)
209207
{
210208
}
211209

212-
bool IsSpan() const
213-
{
214-
return isPromotedSpan || isNonPromotedSpan;
215-
}
216-
217210
#ifdef DEBUG
218211
void Print(unsigned dim = -1);
219212
void PrintBoundsCheckNodes(unsigned dim = -1);

0 commit comments

Comments
 (0)