This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: optimizing % CONST_INT
Richard Henderson <rth@redhat.com> writes:
> On Wed, Apr 17, 2002 at 04:54:12PM -0700, Dan Nicolaescu wrote:
> > the code could be branchless...
> >
> > Any idea how to fix it?
>
> Use -mcpu=v9?
>
> cmp %o0, -1
> add %o0, 15, %g2
> movg %icc, %o0, %g2
> and %g2, -16, %g2
> sub %o0, %g2, %o0
>
> Seriously, what did you have in mind?
I wasn't thinking conditional moves, but different code.
look at what the SUN compiler generates:
/* 000000 9 */ sra %o0,31,%o1
/* 0x0004 */ and %o1,15,%o1
/* 0x0008 */ add %o0,%o1,%o1
/* 0x000c */ andn %o1,15,%o1
/* 0x0010 */ retl ! Result = %o0
/* 0x0014 */ sub %o0,%o1,%o0
> There is a bunch of code in ifcvt.c that tries to use some arithmetic
> to avoid branches. Either sparcv7 doesn't define the right patterns,
> or we're missing some tricks, or sparcv7 sets the cost of a branch so
> low that we don't think the transformation is helpful.
Maybe fold should take care of this? (I don't know).
It also happens on i386 (though I tried with a 4-5 month old gcc)