Bug 87128 - Wrong Value Generated for m32 without optimization
Summary: Wrong Value Generated for m32 without optimization
Status: RESOLVED DUPLICATE of bug 323
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2018-08-28 11:54 UTC by Neha Gowda
Modified: 2018-08-28 14:23 UTC (History)
1 user (show)

See Also:
Target: x86
Known to work:
Known to fail:
Last reconfirmed:

Testcase to generate the issue (134 bytes, text/plain)
2018-08-28 11:54 UTC, Neha Gowda

Note You need to log in before you can comment on or make changes to this bug.
Description Neha Gowda 2018-08-28 11:54:58 UTC
Created attachment 44615 [details]
Testcase to generate the issue

When the attached file is compiled for -m32 without any optimization,
it generates wrong result.
$gcc test.c -m32
$ ./a.out
result = -8388608.000000    -> Wrong result

$gcc test.c -m32 -O1
$ ./a.out
result = 0.000000           -> Correct result

Additional Info

Checked with many native GCC from GCC-4.1.0 to current upstream sources.

The result in only wrong when the values of exponents add to zero.
And the value of a is equal or greater than 1.0e23
Example1 a = 1.0e23 b = 1.0e15 c = 1.0e8
Example2 a = 1.0e28 b = 1.0e15 c = 1.0e13

The issue is not observed in the following scenarios
1. Any optimization is enabled.
2. m64 
3. Precision value set to mpc64

Are the values greater than 1.0e23 not handled by 32 properly?
Is anything obvious being missed in the testcase?
Comment 1 Jonathan Wakely 2018-08-28 12:36:38 UTC
1e23 is outside the range where all integers can be represented exactly by a 64-bit IEEE double, and the calculation is imprecise when using i387 floating point registers.

The expected answer is given when using:


or when using:

    -msse -mfpmath=sse -fexcess-precision=standard
Comment 2 Richard Biener 2018-08-28 13:46:06 UTC
Dup of 323 then?
Comment 3 Jakub Jelinek 2018-08-28 13:54:26 UTC

*** This bug has been marked as a duplicate of bug 323 ***
Comment 4 Neha Gowda 2018-08-28 14:23:20 UTC
Thanks for the explanation.