Global constant propagation
Jeffrey A Law
law@upchuck.cygnus.com
Fri Apr 30 23:15:00 GMT 1999
In message < 19990405203851.A5911@daimi.au.dk >you write:
> On Sun, Apr 04, 1999 at 05:47:47AM -0600, Jeffrey A Law wrote:
> >
> > In message < 19990404133100.A3351@daimi.au.dk >you write:
> > >
> > > Here is a small C fn:
> > >
> > > int testfn(int a, int b)
> > > {
> > > a = 1;
> > > if(b == 1)
> > > {
> > > b = 2;
> > > }
> > > else
> > > {
> > > b = 3;
> > > }
> > > return a*b;
> > > }
> >
> > If the if-then-else is confusing cprop, then that would be a bug.
>
> It turns out it isn't. The problem is that on MIPS the
> multiplication is inside a PARALLEL rtl (due to the clobbers
> of the HI and LO registers as far as I can see), which means
> the code in gcse.c can't recognise it and doesn't propagate
> the a=1 into it (see cprop_insn). Looks like this:
Quite possible. gcse doesn't try to do any simplifications. It merely
does a straightforward replacement, then tries to recognize the resulting
insn.
> (insn 34 51 36 (parallel[
> (set (reg:SI 85)
> (mult:SI (reg/v:SI 81)
> (reg/v:SI 82)))
> (clobber (scratch:SI))
> (clobber (scratch:SI))
> (clobber (scratch:SI))
> ] ) 57 {mulsi3_r4000} (nil)
> (nil))
>
> If the a=1 and the multiplication are in the same basic block
> then it is spotted by the code in cse, which understands
> parralels better
Local cse does a lot of simplifications on resulting rtx expressions. That
probably explains why it's the slowest part of the compiler :(
> (it seems to be doing a rather complete
> constant propagation of its own, though not much across basic
> blocks).
Correct. local cse has only minimal support for cse or cprop across
basic blocks.
> A solution might be to get gcse.c to recognise parallels that
> consist only of a 'set' and some clobbers and treat them like
> 'set's. I'm not really into this enough to do that...
Probably still not enough for the mips since I believe the mips requires
that the operands to the multiply to be in registers. ie, a constant
is not a valid operand to a multiply. So not only does it have to handle
parallels better, it has to perform simplifications, then recognize the
simplified result.
jeff
More information about the Gcc
mailing list