This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

int div by constant optimization

gcc optimizes this nicely, substituting a sequence of cheap
instructions for the divide:
But this is done during the tree->rtl conversion, so other
opportunities that arise after constant propagation are
missed.  gcc doesn't get either of these:
    int x=7;
    for (;;) {
I'd like to fix this.  Conceptually what you
need to do isn't hard:  call expand_divmod() after const
propagation.  I'm not sure where, though.  It needs to be
after (or during) gcse, and before (or during) loop_optimize;
that's a narrow window.  I've put some code in
gcse.c:cprop_insn() to do this.  It seems rather unaesthetic,
though, looking for a specific pattern in code that's intended
to be general.

(It's a little trickier, actually, since
y/7 is not a valid instruction on the target I'm interested
in [ppc].  gcse adds a REG_EQUAL note when it sees that a
const could be propagated, but the resulting insn is not
valid; the code I mentioned above looks for that note, in
addition to looking for a (div by const) instruction.  That
catches the second example above, inside the loop, which
is most interesting from an efficiency perspective.  It
doesn't catch the first example, because cse adds no such
note.  It could; can somebody advise me where?)

I'll submit my change in a day or two, if it passes testing
and nobody has a better way to do it.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]