Skip to content

Commit

Permalink
fix bugzilla Issue 24819 - Optimizer changes result of float calculat…
Browse files Browse the repository at this point in the history
…ions on 32-bit
  • Loading branch information
WalterBright committed Oct 24, 2024
1 parent adb1c3f commit 06a4bff
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions compiler/src/dmd/backend/cgelem.d
Original file line number Diff line number Diff line change
Expand Up @@ -3906,6 +3906,10 @@ static if (0)
// If floating point, replace (x = -y) with (x = y ^ signbit)
if (op2 == OPneg && (tyreal(e2.Ety) || tyimaginary(e2.Ety)) &&
(e2.E1.Eoper == OPvar || e2.E1.Eoper == OPind) &&
/* Turned off for x87 because of https://issues.dlang.org/show_bug.cgi?id=24819
* and this is unnecessary anyway because of the FCHS x87 instruction
*/
!config.inline8087 &&

Check warning on line 3912 in compiler/src/dmd/backend/cgelem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/cgelem.d#L3912

Added line #L3912 was not covered by tests
/* Turned off for XMM registers because they don't play well with
* int registers.
*/
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/backend/debugprint.d
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ void numberBlocks(block *startblock)
@trusted
void WRfunc(const char* msg, Symbol* sfunc, block* startblock)
{
printf("............%s...%s().............\n", msg, sfunc.Sident.ptr);
printf("............%s...%s()\n", msg, sfunc.Sident.ptr);

Check warning on line 512 in compiler/src/dmd/backend/debugprint.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/debugprint.d#L512

Added line #L512 was not covered by tests
numberBlocks(startblock);
for (block *b = startblock; b; b = b.Bnext)
WRblock(b);
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/backend/dout.d
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ private void writefunc2(Symbol *sfunc, ref GlobalOptimizer go)
{
func_t *f = sfunc.Sfunc;

//printf("writefunc(%s)\n",sfunc.Sident.ptr);
debugb && printf("=========== writefunc %s ==================\n",sfunc.Sident.ptr);
//symbol_print(sfunc);
debug debugy && printf("writefunc(%s)\n",sfunc.Sident.ptr);

Expand Down
18 changes: 18 additions & 0 deletions compiler/test/runnable/test24819.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import core.stdc.stdio;

pragma(inline, true)
double sqrt(double x)
{
static import core.math;
return core.math.sqrt(x);
}

int main()
{
double q = -5.0;
double r = q + 1.0;
double result = sqrt(-r);
//printf("%f\n", result);
assert(result == 2);
return 0;
}

0 comments on commit 06a4bff

Please sign in to comment.