public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/47670] New: Gcc 4.5.1 inconsistent optimisation of loop with mixed 32bit and 64bit arithmetic
@ 2011-02-09 20:56 argondsgn at gmail dot com
2011-02-09 21:14 ` [Bug c/47670] " rguenth at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: argondsgn at gmail dot com @ 2011-02-09 20:56 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47670
Summary: Gcc 4.5.1 inconsistent optimisation of loop with mixed
32bit and 64bit arithmetic
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: argondsgn@gmail.com
Created attachment 23290
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23290
Output of gcc -v save-temps -O2 bug.c
int main(int argc, char *argv[])
{
int i;
long long count=0;
int ret;
for (i=0;i<9;i++)
{
count+=i*0x40000000;
}
ret=count>>32;
return ret;
}
produces different answers when compiled with
gcc -O1 bug.c (returns -1)
or
gcc -O2 bug.c (returns 9)
Judging from the assembler output with -S, this loop is optimised to a
different constant expression in the two cases.
It works with gcc 3.4.4, but not with gcc 4.5.1 (I haven't tested any other
versions yet)
(First time I've attempted to submit a bug report to an open source project, so
many apologies if this is already fixed, an issue with my understanding of C,
or in the wrong category!)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/47670] Gcc 4.5.1 inconsistent optimisation of loop with mixed 32bit and 64bit arithmetic
2011-02-09 20:56 [Bug c/47670] New: Gcc 4.5.1 inconsistent optimisation of loop with mixed 32bit and 64bit arithmetic argondsgn at gmail dot com
@ 2011-02-09 21:14 ` rguenth at gcc dot gnu.org
2011-02-09 21:20 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-02-09 21:14 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47670
--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-02-09 21:13:46 UTC ---
Singed overflow invokes undefined behavior, use
count += ((long long)i) * 0x40000000
instead.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/47670] Gcc 4.5.1 inconsistent optimisation of loop with mixed 32bit and 64bit arithmetic
2011-02-09 20:56 [Bug c/47670] New: Gcc 4.5.1 inconsistent optimisation of loop with mixed 32bit and 64bit arithmetic argondsgn at gmail dot com
2011-02-09 21:14 ` [Bug c/47670] " rguenth at gcc dot gnu.org
@ 2011-02-09 21:20 ` rguenth at gcc dot gnu.org
2011-02-09 21:54 ` jakub at gcc dot gnu.org
2011-02-09 22:00 ` argondsgn at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-02-09 21:20 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47670
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-02-09 21:14:01 UTC ---
.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/47670] Gcc 4.5.1 inconsistent optimisation of loop with mixed 32bit and 64bit arithmetic
2011-02-09 20:56 [Bug c/47670] New: Gcc 4.5.1 inconsistent optimisation of loop with mixed 32bit and 64bit arithmetic argondsgn at gmail dot com
2011-02-09 21:14 ` [Bug c/47670] " rguenth at gcc dot gnu.org
2011-02-09 21:20 ` rguenth at gcc dot gnu.org
@ 2011-02-09 21:54 ` jakub at gcc dot gnu.org
2011-02-09 22:00 ` argondsgn at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-02-09 21:54 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47670
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-02-09 21:20:51 UTC ---
Or count+=i*0x40000000LL;
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/47670] Gcc 4.5.1 inconsistent optimisation of loop with mixed 32bit and 64bit arithmetic
2011-02-09 20:56 [Bug c/47670] New: Gcc 4.5.1 inconsistent optimisation of loop with mixed 32bit and 64bit arithmetic argondsgn at gmail dot com
` (2 preceding siblings ...)
2011-02-09 21:54 ` jakub at gcc dot gnu.org
@ 2011-02-09 22:00 ` argondsgn at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: argondsgn at gmail dot com @ 2011-02-09 22:00 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47670
Peter de Rivaz <argondsgn at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |CLOSED
--- Comment #4 from Peter de Rivaz <argondsgn at gmail dot com> 2011-02-09 21:54:15 UTC ---
Thanks! (And sorry for the invalid report).
C99 specification 6.5 para 5 agrees that this is undefined behaviour.
Both suggestions solve the problem.
I've closed the bug now.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-02-09 21:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-09 20:56 [Bug c/47670] New: Gcc 4.5.1 inconsistent optimisation of loop with mixed 32bit and 64bit arithmetic argondsgn at gmail dot com
2011-02-09 21:14 ` [Bug c/47670] " rguenth at gcc dot gnu.org
2011-02-09 21:20 ` rguenth at gcc dot gnu.org
2011-02-09 21:54 ` jakub at gcc dot gnu.org
2011-02-09 22:00 ` argondsgn at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).