optimization/5264: Possible optimization bug at -O2 on HP-UX
luke@stat.umn.edu
luke@stat.umn.edu
Thu Jan 3 07:06:00 GMT 2002
>Number: 5264
>Category: optimization
>Synopsis: Possible optimization bug at -O2 on HP-UX
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Thu Jan 03 07:06:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Luke Tierney
>Release: gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
HP-UX bass B.11.00 A 9000/780 2007851940
>Description:
A possible optimization bug at -O2 on HP-UX found in building
R (Gnu S). Simplified program:
---------------(opttest.c)--------------------------------------------#include <stdio.h>
double x[] = { 1.0, 2.0}, y[] = { 1.0, 2.0 }, z[2];
main()
{
int i, i1, i2, n, n1, n2;
i1 = i2 = 0;
n = n1 = n2 = 2;
for (i = 0; i < n; i++) {
z[i] = x[i1] + y[i2];
i1 = (++i1 == n1) ? 0 : i1;
i2 = (++i2 == n2) ? 0 : i2;
}
printf("z[1] = %g\n", z[1]);
}
----------------------------------------------------------------------
Without optimization or with just -O it works fine:
tierney@bass [125]% gcc -o opttest opttest.c
ltierney@bass [126]% ./opttest
z[1] = 4ltierney@bass [127]% gcc -O -o opttest opttest.c
ltierney@bass [128]% ./opttest
z[1] = 4
But with -O2 it gets the wrong answer:
ltierney@bass [129]% gcc -O2 -o opttest opttest.c
ltierney@bass [130]% ./opttest
z[1] = 2
Please let me know if you need additional info.
>How-To-Repeat:
On HP-UX compare output of
gcc -O2 -o opttest opttest.c; ./opttest
gcc -O -o opttest opttest.c; ./opttest
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="opttest.c"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="opttest.c"
I2luY2x1ZGUgPHN0ZGlvLmg+Cgpkb3VibGUgeFtdID0geyAxLjAsIDIuMH0sIHlbXSA9IHsgMS4w
LCAyLjAgfSwgelsyXTsKCm1haW4oKQp7CiAgaW50IGksIGkxLCBpMiwgbiwgbjEsIG4yOwoKICBp
MSA9IGkyID0gMDsKICBuID0gbjEgPSBuMiA9IDI7CgogIGZvciAoaSA9IDA7IGkgPCBuOyBpKysp
IHsKICAgIHpbaV0gPSB4W2kxXSArIHlbaTJdOwogICAgaTEgPSAoKytpMSA9PSBuMSkgPyAwIDog
aTE7CiAgICBpMiA9ICgrK2kyID09IG4yKSA/IDAgOiBpMjsKICB9CiAgcHJpbnRmKCJ6WzFdID0g
JWdcbiIsIHpbMV0pOwp9Cg==
More information about the Gcc-bugs
mailing list