@@ -11416,6 +11416,20 @@ GenTreePtr Compiler::fgMorphSmpOp(GenTreePtr tree, MorphAddrContext* mac)
11416
11416
}
11417
11417
}
11418
11418
11419
+ // If gtOp1 is a GT_FIELD, we need to pass down the mac if
11420
+ // its parent is GT_ADDR, since the address of the field
11421
+ // is part of an ongoing address computation. Otherwise
11422
+ // op1 represents the value of the field and so any address
11423
+ // calculations it does are in a new context.
11424
+ if ((op1->gtOper == GT_FIELD) && (tree->gtOper != GT_ADDR))
11425
+ {
11426
+ subMac1 = nullptr;
11427
+
11428
+ // The impact of this field's value to any ongoing
11429
+ // address computation is handled below when looking
11430
+ // at op2.
11431
+ }
11432
+
11419
11433
tree->gtOp.gtOp1 = op1 = fgMorphTree(op1, subMac1);
11420
11434
11421
11435
#if LOCAL_ASSERTION_PROP
@@ -11496,7 +11510,6 @@ GenTreePtr Compiler::fgMorphSmpOp(GenTreePtr tree, MorphAddrContext* mac)
11496
11510
// (These are used to convey parent context about how addresses being calculated
11497
11511
// will be used; see the specification comment for MorphAddrContext for full details.)
11498
11512
// Assume it's an Ind context to start.
11499
- MorphAddrContext subIndMac2(MACK_Ind);
11500
11513
switch (tree->gtOper)
11501
11514
{
11502
11515
case GT_ADD:
@@ -11517,6 +11530,17 @@ GenTreePtr Compiler::fgMorphSmpOp(GenTreePtr tree, MorphAddrContext* mac)
11517
11530
default:
11518
11531
break;
11519
11532
}
11533
+
11534
+ // If gtOp2 is a GT_FIELD, we must be taking its value,
11535
+ // so it should evaluate its address in a new context.
11536
+ if (op2->gtOper == GT_FIELD)
11537
+ {
11538
+ // The impact of this field's value to any ongoing
11539
+ // address computation is handled above when looking
11540
+ // at op1.
11541
+ mac = nullptr;
11542
+ }
11543
+
11520
11544
tree->gtOp.gtOp2 = op2 = fgMorphTree(op2, mac);
11521
11545
11522
11546
/* Propagate the side effect flags from op2 */
0 commit comments