Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2052,9 +2052,13 @@ ValueNum ValueNumStore::VNIgnoreIntToLongCast(ValueNum vn)
var_types castToType;
bool srcIsUnsigned;
GetCastOperFromVN(castInfoVN, &castToType, &srcIsUnsigned);
if ((castToType == TYP_LONG) && !srcIsUnsigned && TypeOfVN(srcVN) == TYP_INT)
if ((genActualType(castToType) == TYP_LONG) && (TypeOfVN(srcVN) == TYP_INT))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is genActualType(castToType) doing anything? Isn't that just TYP_ULONG -> TYP_LONG, in which case varTypeIsLong(castToType) is preferred?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is genActualType(castToType) doing anything? Isn't that just TYP_ULONG -> TYP_LONG, in which case varTypeIsLong(castToType) is preferred?

Yep, pretty much the same as varTypeIsLong, will fix as part of some otherchange if no other fixes needed here

Comment thread
tannergooding marked this conversation as resolved.
{
return srcVN;
// A zero-extending cast preserves the sign-extended value only when the source is non-negative.
if (!srcIsUnsigned || IsVNNeverNegative(srcVN))
{
return srcVN;
}
}
}

Expand Down Expand Up @@ -5273,6 +5277,18 @@ ValueNum ValueNumStore::EvalUsingMathIdentity(var_types typ, VNFunc func, ValueN
return resultVN; // return the unsuccessful value
}

// Narrow "(long)x <cmp> (long)y" to an int comparison when both operands are just
// sign-extended ints; only TYP_INT comparisons feed assertion prop / bounds checks.
Comment thread
EgorBo marked this conversation as resolved.
if (VNFuncIsComparison(func) && (TypeOfVN(arg0VN) == TYP_LONG) && (TypeOfVN(arg1VN) == TYP_LONG))
Comment thread
tannergooding marked this conversation as resolved.
{
ValueNum newArg0VN = VNIgnoreIntToLongCast(arg0VN);
ValueNum newArg1VN = VNIgnoreIntToLongCast(arg1VN);
if ((TypeOfVN(newArg0VN) == TYP_INT) && (TypeOfVN(newArg1VN) == TYP_INT))
{
return VNForFunc(TYP_INT, func, newArg0VN, newArg1VN);
}
}

ValueNum cnsVN = NoVN;
ValueNum opVN = NoVN;

Expand Down
Loading