public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Signed divide by 2 pessimization
@ 2000-09-09 12:41 Marek Michalkiewicz
  2000-09-09 13:26 ` Geoff Keating
  0 siblings, 1 reply; 7+ messages in thread
From: Marek Michalkiewicz @ 2000-09-09 12:41 UTC (permalink / raw)
  To: gcc; +Cc: denisc, marekm

Hello,

a few months ago I reported a problem with inefficient code
generated for signed divide by 2 on the AVR target (possibly
some other small targets as well).  The problem is still there,
in expmed.c (expand_divmod), line 3240 in today's CVS:

		    if (abs_d != 2 && BRANCH_COST < 3)

This test decides which one of the two possible algorithms
should be used for signed divide by a +/- power of 2.
On the AVR, branches are cheaper than shifts (especially
by many bits), so making the test always true makes MUCH
better code for this case.  But there is currently no way
to make that test true also for divide by 2 and -2.

I submitted a small patch for expmed.c that adds a new
macro to give the target some control over this test, but
it was rejected.  While I agree that ideally, rtx costs
should be used instead of adding new macros, that hasn't
happened, and doing it would require a lot of testing on
many different machines to make sure it doesn't make things
worse.  (I tried once, and it made x86 code slower, because
its BRANCH_COST seems to be defined lower than it usually is.
I can't tell what happens on other machines.)

I have a workaround for the AVR port, but you don't want
to see it :-) (not yet in CVS, I still hope it will not be
necessary).  What it does is to handle division with a
define_expand, generate rtl for divide by +/- power of 2
(as if the test in expmed.c was always true) ourselves,
and FAIL in other cases.  Yet it only works for divide
by 2, and divide by -2 is still done the inefficient way
(doesn't happen that often though).  So it's a lot of
work in one place (avr.c, avr.md) to avoid a 2-line change
in another place (expmed.c).

After a few months, the ideal solution (using rtx costs)
hasn't come yet.  So, PLEASE consider adding a new macro
in the meantime (I can re-submit the patch, first sent
on 12 May).  I know it is not elegant, but it works for
targets that need it, and doesn't change anything for
other targets.  Please...

Thanks,
Marek

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2000-09-16 12:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-09 12:41 Signed divide by 2 pessimization Marek Michalkiewicz
2000-09-09 13:26 ` Geoff Keating
2000-09-10  4:22   ` Marek Michalkiewicz
2000-09-10  6:17     ` Geoff Keating
2000-09-10  9:44       ` Marek Michalkiewicz
2000-09-10 14:41         ` Geoff Keating
2000-09-16 12:53           ` Marek Michalkiewicz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).