Re: [104/nnn] poly_int: GET_MODE_PRECISION

2017-11-27 Thread Jeff Law
On 10/23/2017 11:42 AM, Richard Sandiford wrote:
> This patch changes GET_MODE_PRECISION from an unsigned short
> to a poly_uint16.
> 
> 
> 2017-10-23  Richard Sandiford  
>   Alan Hayward  
>   David Sherwood  
> 
> gcc/
>   * machmode.h (mode_precision): Change from unsigned short to
>   poly_uint16_pod.
>   (mode_to_precision): Return a poly_uint16 rather than an unsigned
>   short.
>   (GET_MODE_PRECISION): Return a constant if ONLY_FIXED_SIZE_MODES,
>   or if measurement_type is not polynomial.
>   (HWI_COMPUTABLE_MODE_P): Turn into a function.  Optimize the case
>   in which the mode is already known to be a scalar_int_mode.
>   * genmodes.c (emit_mode_precision): Change the type of mode_precision
>   from unsigned short to poly_uint16_pod.  Use ZERO_COEFFS for the
>   initializer.
>   * lto-streamer-in.c (lto_input_mode_table): Use bp_unpack_poly_value
>   for GET_MODE_PRECISION.
>   * lto-streamer-out.c (lto_write_mode_table): Use bp_pack_poly_value
>   for GET_MODE_PRECISION.
>   * combine.c (update_rsp_from_reg_equal): Treat GET_MODE_PRECISION
>   as polynomial.
>   (try_combine, find_split_point, combine_simplify_rtx): Likewise.
>   (expand_field_assignment, make_extraction): Likewise.
>   (make_compound_operation_int, record_dead_and_set_regs_1): Likewise.
>   (get_last_value): Likewise.
>   * convert.c (convert_to_integer_1): Likewise.
>   * cse.c (cse_insn): Likewise.
>   * expr.c (expand_expr_real_1): Likewise.
>   * lra-constraints.c (simplify_operand_subreg): Likewise.
>   * optabs-query.c (can_atomic_load_p): Likewise.
>   * optabs.c (expand_atomic_load): Likewise.
>   (expand_atomic_store): Likewise.
>   * ree.c (combine_reaching_defs): Likewise.
>   * rtl.h (partial_subreg_p, paradoxical_subreg_p): Likewise.
>   * rtlanal.c (nonzero_bits1, lsb_bitfield_op_p): Likewise.
>   * tree.h (type_has_mode_precision_p): Likewise.
>   * ubsan.c (instrument_si_overflow): Likewise.
> 
> gcc/ada/
>   * gcc-interface/misc.c (enumerate_modes): Treat GET_MODE_PRECISION
>   as polynomial.
OK.
jeff


[104/nnn] poly_int: GET_MODE_PRECISION

2017-10-23 Thread Richard Sandiford
This patch changes GET_MODE_PRECISION from an unsigned short
to a poly_uint16.


2017-10-23  Richard Sandiford  
Alan Hayward  
David Sherwood  

gcc/
* machmode.h (mode_precision): Change from unsigned short to
poly_uint16_pod.
(mode_to_precision): Return a poly_uint16 rather than an unsigned
short.
(GET_MODE_PRECISION): Return a constant if ONLY_FIXED_SIZE_MODES,
or if measurement_type is not polynomial.
(HWI_COMPUTABLE_MODE_P): Turn into a function.  Optimize the case
in which the mode is already known to be a scalar_int_mode.
* genmodes.c (emit_mode_precision): Change the type of mode_precision
from unsigned short to poly_uint16_pod.  Use ZERO_COEFFS for the
initializer.
* lto-streamer-in.c (lto_input_mode_table): Use bp_unpack_poly_value
for GET_MODE_PRECISION.
* lto-streamer-out.c (lto_write_mode_table): Use bp_pack_poly_value
for GET_MODE_PRECISION.
* combine.c (update_rsp_from_reg_equal): Treat GET_MODE_PRECISION
as polynomial.
(try_combine, find_split_point, combine_simplify_rtx): Likewise.
(expand_field_assignment, make_extraction): Likewise.
(make_compound_operation_int, record_dead_and_set_regs_1): Likewise.
(get_last_value): Likewise.
* convert.c (convert_to_integer_1): Likewise.
* cse.c (cse_insn): Likewise.
* expr.c (expand_expr_real_1): Likewise.
* lra-constraints.c (simplify_operand_subreg): Likewise.
* optabs-query.c (can_atomic_load_p): Likewise.
* optabs.c (expand_atomic_load): Likewise.
(expand_atomic_store): Likewise.
* ree.c (combine_reaching_defs): Likewise.
* rtl.h (partial_subreg_p, paradoxical_subreg_p): Likewise.
* rtlanal.c (nonzero_bits1, lsb_bitfield_op_p): Likewise.
* tree.h (type_has_mode_precision_p): Likewise.
* ubsan.c (instrument_si_overflow): Likewise.

gcc/ada/
* gcc-interface/misc.c (enumerate_modes): Treat GET_MODE_PRECISION
as polynomial.

Index: gcc/machmode.h
===
--- gcc/machmode.h  2017-10-23 17:25:48.620492005 +0100
+++ gcc/machmode.h  2017-10-23 17:25:54.180292158 +0100
@@ -23,7 +23,7 @@ #define HAVE_MACHINE_MODES
 typedef opt_mode opt_machine_mode;
 
 extern CONST_MODE_SIZE unsigned short mode_size[NUM_MACHINE_MODES];
-extern const unsigned short mode_precision[NUM_MACHINE_MODES];
+extern const poly_uint16_pod mode_precision[NUM_MACHINE_MODES];
 extern const unsigned char mode_inner[NUM_MACHINE_MODES];
 extern const poly_uint16_pod mode_nunits[NUM_MACHINE_MODES];
 extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];
@@ -535,7 +535,7 @@ mode_to_bits (machine_mode mode)
 
 /* Return the base GET_MODE_PRECISION value for MODE.  */
 
-ALWAYS_INLINE unsigned short
+ALWAYS_INLINE poly_uint16
 mode_to_precision (machine_mode mode)
 {
   return mode_precision[mode];
@@ -604,7 +604,30 @@ #define GET_MODE_BITSIZE(MODE) (mode_to_
 
 /* Get the number of value bits of an object of mode MODE.  */
 
-#define GET_MODE_PRECISION(MODE) (mode_to_precision (MODE))
+#if ONLY_FIXED_SIZE_MODES
+#define GET_MODE_PRECISION(MODE) \
+  ((unsigned short) mode_to_precision (MODE).coeffs[0])
+#else
+ALWAYS_INLINE poly_uint16
+GET_MODE_PRECISION (machine_mode mode)
+{
+  return mode_to_precision (mode);
+}
+
+template
+ALWAYS_INLINE typename if_poly::t
+GET_MODE_PRECISION (const T )
+{
+  return mode_to_precision (mode);
+}
+
+template
+ALWAYS_INLINE typename if_nonpoly::t
+GET_MODE_PRECISION (const T )
+{
+  return mode_to_precision (mode).coeffs[0];
+}
+#endif
 
 /* Get the number of integral bits of an object of mode MODE.  */
 extern CONST_MODE_IBIT unsigned char mode_ibit[NUM_MACHINE_MODES];
@@ -863,9 +886,22 @@ #define TRULY_NOOP_TRUNCATION_MODES_P(MO
   (targetm.truly_noop_truncation (GET_MODE_PRECISION (MODE1), \
  GET_MODE_PRECISION (MODE2)))
 
-#define HWI_COMPUTABLE_MODE_P(MODE) \
-  (SCALAR_INT_MODE_P (MODE) \
-   && GET_MODE_PRECISION (MODE) <= HOST_BITS_PER_WIDE_INT)
+/* Return true if MODE is a scalar integer mode that fits in a
+   HOST_WIDE_INT.  */
+
+inline bool
+HWI_COMPUTABLE_MODE_P (machine_mode mode)
+{
+  machine_mode mme = mode;
+  return (SCALAR_INT_MODE_P (mme)
+ && mode_to_precision (mme).coeffs[0] <= HOST_BITS_PER_WIDE_INT);
+}
+
+inline bool
+HWI_COMPUTABLE_MODE_P (scalar_int_mode mode)
+{
+  return GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT;
+}
 
 struct int_n_data_t {
   /* These parts are initailized by genmodes output */
Index: gcc/genmodes.c
===
--- gcc/genmodes.c  2017-10-23 17:25:48.618492077 +0100
+++ gcc/genmodes.c  2017-10-23 17:25:54.178292230 +0100
@@ -1358,13