Skip to content

Commit 44f040f

Browse files
committed
Add support for native int for loop range optimizations
1 parent 035c36b commit 44f040f

File tree

9 files changed

+168
-42
lines changed

9 files changed

+168
-42
lines changed

src/coreclr/src/jit/assertionprop.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,11 @@ AssertionInfo Compiler::optCreateJTrueBoundsAssertion(GenTree* tree)
18201820
dsc.op1.kind = O1K_BOUND_LOOP_BND;
18211821
dsc.op1.vn = relopVN;
18221822
dsc.op2.kind = O2K_CONST_INT;
1823+
#ifdef STARK
1824+
dsc.op2.vn = vnStore->VNZeroForType(TYP_I_IMPL);
1825+
#else
18231826
dsc.op2.vn = vnStore->VNZeroForType(TYP_INT);
1827+
#endif
18241828
dsc.op2.u1.iconVal = 0;
18251829
dsc.op2.u1.iconFlags = 0;
18261830
AssertionIndex index = optAddAssertion(&dsc);
@@ -1880,7 +1884,11 @@ AssertionInfo Compiler::optCreateJTrueBoundsAssertion(GenTree* tree)
18801884
dsc.op1.kind = O1K_CONSTANT_LOOP_BND;
18811885
dsc.op1.vn = relopVN;
18821886
dsc.op2.kind = O2K_CONST_INT;
1887+
#ifdef STARK
1888+
dsc.op2.vn = vnStore->VNZeroForType(TYP_I_IMPL);
1889+
#else
18831890
dsc.op2.vn = vnStore->VNZeroForType(TYP_INT);
1891+
#endif
18841892
dsc.op2.u1.iconVal = 0;
18851893
dsc.op2.u1.iconFlags = 0;
18861894
AssertionIndex index = optAddAssertion(&dsc);

src/coreclr/src/jit/importer.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -15976,8 +15976,11 @@ void Compiler::impImportBlockCode(BasicBlock* block)
1597615976
if (opts.OptimizationEnabled())
1597715977
{
1597815978
/* Use GT_ARR_LENGTH operator so rng check opts see this */
15979+
#ifdef STARK
15980+
GenTreeArrLen* arrLen = gtNewArrLen(TYP_I_IMPL, op1, OFFSETOF__CORINFO_Array__length);
15981+
#else
1597915982
GenTreeArrLen* arrLen = gtNewArrLen(TYP_INT, op1, OFFSETOF__CORINFO_Array__length);
15980-
15983+
#endif
1598115984
/* Mark the block as containing a length expression */
1598215985

1598315986
if (op1->gtOper == GT_LCL_VAR)

src/coreclr/src/jit/morph.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -5492,6 +5492,10 @@ GenTree* Compiler::fgMorphArrayIndex(GenTree* tree)
54925492
}
54935493

54945494
// Next introduce a GT_ARR_BOUNDS_CHECK node
5495+
#ifdef STARK
5496+
var_types bndsChkType = TYP_I_IMPL; // By default, always use a native int
5497+
GenTree* arrLen = gtNewArrLen(TYP_I_IMPL, arrRef, (int)lenOffs);
5498+
#else
54955499
var_types bndsChkType = TYP_INT; // By default, try to use 32-bit comparison for array bounds check.
54965500

54975501
#ifdef _TARGET_64BIT_
@@ -5510,6 +5514,7 @@ GenTree* Compiler::fgMorphArrayIndex(GenTree* tree)
55105514
{
55115515
arrLen = gtNewCastNode(bndsChkType, arrLen, false, bndsChkType);
55125516
}
5517+
#endif
55135518

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

src/coreclr/src/jit/optimizer.cpp

+51
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,11 @@ bool Compiler::optPopulateInitInfo(unsigned loopInd, GenTree* init, unsigned ite
729729

730730
// RHS can be constant or local var.
731731
// TODO-CQ: CLONE: Add arr length for descending loops.
732+
#ifdef STARK
733+
if (rhs->gtOper == GT_CNS_INT && rhs->TypeGet() == TYP_I_IMPL)
734+
#else
732735
if (rhs->gtOper == GT_CNS_INT && rhs->TypeGet() == TYP_INT)
736+
#endif
733737
{
734738
optLoopTable[loopInd].lpFlags |= LPFLG_CONST_INIT;
735739
optLoopTable[loopInd].lpConstInit = (int)rhs->AsIntCon()->gtIconVal;
@@ -803,7 +807,11 @@ bool Compiler::optCheckIterInLoopTest(
803807
return false;
804808
}
805809

810+
#ifdef STARK
811+
if (iterOp->gtType != TYP_I_IMPL)
812+
#else
806813
if (iterOp->gtType != TYP_INT)
814+
#endif
807815
{
808816
return false;
809817
}
@@ -875,7 +883,11 @@ unsigned Compiler::optIsLoopIncrTree(GenTree* incr)
875883

876884
// Increment should be by a const int.
877885
// TODO-CQ: CLONE: allow variable increments.
886+
#ifdef STARK
887+
if ((incrVal->gtOper != GT_CNS_INT) || (incrVal->TypeGet() != TYP_I_IMPL))
888+
#else
878889
if ((incrVal->gtOper != GT_CNS_INT) || (incrVal->TypeGet() != TYP_INT))
890+
#endif
879891
{
880892
return BAD_VAR_NUM;
881893
}
@@ -2989,6 +3001,10 @@ bool jitIterSmallOverflow(int iterAtExit, var_types incrType)
29893001

29903002
case TYP_UINT: // Detected by checking for 32bit ....
29913003
case TYP_INT:
3004+
#ifdef STARK
3005+
case TYP_ULONG: // Detected by checking for 64bit ....
3006+
case TYP_LONG:
3007+
#endif
29923008
return false; // ... overflow same as done for TYP_INT
29933009

29943010
default:
@@ -3030,6 +3046,10 @@ bool jitIterSmallUnderflow(int iterAtExit, var_types decrType)
30303046

30313047
case TYP_UINT: // Detected by checking for 32bit ....
30323048
case TYP_INT:
3049+
#ifdef STARK
3050+
case TYP_ULONG: // Detected by checking for 64bit ....
3051+
case TYP_LONG:
3052+
#endif
30333053
return false; // ... underflow same as done for TYP_INT
30343054

30353055
default:
@@ -3062,7 +3082,11 @@ bool Compiler::optComputeLoopRep(int constInit,
30623082
bool dupCond,
30633083
unsigned* iterCount)
30643084
{
3085+
#ifdef STARK
3086+
noway_assert(genActualType(iterOperType) == TYP_I_IMPL);
3087+
#else
30653088
noway_assert(genActualType(iterOperType) == TYP_INT);
3089+
#endif
30663090

30673091
__int64 constInitX;
30683092
__int64 constLimitX;
@@ -3115,6 +3139,20 @@ bool Compiler::optComputeLoopRep(int constInit,
31153139
}
31163140
break;
31173141

3142+
#ifdef STARK
3143+
case TYP_LONG:
3144+
case TYP_ULONG:
3145+
if (unsTest)
3146+
{
3147+
constInitX = (unsigned long long)constInit;
3148+
}
3149+
else
3150+
{
3151+
constInitX = (long long)constInit;
3152+
}
3153+
break;
3154+
#endif
3155+
31183156
default:
31193157
noway_assert(!"Bad type");
31203158
NO_WAY("Bad type");
@@ -5633,6 +5671,14 @@ bool Compiler::optNarrowTree(GenTree* tree, var_types srct, var_types dstt, Valu
56335671
case TYP_UINT:
56345672
imask = 0xFFFFFFFF;
56355673
break;
5674+
#ifdef STARK
5675+
case TYP_LONG:
5676+
imask = 0x7FFFFFFFFFFFFFFF;
5677+
break;
5678+
case TYP_ULONG:
5679+
imask = 0xFFFFFFFFFFFFFFFF;
5680+
break;
5681+
#endif
56365682
#endif // _TARGET_64BIT_
56375683
default:
56385684
return false;
@@ -5646,8 +5692,13 @@ bool Compiler::optNarrowTree(GenTree* tree, var_types srct, var_types dstt, Valu
56465692
#ifdef _TARGET_64BIT_
56475693
if (doit)
56485694
{
5695+
#ifdef STARK
5696+
tree->gtType = TYP_I_IMPL;
5697+
tree->AsIntCon()->gtIconVal = (NATIVE_INT)ival;
5698+
#else
56495699
tree->gtType = TYP_INT;
56505700
tree->AsIntCon()->gtIconVal = (int)ival;
5701+
#endif
56515702
if (vnStore != nullptr)
56525703
{
56535704
fgValueNumberTreeConst(tree);

0 commit comments

Comments
 (0)