From 98b450798c99c1c0a3f3d0394259693609c2cbe4 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Thu, 25 Oct 2018 08:17:49 -0700 Subject: [PATCH] JIT: ensure float folding is done using float precision (dotnet/coreclr#20578) 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coreclr/src/jit/gentree.cpp b/src/coreclr/src/jit/gentree.cpp index 37feba6fcb0bea..5c785da3c7a87c 100644 --- a/src/coreclr/src/jit/gentree.cpp +++ b/src/coreclr/src/jit/gentree.cpp @@ -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 {