Skip to content

Commit

Permalink
JIT: ensure float folding is done using float precision (dotnet/corec…
Browse files Browse the repository at this point in the history
…lr#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 dotnet/coreclr@1370fb9
  • Loading branch information
AndyAyersMS authored Oct 25, 2018
1 parent 3f4cf37 commit 98b4507
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/coreclr/src/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14099,7 +14099,7 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
{
f1 = forceCastToFloat(d1);
f2 = forceCastToFloat(d2);
d1 = f1 + f2;
d1 = forceCastToFloat(f1 + f2);
}
else
{
Expand All @@ -14112,7 +14112,7 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
{
f1 = forceCastToFloat(d1);
f2 = forceCastToFloat(d2);
d1 = f1 - f2;
d1 = forceCastToFloat(f1 - f2);
}
else
{
Expand All @@ -14125,7 +14125,7 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
{
f1 = forceCastToFloat(d1);
f2 = forceCastToFloat(d2);
d1 = f1 * f2;
d1 = forceCastToFloat(f1 * f2);
}
else
{
Expand All @@ -14142,7 +14142,7 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
{
f1 = forceCastToFloat(d1);
f2 = forceCastToFloat(d2);
d1 = f1 / f2;
d1 = forceCastToFloat(f1 / f2);
}
else
{
Expand Down

0 comments on commit 98b4507

Please sign in to comment.