Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 2448e08

Browse files
Merge pull request #6754 from hseok-oh/castd2ul
disable gtFoldExprConst for conversion from negative double to unsigned long
2 parents ff7731c + 358846b commit 2448e08

File tree

2 files changed

+12
-41
lines changed

2 files changed

+12
-41
lines changed

src/jit/gentree.cpp

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12495,49 +12495,20 @@ GenTreePtr Compiler::gtFoldExprConst(GenTreePtr tree)
1249512495
// constants in a target-specific function.
1249612496
CLANG_FORMAT_COMMENT_ANCHOR;
1249712497

12498-
#ifdef _TARGET_XARCH_
12499-
// Don't fold conversions of +inf/-inf to integral value as the value returned by JIT helper
12500-
// doesn't match with the C compiler's cast result.
12498+
// Don't fold conversions of +inf/-inf to integral value on all platforms
12499+
// as the value returned by JIT helper doesn't match with the C compiler's cast result.
12500+
// We want the behavior to be same with or without folding.
1250112501
return tree;
12502-
#else //!_TARGET_XARCH_
12503-
12504-
switch (tree->CastToType())
12505-
{
12506-
case TYP_BYTE:
12507-
i1 = ssize_t(INT8(d1));
12508-
goto CNS_INT;
12509-
case TYP_UBYTE:
12510-
i1 = ssize_t(UINT8(d1));
12511-
goto CNS_INT;
12512-
case TYP_SHORT:
12513-
i1 = ssize_t(INT16(d1));
12514-
goto CNS_INT;
12515-
case TYP_CHAR:
12516-
i1 = ssize_t(UINT16(d1));
12517-
goto CNS_INT;
12518-
case TYP_INT:
12519-
i1 = ssize_t(INT32(d1));
12520-
goto CNS_INT;
12521-
case TYP_UINT:
12522-
i1 = ssize_t(UINT32(d1));
12523-
goto CNS_INT;
12524-
case TYP_LONG:
12525-
lval1 = INT64(d1);
12526-
goto CNS_LONG;
12527-
case TYP_ULONG:
12528-
lval1 = UINT64(d1);
12529-
goto CNS_LONG;
12530-
case TYP_FLOAT:
12531-
case TYP_DOUBLE:
12532-
if (op1->gtType == TYP_FLOAT)
12533-
d1 = forceCastToFloat(d1); // it's only !_finite() after this conversion
12534-
goto CNS_DOUBLE;
12535-
default:
12536-
unreached();
12537-
}
12538-
#endif //!_TARGET_XARCH_
1253912502
}
1254012503

12504+
if (d1 <= -1.0 && varTypeIsUnsigned(tree->CastToType()))
12505+
{
12506+
// Don't fold conversions of these cases becasue the result is unspecified per ECMA spec
12507+
// and the native math doing the fold doesn't match the run-time computation on all platforms.
12508+
// We want the behavior to be same with or without folding.
12509+
return tree;
12510+
}
12511+
1254112512
switch (tree->CastToType())
1254212513
{
1254312514
case TYP_BYTE:

src/vm/jithelpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ HCIMPL1_V(UINT64, JIT_Dbl2ULng, double val)
619619
else {
620620
// subtract 0x8000000000000000, do the convert then add it back again
621621
ret = FastDbl2Lng(val - two63) + I64(0x8000000000000000);
622-
}
622+
}
623623
return ret;
624624
}
625625
HCIMPLEND

0 commit comments

Comments
 (0)