Skip to content

Commit a1a0850

Browse files
Assert instead of normalizing
Instead of normalizing GTF_UNSIGNED for FP sources in "gtNewCastNode", assert that it is not set in GenTreeCast's constructor and fix the importer to respect that constraint.
1 parent 6e87a65 commit a1a0850

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/coreclr/jit/compiler.hpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,18 +1410,9 @@ inline void GenTree::SetOper(genTreeOps oper, ValueNumberUpdate vnUpdate)
14101410
}
14111411
}
14121412

1413-
inline void CanonicalizeCastNode(GenTreeCast* cast)
1414-
{
1415-
if (varTypeIsFloating(cast->CastOp()))
1416-
{
1417-
cast->gtFlags &= ~GTF_UNSIGNED;
1418-
}
1419-
}
1420-
14211413
inline GenTreeCast* Compiler::gtNewCastNode(var_types typ, GenTree* op1, bool fromUnsigned, var_types castType)
14221414
{
14231415
GenTreeCast* cast = new (this, GT_CAST) GenTreeCast(typ, op1, fromUnsigned, castType);
1424-
CanonicalizeCastNode(cast);
14251416

14261417
return cast;
14271418
}
@@ -1437,7 +1428,6 @@ inline GenTreeCast* Compiler::gtNewCastNodeL(var_types typ, GenTree* op1, bool f
14371428

14381429
GenTreeCast* cast =
14391430
new (this, LargeOpOpcode()) GenTreeCast(typ, op1, fromUnsigned, castType DEBUGARG(/*largeNode*/ true));
1440-
CanonicalizeCastNode(cast);
14411431

14421432
return cast;
14431433
}

src/coreclr/jit/gentree.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3531,6 +3531,11 @@ struct GenTreeCast : public GenTreeOp
35313531
GenTreeCast(var_types type, GenTree* op, bool fromUnsigned, var_types castType DEBUGARG(bool largeNode = false))
35323532
: GenTreeOp(GT_CAST, type, op, nullptr DEBUGARG(largeNode)), gtCastType(castType)
35333533
{
3534+
// We do not allow casts from floating point types to be treated as from
3535+
// unsigned to avoid bugs related to wrong GTF_UNSIGNED in case the
3536+
// CastOp's type changes.
3537+
assert(!varTypeIsFloating(op) || !fromUnsigned);
3538+
35343539
gtFlags |= fromUnsigned ? GTF_UNSIGNED : GTF_EMPTY;
35353540
}
35363541
#if DEBUGGABLE_GENTREE

src/coreclr/jit/importer.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13456,11 +13456,17 @@ void Compiler::impImportBlockCode(BasicBlock* block)
1345613456
callNode = varTypeIsFloating(impStackTop().val->TypeGet());
1345713457
}
1345813458

13459-
// At this point uns, ovf, callNode are all set.
13460-
1346113459
op1 = impPopStack().val;
1346213460
impBashVarAddrsToI(op1);
1346313461

13462+
// Casts from floating point types must not have GTF_UNSIGNED set.
13463+
if (varTypeIsFloating(op1))
13464+
{
13465+
uns = false;
13466+
}
13467+
13468+
// At this point uns, ovf, callNode are all set.
13469+
1346413470
if (varTypeIsSmall(lclTyp) && !ovfl && op1->gtType == TYP_INT && op1->gtOper == GT_AND)
1346513471
{
1346613472
op2 = op1->AsOp()->gtOp2;

0 commit comments

Comments
 (0)