This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 2/4, middle-end] Factor out low_bitmask_len from try_widen_shift_mode
- From: Adam Nemet <anemet at caviumnetworks dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 30 Jul 2009 12:34:22 -0700
- Subject: [PATCH 2/4, middle-end] Factor out low_bitmask_len from try_widen_shift_mode
- References: <19057.62127.907350.916479@ropi.home>
This patch should have no effect on the generated code. It simply factors out
a helper, low_bitmask_len, to be used from the MIPS backend in the final patch
of the series.
Bootstrapped and regtested on {mips64octeon,x86_64}-linux. Also regtested on
mipsisa64r2-elf.
OK to install?
Adam
* combine.c (try_widen_shift_mode): Factor out code to check if an
interger constant is a low-order bitmask from here ...
* rtlanal.c (low_bitmask_len): ... to here.
* rtl.h (low_bitmask_len): Declare.
Index: gcc/rtl.h
===================================================================
--- gcc.orig/rtl.h 2009-07-28 12:19:56.000000000 -0700
+++ gcc/rtl.h 2009-07-28 13:41:46.000000000 -0700
@@ -1095,6 +1095,7 @@ extern unsigned HOST_WIDE_INT nonzero_bi
extern unsigned int num_sign_bit_copies (const_rtx, enum machine_mode);
extern bool constant_pool_constant_p (rtx);
extern bool truncated_to_mode (enum machine_mode, const_rtx);
+extern int low_bitmask_len (enum machine_mode, unsigned HOST_WIDE_INT);
/* 1 if RTX is a subreg containing a reg that is already known to be
Index: gcc/combine.c
===================================================================
--- gcc.orig/combine.c 2009-07-28 12:19:56.000000000 -0700
+++ gcc/combine.c 2009-07-28 12:20:45.000000000 -0700
@@ -9024,13 +9024,9 @@ try_widen_shift_mode (enum rtx_code code
/* We can also widen if the bits brought in will be masked off. This
operation is performed in ORIG_MODE. */
- if (outer_code == AND
- && GET_MODE_BITSIZE (orig_mode) <= HOST_BITS_PER_WIDE_INT)
+ if (outer_code == AND)
{
- int care_bits;
-
- outer_const &= GET_MODE_MASK (orig_mode);
- care_bits = exact_log2 (outer_const + 1);
+ int care_bits = low_bitmask_len (orig_mode, outer_const);
if (care_bits >= 0
&& GET_MODE_BITSIZE (orig_mode) - care_bits >= count)
Index: gcc/rtlanal.c
===================================================================
--- gcc.orig/rtlanal.c 2009-07-28 12:19:56.000000000 -0700
+++ gcc/rtlanal.c 2009-07-28 13:50:34.000000000 -0700
@@ -5032,3 +5032,18 @@ constant_pool_constant_p (rtx x)
x = avoid_constant_pool_reference (x);
return GET_CODE (x) == CONST_DOUBLE;
}
+
+/* If M is a bitmask that selects a field of low-order bits within an item but
+ not the entire word, return the length of the field. Return -1 otherwise.
+ M is used in machine mode MODE. MODE can be VOIDmode if it's unknown. */
+
+int
+low_bitmask_len (enum machine_mode mode, unsigned HOST_WIDE_INT m)
+{
+ if (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT)
+ return -1;
+ if (mode != VOIDmode)
+ m &= GET_MODE_MASK (mode);
+
+ return exact_log2 (m + 1);
+}