--- Comment #7 from rguenth at gcc dot gnu dot org 2006-10-11 12:23 ---
We're not folding
return (int) *((char *) (long unsigned int) i + a + 1B) + (int) *((char *)
(long unsigned int) i + b + 1B);
one reason is that the C frontend decomposes a[i], one is the array-to-pointer
decay
--- Comment #8 from rguenth at gcc dot gnu dot org 2006-10-11 12:30 ---
One minimal fix for this is the following (patches for this I sent many times
long time ago, but poking in the C frontend is tedious):
Index: c-typeck.c
--- Comment #9 from bonzini at gnu dot org 2006-10-11 12:47 ---
For this, on i386-pc-linux-gnu, C and C++ give the exact (pessimized) same
code:
char a[10], b[10];
int f1(int i)
{
return a[i+1] + b[i+1];
}
That RTL address selection sucks is just a fact. :-)
--
--- Comment #10 from rguenth at gcc dot gnu dot org 2006-10-11 12:53
---
I get (-O -m32) for C++:
_Z2f1i:
.LFB2:
pushl %ebp
.LCFI0:
movl%esp, %ebp
.LCFI1:
movl8(%ebp), %edx
addl$1, %edx
movsbl b(%edx),%eax
movsbl
--- Comment #11 from paolo dot bonzini at lu dot unisi dot ch 2006-10-11
13:05 ---
Subject: Re: [4.0/4.1/4.2 Regression] address selection does
not work correctly
movl8(%ebp), %edx
addl$1, %edx
movsbl b(%edx),%eax
movsbl a(%edx),%edx