This repository was archived by the owner on Jan 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -461,12 +461,26 @@ GenTree* Compiler::fgMorphCast(GenTree* tree)
461
461
// Don't try to optimize.
462
462
assert(!canPushCast);
463
463
}
464
- else if (( shiftAmountValue >= 32) && ((tree->gtFlags & GTF_ALL_EFFECT) == 0) )
464
+ else if (shiftAmountValue >= 32)
465
465
{
466
- // Result of the shift is zero.
467
- DEBUG_DESTROY_NODE(tree);
468
- GenTree* zero = gtNewZeroConNode(TYP_INT);
469
- return fgMorphTree(zero);
466
+ // We know that we have a narrowing cast ([u]long -> [u]int)
467
+ // and that we are casting to a 32-bit value, which will result in zero.
468
+ //
469
+ // Check to see if we have any side-effects that we must keep
470
+ //
471
+ if ((tree->gtFlags & GTF_ALL_EFFECT) == 0)
472
+ {
473
+ // Result of the shift is zero.
474
+ DEBUG_DESTROY_NODE(tree);
475
+ GenTree* zero = gtNewZeroConNode(TYP_INT);
476
+ return fgMorphTree(zero);
477
+ }
478
+ else // We do have a side-effect
479
+ {
480
+ // We could create a GT_COMMA node here to keep the side-effect and return a zero
481
+ // Instead we just don't try to optimize this case.
482
+ canPushCast = false;
483
+ }
470
484
}
471
485
else
472
486
{
You can’t perform that action at this time.
0 commit comments