Skip to content

Commit

Permalink
Use local assertion prop to omit casts on returns (#55632)
Browse files Browse the repository at this point in the history
When inserting normalizing casts for returns in pre-order
morph, "fgMorphCast" was used, which did not account for
the fact that local assertion propagation could tell us
that the cast is in fact unnecessary. Fix this by calling
"fgMorphTree" instead.

Also some miscellaneous code cleanup.
  • Loading branch information
SingleAccretion authored Jul 15, 2021
1 parent 0733681 commit 9cfb02a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11482,7 +11482,7 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac)

case GT_RETURN:
// normalize small integer return values
if (fgGlobalMorph && varTypeIsSmall(info.compRetType) && (op1 != nullptr) && (op1->TypeGet() != TYP_VOID) &&
if (fgGlobalMorph && varTypeIsSmall(info.compRetType) && (op1 != nullptr) && !op1->TypeIs(TYP_VOID) &&
fgCastNeeded(op1, info.compRetType))
{
// Small-typed return values are normalized by the callee
Expand All @@ -11491,11 +11491,10 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac)
// Propagate GTF_COLON_COND
op1->gtFlags |= (tree->gtFlags & GTF_COLON_COND);

tree->AsOp()->gtOp1 = fgMorphCast(op1);
tree->AsOp()->gtOp1 = fgMorphTree(op1);

// Propagate side effect flags
tree->gtFlags &= ~GTF_ALL_EFFECT;
tree->gtFlags |= (tree->AsOp()->gtOp1->gtFlags & GTF_ALL_EFFECT);
tree->SetAllEffectsFlags(tree->AsOp()->gtGetOp1());

return tree;
}
Expand Down

0 comments on commit 9cfb02a

Please sign in to comment.