Strange regression in egcs-current/x86
Jeffrey A Law
law@upchuck.cygnus.com
Mon Mar 29 08:19:00 GMT 1999
In message <19980704150630.38682@kali.lrz-muenchen.de>you write:
> Hello,
>
> There is something strange in the x86 code generated by egcs-current.
I don't think so.
> f(int i)
> {
> float b[i + 1];
>
> for (int c = 0; c <= i; c++) {
> b[c] = sin(c - 1); /* nonsense */
> }
> }
> movl 8(%ebp),%ecx
> leal 1(%ecx),%eax <-------
> sall $5,%eax <------- shift to the left
> shrl $3,%eax <------- shift back
> subl %eax,%esp
> [...]
>
> g++ 2.7.2 did it with:
>
> [..]
> movl %esp,-8(%ebp)
> leal 4(,%esi,4),%eax
> subl %eax,%esp
>
> I know that often more primitive operations are faster on later x86 CPUs,
> but I doubt that first shifting to the left, and the backshifting to the
> right is the fastest way to do it. It seems some patterns got lost or the
> combiner has some problems.
Combining shifts like that is not safe.
Consider the value 0x20000000
If you shift it left 5 times, then shift it right 3 times you get the value
zero.
If you combine the shifts and just shift it left 2 times you get 0x80000000.
jeff
More information about the Gcc-bugs
mailing list