This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Speed up nonzero_bits computation (was Re: [RFC] nonzero_bits)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Richard Henderson <rth at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 28 Mar 2002 23:39:26 +0100
- Subject: [PATCH] Speed up nonzero_bits computation (was Re: [RFC] nonzero_bits)
- References: <Pine.BSF.4.44.0203261704560.46283-100000@naos.dbai.tuwien.ac.at> <20020327205432.E32482@sunsite.ms.mff.cuni.cz> <20020327223810.G32482@sunsite.ms.mff.cuni.cz> <20020327141749.B17601@redhat.com> <20020327182905.H1213@devserv.devel.redhat.com> <20020327153752.A17778@redhat.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Wed, Mar 27, 2002 at 03:37:52PM -0800, Richard Henderson wrote:
> On Wed, Mar 27, 2002 at 06:29:05PM -0500, Jakub Jelinek wrote:
> > mode is surely fits in HOST_BITS_PER_WIDE_INT (early in nonzero_bits):
>
> Ah, right.
>
> > Replace the above line with
> > if (GET_MODE_CLASS (mode) == MODE_INT
> > && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
>
> Ok.
>
> > The thing I'm not sure about is if there is:
> > (subreg/u:QI (reg:SI ))
> > and nonzero_bits_mode is DI, whether this sais anything about the upper 32
> > bits (ie. if it shouldn't be &= 0xffffffff000000ff instead of 0xff above).
>
> You're not changing behaviour. MODE has always been the
> mode of the subreg, which is always been masking out the
> high bits, whether there were 32 or 64 of them.
Ok, here is the final patch, bootstrapped/regtested on i386-redhat-linux,
bootstrapped on sparcv9-sun-solaris2.8 (started using university
public lab for this), regtest there still ongoing.
Ok to commit if it succeeds (branch too)?
2002-03-28 Jakub Jelinek <jakub@redhat.com>
* combine.c (set_nonzero_bits_and_sign_copies): Don't call
nonzero_bits if not needed.
(nonzero_bits) [XOR]: Likewise.
(nonzero_bits) [REG]: Use reg_last_set_nonzero_bits even if
reg_last_set_mode and mode are both MODE_INT, but not equal.
(record_value_for_reg): Compute reg_last_set_nonzero_bits
in nonzero_bits_mode for MODE_INT modes.
--- gcc/combine.c.jj Tue Mar 26 17:54:46 2002
+++ gcc/combine.c Thu Mar 28 14:06:29 2002
@@ -904,8 +904,10 @@ set_nonzero_bits_and_sign_copies (x, set
<< GET_MODE_BITSIZE (GET_MODE (x))));
#endif
- reg_nonzero_bits[REGNO (x)]
- |= nonzero_bits (src, nonzero_bits_mode);
+ /* Don't call nonzero_bits if it cannot change anything. */
+ if (reg_nonzero_bits[REGNO (x)] != ~(unsigned HOST_WIDE_INT) 0)
+ reg_nonzero_bits[REGNO (x)]
+ |= nonzero_bits (src, nonzero_bits_mode);
num = num_sign_bit_copies (SET_SRC (set), GET_MODE (x));
if (reg_sign_bit_copies[REGNO (x)] == 0
|| reg_sign_bit_copies[REGNO (x)] > num)
@@ -8035,7 +8037,9 @@ nonzero_bits (x, mode)
for this register. */
if (reg_last_set_value[REGNO (x)] != 0
- && reg_last_set_mode[REGNO (x)] == mode
+ && (reg_last_set_mode[REGNO (x)] == mode
+ || (GET_MODE_CLASS (reg_last_set_mode[REGNO (x)]) == MODE_INT
+ && GET_MODE_CLASS (mode) == MODE_INT))
&& (reg_last_set_label[REGNO (x)] == label_tick
|| (REGNO (x) >= FIRST_PSEUDO_REGISTER
&& REG_N_SETS (REGNO (x)) == 1
@@ -8177,8 +8181,14 @@ nonzero_bits (x, mode)
case XOR: case IOR:
case UMIN: case UMAX: case SMIN: case SMAX:
- nonzero &= (nonzero_bits (XEXP (x, 0), mode)
- | nonzero_bits (XEXP (x, 1), mode));
+ {
+ unsigned HOST_WIDE_INT nonzero0 = nonzero_bits (XEXP (x, 0), mode);
+
+ /* Don't call nonzero_bits for the second time if it cannot change
+ anything. */
+ if ((nonzero & nonzero0) != nonzero)
+ nonzero &= (nonzero0 | nonzero_bits (XEXP (x, 1), mode));
+ }
break;
case PLUS: case MINUS:
@@ -11204,9 +11214,13 @@ record_value_for_reg (reg, insn, value)
if (value)
{
+ enum machine_mode mode = GET_MODE (reg);
subst_low_cuid = INSN_CUID (insn);
- reg_last_set_mode[regno] = GET_MODE (reg);
- reg_last_set_nonzero_bits[regno] = nonzero_bits (value, GET_MODE (reg));
+ reg_last_set_mode[regno] = mode;
+ if (GET_MODE_CLASS (mode) == MODE_INT
+ && GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT)
+ mode = nonzero_bits_mode;
+ reg_last_set_nonzero_bits[regno] = nonzero_bits (value, mode);
reg_last_set_sign_bit_copies[regno]
= num_sign_bit_copies (value, GET_MODE (reg));
}
Jakub