JIT: ensure float folding is done using float precision (dotnet/coreclr#20578)
authorAndy Ayers <andya@microsoft.com>
Thu, 25 Oct 2018 15:17:49 +0000 (08:17 -0700)
committerGitHub <noreply@github.com>
Thu, 25 Oct 2018 15:17:49 +0000 (08:17 -0700)
Cast float folded values back to float before assigning to the double
the jit uses for storing FP literal constants.

Fixes dotnet/coreclr#20561.

No diffs on Core; exposing the original bug requires building RyuJit with
an older x86 C++ compiler that uses x87 floating point.

Commit migrated from https://github.com/dotnet/coreclr/commit/1370fb92bc9c1ae9475e92f8638c827128c84527

src/coreclr/src/jit/gentree.cpp

index 37feba6..5c785da 100644 (file)
@@ -14082,7 +14082,7 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
                     i1 = (d1 > d2);
                     goto FOLD_COND;
 
-                // non-x86 arch: floating point arithmetic should be done in declared
+                // Floating point arithmetic should be done in declared
                 // precision while doing constant folding. For this reason though TYP_FLOAT
                 // constants are stored as double constants, while performing float arithmetic,
                 // double constants should be converted to float.  Here is an example case
@@ -14099,7 +14099,7 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
                     {
                         f1 = forceCastToFloat(d1);
                         f2 = forceCastToFloat(d2);
-                        d1 = f1 + f2;
+                        d1 = forceCastToFloat(f1 + f2);
                     }
                     else
                     {
@@ -14112,7 +14112,7 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
                     {
                         f1 = forceCastToFloat(d1);
                         f2 = forceCastToFloat(d2);
-                        d1 = f1 - f2;
+                        d1 = forceCastToFloat(f1 - f2);
                     }
                     else
                     {
@@ -14125,7 +14125,7 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
                     {
                         f1 = forceCastToFloat(d1);
                         f2 = forceCastToFloat(d2);
-                        d1 = f1 * f2;
+                        d1 = forceCastToFloat(f1 * f2);
                     }
                     else
                     {
@@ -14142,7 +14142,7 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
                     {
                         f1 = forceCastToFloat(d1);
                         f2 = forceCastToFloat(d2);
-                        d1 = f1 / f2;
+                        d1 = forceCastToFloat(f1 / f2);
                     }
                     else
                     {