This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/16052] New: strength reduction produces wrong code
- From: "yamt at mwd dot biglobe dot ne dot jp" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 18 Jun 2004 10:28:29 -0000
- Subject: [Bug c/16052] New: strength reduction produces wrong code
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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"
--
Summary: strength reduction produces wrong code
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: yamt at mwd dot biglobe dot ne dot jp
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i386-unknown-netbsdelf2.0F
GCC host triplet: i386-unknown-netbsdelf2.0F
GCC target triplet: i386-unknown-netbsdelf2.0F
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16052