This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GCC optimizes integer overflow: bug or feature?
- From: Denis Vlasenko <vda dot linux at googlemail dot com>
- To: Paul Brook <paul at codesourcery dot com>
- Cc: gcc at gcc dot gnu dot org, Andrew Haley <aph at redhat dot com>, Paolo Bonzini <bonzini at gnu dot org>, bug-gnulib at gnu dot org
- Date: Fri, 22 Dec 2006 01:58:39 +0100
- Subject: Re: GCC optimizes integer overflow: bug or feature?
- References: <20061218230847.GD3824@iam.uni-bonn.de> <200612192146.39773.paul@codesourcery.com> <200612192339.50256.vda.linux@googlemail.com>
On Tuesday 19 December 2006 23:39, Denis Vlasenko wrote:
> There are a lot of 100.00% safe optimizations which gcc
> can do. Value range propagation for bitwise operations, for one
Or this, absolutely typical C code. i386 arch can compare
16 bits at a time here (luckily, no alighment worries on this arch):
# cat tt.c
int f(char *p)
{
if (p[0] == 1 && p[1] == 2) return 1;
return 0;
}
# gcc -O2 -S -fomit-frame-pointer tt.c
# cat tt.s
.file "tt.c"
.text
.p2align 2,,3
.globl f
.type f, @function
f:
movl 4(%esp), %eax
cmpb $1, (%eax)
je .L2
xorl %eax, %eax
ret
.p2align 2,,3
.L2:
cmpb $2, 1(%eax)
sete %al
movzbl %al, %eax
ret
.size f, .-f
.ident "GCC: (GNU) 4.2.0 20061128 (prerelease)"
.section .note.GNU-stack,"",@progbits