modify gtFoldExprConst for casting to integer from floating point overflow
authorHyeongseok Oh <hseok82.oh@smasung.com>
Fri, 26 Aug 2016 04:24:02 +0000 (13:24 +0900)
committerHyeongseok Oh <hseok82.oh@smasung.com>
Fri, 26 Aug 2016 04:24:02 +0000 (13:24 +0900)
Commit migrated from https://github.com/dotnet/coreclr/commit/8c21c23d979ff55075f0a2ec00d98c1acb7f041f

src/coreclr/src/jit/gentree.cpp
src/coreclr/src/vm/jithelpers.cpp

index ee8c4c8..22b3783 100644 (file)
@@ -11313,39 +11313,15 @@ CHK_OVF:
                     // constants in a target-specific function.
                     CLANG_FORMAT_COMMENT_ANCHOR;
 
-#ifdef _TARGET_XARCH_
                     // Don't fold conversions of +inf/-inf to integral value as the value returned by JIT helper
                     // doesn't match with the C compiler's cast result.
                     return tree;
-#else //!_TARGET_XARCH_
-
-                    switch (tree->CastToType())
-                    {  
-                    case TYP_BYTE:
-                        i1 = ssize_t(INT8(d1)); goto CNS_INT;
-                    case TYP_UBYTE:
-                        i1 = ssize_t(UINT8(d1)); goto CNS_INT;
-                    case TYP_SHORT:
-                        i1 = ssize_t(INT16(d1)); goto CNS_INT;
-                    case TYP_CHAR:
-                        i1 = ssize_t(UINT16(d1)); goto CNS_INT;
-                    case TYP_INT:
-                        i1 = ssize_t(INT32(d1)); goto CNS_INT;
-                    case TYP_UINT:
-                        i1 = ssize_t(UINT32(d1)); goto CNS_INT;
-                    case TYP_LONG: 
-                        lval1 = INT64(d1); goto CNS_LONG;
-                    case TYP_ULONG:
-                        lval1 = UINT64(d1); goto CNS_LONG;
-                    case TYP_FLOAT:
-                    case TYP_DOUBLE:
-                        if (op1->gtType == TYP_FLOAT)
-                            d1 = forceCastToFloat(d1);  // it's only !_finite() after this conversion
-                        goto CNS_DOUBLE;
-                    default:
-                        unreached();
-                    }
-#endif //!_TARGET_XARCH_
+                }
+
+                if (d1 < 0.0) {
+                    if (tree->CastToType() == TYP_CHAR || tree->CastToType() == TYP_UBYTE ||
+                        tree->CastToType() == TYP_UINT || tree->CastToType() == TYP_ULONG)
+                    return tree;
                 }
                
                 switch (tree->CastToType())
index d362078..276c2d6 100644 (file)
@@ -613,7 +613,6 @@ HCIMPL1_V(UINT64, JIT_Dbl2ULng, double val)
 
     const double two63  = 2147483648.0 * 4294967296.0;
     UINT64 ret;
-#ifdef _TARGET_XARCH_
     if (val < two63) {
         ret = FastDbl2Lng(val);
     }
@@ -621,28 +620,6 @@ HCIMPL1_V(UINT64, JIT_Dbl2ULng, double val)
         // subtract 0x8000000000000000, do the convert then add it back again
         ret = FastDbl2Lng(val - two63) + I64(0x8000000000000000);
     }
-#else
-// In x86/x64, conversion result of negative double to unsigned integer is
-// bit-equivalent unsigned value.
-// But other architecture's compiler convert negative doubles to zero when
-// the target is unsigned.
-    if (!_finite(val)) {
-        ret = UINT64(val);
-    }
-    else {
-        if (val >= 0.0) {
-            if (val < two63) {
-                ret = UINT64(val);
-            }
-            else {
-                ret = FastDbl2Lng(val - two63) + I64(0x8000000000000000);
-            }
-        }
-        else {
-            ret = UINT64(val);
-        }
-    }
-#endif
     return ret;
 }
 HCIMPLEND