From 1370fb92bc9c1ae9475e92f8638c827128c84527 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 (#20578) Cast float folded values back to float before assigning to the double the jit uses for storing FP literal constants. Fixes #20561. No diffs on Core; exposing the original bug requires building RyuJit with an older x86 C++ compiler that uses x87 floating point. --- src/jit/gentree.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/jit/gentree.cpp b/src/jit/gentree.cpp index 37feba6..5c785da 100644 --- a/src/jit/gentree.cpp +++ b/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 { -- 2.7.4