This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
optimization/4251: Bug in optimization of floating-point code
- To: gcc-gnats at gcc dot gnu dot org
- Subject: optimization/4251: Bug in optimization of floating-point code
- From: Bart dot VanAssche at yucom dot be
- Date: 6 Sep 2001 17:31:09 -0000
- Reply-To: Bart dot VanAssche at yucom dot be
>Number: 4251
>Category: optimization
>Synopsis: Bug in optimization of floating-point code
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Thu Sep 06 10:36:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Bart Van Assche
>Release: both 2.95.3 and 3.0
>Organization:
>Environment:
RedHat Linux 6.1 with 2.4.7 kernel
>Description:
When compiling the attached program with -O0, the program
exits with exit code 0 (echo $?) -- this is OK. When
compiling the attached program with -O2 however, then it
exits with exit code 1 -- this is wrong. I'm not sure
whether this really is a bug in the optimizer or the result
of rounding effects, but it is really something strange.
BTW, when replacing "<" by ">", the problem disappears.
It also looks like the problem only occurs when "step" has
a lot of bits behind the binary point (e.g. 0.1, 0.2 or
0.3, but not 0.5 or 0.25).
>How-To-Repeat:
g++ -O0 -Wall NormalizeFloat.cpp && (./a.out;echo $?)
g++ -O2 -Wall NormalizeFloat.cpp && (./a.out;echo $?)
will give you the output 0 and 1 on separate lines.
>Fix:
Either turn optimization off or put one of the calls to
Normalize() in a separate statement.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="NormalizeFloat.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="NormalizeFloat.cpp"
Ly8gRGVtb25zdHJhdGlvbiBwcm9ncmFtIG9mIGEgYnVnIGluIGcrKycgb3B0aW1pemVyIC0tIEJW
QVMsIDA1LXNlcHQtMjAwMS4KLy8gV2hlbiBjb21waWxpbmcgd2l0aCAtV2FsbCAtTzA6IGV4aXQg
Y29kZSBpcyAwIChPSykuCi8vIFdoZW4gY29tcGlsaW5nIHdpdGggLVdhbGwgLU8yOiBleGl0IGNv
ZGUgaXMgMSAoV1JPTkcpLgoKIyBkZWZpbmUgX19NQVRIX0lOTElORSBfX2lubGluZQojZGVmaW5l
IF9fQ09OQ0FUKGEsYikgYSMjYgojZGVmaW5lIF9faW5saW5lX21hdGhjb2RlXyhmbG9hdF90eXBl
LCBmdW5jLCBhcmcsIGNvZGUpIFwKICBfX01BVEhfSU5MSU5FIGZsb2F0X3R5cGUgZnVuYyAoZmxv
YXRfdHlwZSk7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogIF9fTUFUSF9JTkxJ
TkUgZmxvYXRfdHlwZSBmdW5jIChmbG9hdF90eXBlIGFyZykgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICBcCiAgeyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICAgIGNvZGU7ICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAog
IH0KIyBkZWZpbmUgX19pbmxpbmVfbWF0aGNvZGUoZnVuYywgYXJnLCBjb2RlKSBcCiAgX19pbmxp
bmVfbWF0aGNvZGVfIChkb3VibGUsIGZ1bmMsIGFyZywgY29kZSkgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgIFwKICBfX2lubGluZV9tYXRoY29kZV8gKGZsb2F0LCBfX0NPTkNBVChmdW5j
LGYpLCBhcmcsIGNvZGUpICAgICAgICAgICAgICAgICAgICAgXAogIF9faW5saW5lX21hdGhjb2Rl
XyAobG9uZyBkb3VibGUsIF9fQ09OQ0FUKGZ1bmMsbCksIGFyZywgY29kZSkKCl9faW5saW5lX21h
dGhjb2RlIChmbG9vciwgX194LCBcCiAgcmVnaXN0ZXIgbG9uZyBkb3VibGUgX192YWx1ZTsgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwKICBfX3ZvbGF0aWxl
IHVuc2lnbmVkIHNob3J0IGludCBfX2N3OyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgXAogIF9fdm9sYXRpbGUgdW5zaWduZWQgc2hvcnQgaW50IF9fY3d0bXA7ICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgX19hc20gX192b2xhdGlsZSAoImZu
c3RjdyAlMCIgOiAiPW0iIChfX2N3KSk7ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFwK
ICBfX2N3dG1wID0gKF9fY3cgJiAweGYzZmYpIHwgMHgwNDAwOyAvKiByb3VuZGluZyBkb3duICov
ICAgICAgICAgICAgICAgICAgICAgXAogIF9fYXNtIF9fdm9sYXRpbGUgKCJmbGRjdyAlMCIgOiA6
ICJtIiAoX19jd3RtcCkpOyAgICAgICAgICAgICAgICAgICAgICAgICAgICBcCiAgX19hc20gX192
b2xhdGlsZSAoImZybmRpbnQiIDogIj10IiAoX192YWx1ZSkgOiAiMCIgKF9feCkpOyAgICAgICAg
ICAgICAgICAgIFwKICBfX2FzbSBfX3ZvbGF0aWxlICgiZmxkY3cgJTAiIDogOiAibSIgKF9fY3cp
KTsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAogIHJldHVybiBfX3ZhbHVlKQoKZmxv
YXQgTm9ybWFsaXplRmxvYXQoZmxvYXQgTm1iciwgZmxvYXQgU3RlcCkKewogIE5tYnIgPSBObWJy
IC8gU3RlcDsKICBObWJyID0gTm1iciArIDAuNWY7CiAgTm1iciA9IGZsb29yKE5tYnIpOwogIE5t
YnIgPSBObWJyICogU3RlcDsKICByZXR1cm4gTm1icjsKfQoKaW50IG1haW4oaW50IGFyZ2MsIGNo
YXIqKiBhcmd2KQp7CiAgcmV0dXJuIChOb3JtYWxpemVGbG9hdCgxLCAwLjEpIDwgTm9ybWFsaXpl
RmxvYXQoMSwgMC4xKSk7Cn0K