public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-5614] Improve double-word mod even on powerpc [PR97459]
@ 2020-12-01 15:25 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-12-01 15:25 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:855bb43f6d0bee5a74b5d3739456ca34b4609a50

commit r11-5614-g855bb43f6d0bee5a74b5d3739456ca34b4609a50
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Dec 1 16:25:06 2020 +0100

    Improve double-word mod even on powerpc [PR97459]
    
    I have noticed that while my (already committed, thanks for review)
    patch works on x86, it doesn't work on powerpc*.  The problem is that
    we don't have lshr double-word optab (neither TImode nor for -m32 DImode),
    but as expander has code for double-word shift, that doesn't really matter.
    As the implementation is prepared to punt whenever something can't be
    expanded with OPTAB_DIRECT and in the end also punts if any library calls
    would be emitted, the optab_handler checks were just to save compile time.
    
    On the other side, for even divisors, we know that (1 << bit) % (2 * x)
    for bit > 0 will never be equal to 1, because both dividend and divisor
    are even and so remainder will be even too, so we can save some compile time
    by adding an early exit.
    
    The even divisors can be handled with the approach Thomas wrote about
    (perhaps generalized into divisors equal to what expand_doubleword_mod
    can handle times some power of two where we can handle power of two modulo
    cheaply), but that would be done in a different function...
    And we could use ctz to find the power of two...
    
    2020-12-01  Jakub Jelinek  <jakub@redhat.com>
    
            PR rtl-optimization/97459
            * optabs.c (expand_doubleword_mod): Punt early for even op1.
            (expand_binop): Don't require lshr_optab double-word handler.

Diff:
---
 gcc/optabs.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gcc/optabs.c b/gcc/optabs.c
index 8d89f08d2bd..3b116d39fb7 100644
--- a/gcc/optabs.c
+++ b/gcc/optabs.c
@@ -949,7 +949,7 @@ expand_doubleword_mult (machine_mode mode, rtx op0, rtx op1, rtx target,
 static rtx
 expand_doubleword_mod (machine_mode mode, rtx op0, rtx op1, bool unsignedp)
 {
-  if (INTVAL (op1) <= 1)
+  if (INTVAL (op1) <= 1 || (INTVAL (op1) & 1) == 0)
     return NULL_RTX;
 
   rtx_insn *last = get_last_insn ();
@@ -2004,7 +2004,6 @@ expand_binop (machine_mode mode, optab binoptab, rtx op0, rtx op1,
       && CONST_INT_P (op1)
       && is_int_mode (mode, &int_mode)
       && GET_MODE_SIZE (int_mode) == 2 * UNITS_PER_WORD
-      && optab_handler (lshr_optab, int_mode) != CODE_FOR_nothing
       && optab_handler (and_optab, word_mode) != CODE_FOR_nothing
       && optab_handler (add_optab, word_mode) != CODE_FOR_nothing
       && optimize_insn_for_speed_p ())


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-01 15:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-01 15:25 [gcc r11-5614] Improve double-word mod even on powerpc [PR97459] Jakub Jelinek

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).