Skip to content

Commit

Permalink
Improve codegen for Span/ReadOnlySpan indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
GrabYourPitchforks committed Mar 8, 2019
1 parent 24d05f5 commit d14b977
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3423,7 +3423,7 @@ class Compiler

static void impBashVarAddrsToI(GenTree* tree1, GenTree* tree2 = nullptr);

GenTree* impImplicitIorI4Cast(GenTree* tree, var_types dstTyp);
GenTree* impImplicitIorI4Cast(GenTree* tree, var_types dstTyp, bool zeroExtend = false);

GenTree* impImplicitR4orR8Cast(GenTree* tree, var_types dstTyp);

Expand Down
10 changes: 7 additions & 3 deletions src/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2946,9 +2946,13 @@ void Compiler::impBashVarAddrsToI(GenTree* tree1, GenTree* tree2)
* exist in the IL (at least on 64-bit where TYP_I_IMPL != TYP_INT) are
* turned into explicit casts here.
* We also allow an implicit conversion of a ldnull into a TYP_I_IMPL(0)
*
* If zeroExtend = false (default), if a non-const 32-bit input is
* widened to 64 bits it will be sign-extended. If zeroExtend = true, it
* will instead be zero-extended.
*/

GenTree* Compiler::impImplicitIorI4Cast(GenTree* tree, var_types dstTyp)
GenTree* Compiler::impImplicitIorI4Cast(GenTree* tree, var_types dstTyp, bool zeroExtend)
{
var_types currType = genActualType(tree->gtType);
var_types wantedType = genActualType(dstTyp);
Expand All @@ -2967,7 +2971,7 @@ GenTree* Compiler::impImplicitIorI4Cast(GenTree* tree, var_types dstTyp)
else if (varTypeIsI(wantedType) && (currType == TYP_INT))
{
// Note that this allows TYP_INT to be cast to a TYP_I_IMPL when wantedType is a TYP_BYREF or TYP_REF
tree = gtNewCastNode(TYP_I_IMPL, tree, false, TYP_I_IMPL);
tree = gtNewCastNode(TYP_I_IMPL, tree, zeroExtend /* fromUnsigned */, TYP_I_IMPL);
}
else if ((wantedType == TYP_INT) && varTypeIsI(currType))
{
Expand Down Expand Up @@ -3885,7 +3889,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
GenTreeBoundsChk(GT_ARR_BOUNDS_CHECK, TYP_VOID, index, length, SCK_RNGCHK_FAIL);

// Element access
GenTree* indexIntPtr = impImplicitIorI4Cast(indexClone, TYP_I_IMPL);
GenTree* indexIntPtr = impImplicitIorI4Cast(indexClone, TYP_I_IMPL, true /* zeroExtend */);
GenTree* sizeofNode = gtNewIconNode(elemSize);
GenTree* mulNode = gtNewOperNode(GT_MUL, TYP_I_IMPL, indexIntPtr, sizeofNode);
CORINFO_FIELD_HANDLE ptrHnd = info.compCompHnd->getFieldInClass(clsHnd, 0);
Expand Down

0 comments on commit d14b977

Please sign in to comment.