From 855bb43f6d0bee5a74b5d3739456ca34b4609a50 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 1 Dec 2020 16:25:06 +0100 Subject: [PATCH] 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 PR rtl-optimization/97459 * optabs.c (expand_doubleword_mod): Punt early for even op1. (expand_binop): Don't require lshr_optab double-word handler. --- gcc/optabs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gcc/optabs.c b/gcc/optabs.c index 8d89f08..3b116d3 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 ()) -- 2.7.4