@@ -1313,32 +1313,42 @@ GenTree* Lowering::LowerHWIntrinsic(GenTreeHWIntrinsic* node)
1313
1313
op1 = addr;
1314
1314
}
1315
1315
1316
- GenTree* offset;
1316
+ GenTree* offset = op2;
1317
+ unsigned baseTypeSize = genTypeSize (simdBaseType);
1317
1318
1318
- if (op2 ->OperIsConst ())
1319
+ if (offset ->OperIsConst ())
1319
1320
{
1320
1321
// 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);
1324
1324
}
1325
1325
else
1326
1326
{
1327
1327
// 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
1330
1331
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);
1333
1336
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
+ }
1336
1340
}
1337
1341
1338
1342
// 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
+ }
1342
1352
1343
1353
// Finally we can indirect the memory address to get the actual value
1344
1354
GenTreeIndir* indir = comp->gtNewIndir (simdBaseType, addr);
0 commit comments