Skip to content

Commit 53db2ec

Browse files
Do not eliminate casts from FP types (#53667)
An optimization in morph was deleting casts on the RHS of a narrow store if the cast-to-type was wider than the type being stored. This is only valid for casts from integral types, as the backend does not handle "STOREIND(byte*, double)", nor is there an instruction to go from an XMM register to a narrow memory location on x86/x64. The issue is not reproducible right now because fgMorphCast wraps the casts in question, but it is an invalid IR transformation nonetheless, and similar code in fgMorphSmpOpOptional guards against non-integral sources.
1 parent c6acf8d commit 53db2ec

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/coreclr/jit/morph.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12071,18 +12071,19 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac)
1207112071
tree->AsOp()->gtOp1 = op1;
1207212072
}
1207312073

12074-
/* If we are storing a small type, we might be able to omit a cast */
12075-
if ((effectiveOp1->gtOper == GT_IND) && varTypeIsSmall(effectiveOp1->TypeGet()))
12074+
// If we are storing a small type, we might be able to omit a cast.
12075+
if (effectiveOp1->OperIs(GT_IND) && varTypeIsSmall(effectiveOp1))
1207612076
{
12077-
if (!gtIsActiveCSE_Candidate(op2) && (op2->gtOper == GT_CAST) && !op2->gtOverflow())
12077+
if (!gtIsActiveCSE_Candidate(op2) && op2->OperIs(GT_CAST) &&
12078+
varTypeIsIntegral(op2->AsCast()->CastOp()) && !op2->gtOverflow())
1207812079
{
1207912080
var_types castType = op2->CastToType();
1208012081

1208112082
// If we are performing a narrowing cast and
1208212083
// castType is larger or the same as op1's type
1208312084
// then we can discard the cast.
1208412085

12085-
if (varTypeIsSmall(castType) && (genTypeSize(castType) >= genTypeSize(effectiveOp1->TypeGet())))
12086+
if (varTypeIsSmall(castType) && (genTypeSize(castType) >= genTypeSize(effectiveOp1)))
1208612087
{
1208712088
tree->AsOp()->gtOp2 = op2 = op2->AsCast()->CastOp();
1208812089
}

0 commit comments

Comments
 (0)