@@ -4150,7 +4150,7 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
4150
4150
GenTree* ptrToSpan = impPopStack().val;
4151
4151
GenTree* indexClone = nullptr;
4152
4152
GenTree* ptrToSpanClone = nullptr;
4153
- assert(varTypeIsIntegral (index));
4153
+ assert(genActualType (index) == TYP_INT );
4154
4154
assert(ptrToSpan->TypeGet() == TYP_BYREF);
4155
4155
4156
4156
#if defined(DEBUG)
@@ -4177,13 +4177,29 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
4177
4177
GenTreeBoundsChk(GT_ARR_BOUNDS_CHECK, TYP_VOID, index, length, SCK_RNGCHK_FAIL);
4178
4178
4179
4179
// Element access
4180
- GenTree* indexIntPtr = impImplicitIorI4Cast(indexClone, TYP_I_IMPL);
4181
- GenTree* sizeofNode = gtNewIconNode(elemSize);
4182
- GenTree* mulNode = gtNewOperNode(GT_MUL, TYP_I_IMPL, indexIntPtr, sizeofNode);
4183
- CORINFO_FIELD_HANDLE ptrHnd = info.compCompHnd->getFieldInClass(clsHnd, 0);
4184
- const unsigned ptrOffset = info.compCompHnd->getFieldOffset(ptrHnd);
4185
- GenTree* data = gtNewFieldRef(TYP_BYREF, ptrHnd, ptrToSpanClone, ptrOffset);
4186
- GenTree* result = gtNewOperNode(GT_ADD, TYP_BYREF, data, mulNode);
4180
+ index = indexClone;
4181
+
4182
+ #ifdef TARGET_64BIT
4183
+ if (index->OperGet() == GT_CNS_INT)
4184
+ {
4185
+ index->gtType = TYP_I_IMPL;
4186
+ }
4187
+ else
4188
+ {
4189
+ index = gtNewCastNode(TYP_I_IMPL, index, true, TYP_I_IMPL);
4190
+ }
4191
+ #endif
4192
+
4193
+ if (elemSize != 1)
4194
+ {
4195
+ GenTree* sizeofNode = gtNewIconNode(elemSize);
4196
+ index = gtNewOperNode(GT_MUL, TYP_I_IMPL, index, sizeofNode);
4197
+ }
4198
+
4199
+ CORINFO_FIELD_HANDLE ptrHnd = info.compCompHnd->getFieldInClass(clsHnd, 0);
4200
+ const unsigned ptrOffset = info.compCompHnd->getFieldOffset(ptrHnd);
4201
+ GenTree* data = gtNewFieldRef(TYP_BYREF, ptrHnd, ptrToSpanClone, ptrOffset);
4202
+ GenTree* result = gtNewOperNode(GT_ADD, TYP_BYREF, data, index);
4187
4203
4188
4204
// Prepare result
4189
4205
var_types resultType = JITtype2varType(sig->retType);
0 commit comments