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: unassig...@gcc.gnu.org ReportedBy: argond...@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!)