if (indir->HasIndex())
{
+ assert(addr->OperGet() == GT_LEA);
+
GenTree* index = indir->Index();
if (offset != 0)
{
regNumber tmpReg = indir->GetSingleTempReg();
+ // If the LEA produces a GCREF or BYREF, we need to be careful to mark any temp register
+ // computed with the base register as a BYREF.
+ GenTreeAddrMode* lea = addr->AsAddrMode();
+ emitAttr leaAttr = emitTypeSize(lea);
+ emitAttr leaBasePartialAddrAttr = EA_IS_GCREF_OR_BYREF(leaAttr) ? EA_BYREF : EA_PTRSIZE;
+
if (emitIns_valid_imm_for_add(offset, INS_FLAGS_DONT_CARE))
{
if (lsl > 0)
{
// Generate code to set tmpReg = base + index*scale
- emitIns_R_R_R_I(INS_add, EA_PTRSIZE, tmpReg, memBase->gtRegNum, index->gtRegNum, lsl,
- INS_FLAGS_DONT_CARE, INS_OPTS_LSL);
+ emitIns_R_R_R_I(INS_add, leaBasePartialAddrAttr, tmpReg, memBase->gtRegNum, index->gtRegNum,
+ lsl, INS_FLAGS_DONT_CARE, INS_OPTS_LSL);
}
else // no scale
{
// Generate code to set tmpReg = base + index
- emitIns_R_R_R(INS_add, EA_PTRSIZE, tmpReg, memBase->gtRegNum, index->gtRegNum);
+ emitIns_R_R_R(INS_add, leaBasePartialAddrAttr, tmpReg, memBase->gtRegNum, index->gtRegNum);
}
noway_assert(emitInsIsLoad(ins) || (tmpReg != dataReg));
codeGen->instGen_Set_Reg_To_Imm(EA_PTRSIZE, tmpReg, offset);
// Then add the base register
// rd = rd + base
- emitIns_R_R_R(INS_add, EA_PTRSIZE, tmpReg, tmpReg, memBase->gtRegNum);
+ emitIns_R_R_R(INS_add, leaBasePartialAddrAttr, tmpReg, tmpReg, memBase->gtRegNum);
noway_assert(emitInsIsLoad(ins) || (tmpReg != dataReg));
noway_assert(tmpReg != index->gtRegNum);