siro% /usr/local/gcc3/bin/gcc -v Reading specs from /usr/local/gcc3/lib/gcc/i386-unknown-netbsdelf2.0F/3.4.0/specs Configured with: ./configure --prefix=/usr/local/gcc3_4 : (reconfigured) ./configure --prefix=/usr/local/gcc3 --enable-languages=c Thread model: posix gcc version 3.4.0 "gcc -O2 -S a.c" produces wrong code. note that the produced code uses "jle" insn for loop condition. because what it attempts to check is "p < (original value of p)+N*M", it should use an unsigned comparison. == a.c (source code) ================================================== #include <stdio.h> typedef int a_t; inline void h1(const a_t *p) { printf("%p\n", p); } #define N 800 #define M 4 void h(const a_t *p) { int j; for (j = 0; j < N; j++) { h1(p + j*M); } } #if 1 #ifdef _LP64 #define PTRBIT 64 #else #define PTRBIT 32 #endif int main(int argc, char **argv) { h((void *) ((1ULL << (PTRBIT - 1)) - sizeof(a_t) * N * M)); } #endif == a.s (produced code) ================================================== .file "a.c" .section .rodata.str1.1,"aMS",@progbits,1 .LC0: .string "%p\n" .text .p2align 2,,3 .globl h1 .type h1, @function h1: pushl %ebp movl %esp, %ebp subl $16, %esp pushl 8(%ebp) pushl $.LC0 call printf leave ret .size h1, .-h1 .p2align 2,,3 .globl h .type h, @function h: pushl %ebp movl %esp, %ebp pushl %esi pushl %ebx movl 8(%ebp), %ebx leal 12784(%ebx), %esi .p2align 2,,3 .L7: subl $8, %esp pushl %ebx pushl $.LC0 addl $16, %ebx call printf addl $16, %esp cmpl %esi, %ebx jle .L7 leal -8(%ebp), %esp popl %ebx popl %esi leave ret .size h, .-h .p2align 2,,3 .globl main .type main, @function main: pushl %ebp movl %esp, %ebp subl $8, %esp andl $-16, %esp subl $28, %esp pushl $2147470848 call h leave ret .size main, .-main .ident "GCC: (GNU) 3.4.0"
Confirmed, -O2 -march=i386 is needed to reproduce it on i686-pc-linux-gnu (well any i?86 really)
*** Bug 16066 has been marked as a duplicate of this bug. ***
Hmm, I did not test 3.3.4 at all, so this might be just a regression I do not know, but the debian folks think it is.
Postponed until GCC 3.4.3.
Postponed until GCC 3.4.4.
Fails on all ix86
> Fails on all ix86 Yeah, this is the classical problem with biv elimination to pointer givs. See gcc.c-torture/execute/loop-2e.c, which is XFAILed on x86. Not a regression.
Fixed for 4.0.0.
*** Bug 21862 has been marked as a duplicate of this bug. ***