Skip to content

Commit 244c8da

Browse files
committed
Account for index 0 and scale 1
1 parent a71d7c8 commit 244c8da

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

src/coreclr/jit/lowerarmarch.cpp

+24-14
Original file line numberDiff line numberDiff line change
@@ -1313,32 +1313,42 @@ GenTree* Lowering::LowerHWIntrinsic(GenTreeHWIntrinsic* node)
13131313
op1 = addr;
13141314
}
13151315

1316-
GenTree* offset;
1316+
GenTree* offset = op2;
1317+
unsigned baseTypeSize = genTypeSize(simdBaseType);
13171318

1318-
if (op2->OperIsConst())
1319+
if (offset->OperIsConst())
13191320
{
13201321
// We have a constant index, so scale it up directly
1321-
GenTreeIntConCommon* index = op2->AsIntCon();
1322-
index->SetIconValue(index->IconValue() * genTypeSize(simdBaseType));
1323-
offset = index;
1322+
GenTreeIntConCommon* index = offset->AsIntCon();
1323+
index->SetIconValue(index->IconValue() * baseTypeSize);
13241324
}
13251325
else
13261326
{
13271327
// We have a non-constant index, so scale it up via mul but
1328-
// don't lower the GT_MUL node since the indir will
1329-
// try to create an addressing mode and will do folding itself
1328+
// don't lower the GT_MUL node since the indir will try to
1329+
// create an addressing mode and will do folding itself. We
1330+
// do, however, skip the multiply for scale == 1
13301331

1331-
GenTreeIntConCommon* scale = comp->gtNewIconNode(genTypeSize(simdBaseType));
1332-
BlockRange().InsertBefore(node, scale);
1332+
if (baseTypeSize != 1)
1333+
{
1334+
GenTreeIntConCommon* scale = comp->gtNewIconNode(baseTypeSize);
1335+
BlockRange().InsertBefore(node, scale);
13331336

1334-
offset = comp->gtNewOperNode(GT_MUL, op2->TypeGet(), op2, scale);
1335-
BlockRange().InsertBefore(node, offset);
1337+
offset = comp->gtNewOperNode(GT_MUL, offset->TypeGet(), offset, scale);
1338+
BlockRange().InsertBefore(node, offset);
1339+
}
13361340
}
13371341

13381342
// Add the offset, don't lower the GT_ADD node since the indir will
1339-
// try to create an addressing mode and will do folding itself
1340-
GenTree* addr = comp->gtNewOperNode(GT_ADD, op1->TypeGet(), op1, offset);
1341-
BlockRange().InsertBefore(node, addr);
1343+
// try to create an addressing mode and will do folding itself. We
1344+
// do, however, skip the add for offset == 0
1345+
GenTree* addr = op1;
1346+
1347+
if (!offset->IsIntegralConst(0))
1348+
{
1349+
addr = comp->gtNewOperNode(GT_ADD, addr->TypeGet(), addr, offset);
1350+
BlockRange().InsertBefore(node, addr);
1351+
}
13421352

13431353
// Finally we can indirect the memory address to get the actual value
13441354
GenTreeIndir* indir = comp->gtNewIndir(simdBaseType, addr);

0 commit comments

Comments
 (0)