public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [00/77] Add wrapper classes for machine_modes
@ 2017-07-13  8:35 Richard Sandiford
  2017-07-13  8:36 ` [01/77] Add an E_ prefix to mode names Richard Sandiford
                   ` (77 more replies)
  0 siblings, 78 replies; 175+ messages in thread
From: Richard Sandiford @ 2017-07-13  8:35 UTC (permalink / raw)
  To: gcc-patches

This series is an update of:

    https://gcc.gnu.org/ml/gcc-patches/2016-12/msg00766.html

It adds a group of wrapper classes around machine_mode for modes that
are known to belong to, or need to belong to, a particular mode_class.
For example, it adds a scalar_int_mode wrapper for MODE_INT and
MODE_PARTIAL_INT modes, a scalar_float_mode wrapper for MODE_FLOAT and
MODE_DECIMAL_FLOAT modes, and so on.

These wrapper classes aren't meant to form an inheritance tree in the
way that rtx_insn or gimple do.  They really just bundle a machine_mode
with a static assertion that a particular condition holds.  In principle
there could be a wrapper class for any useful condition.

The reason for using wrapper classes is that they provide more
build-time checking that modes have the right class.  In the best
cases they avoid the need for any runtime assertions, but "at worst" they
force the assertion further up to the place that derives the mode, often
a TYPE_MODE or a GET_MODE.  Enforcing the condition at this level should
catch mistakes earlier and with less sensitivity to the following code
paths.  It should also make the basis for the assertion more obvious;
e.g. scalar_int_mode uses of TYPE_MODEs are often guarded at some level
by an INTEGRAL_TYPE_P test.

I know of three specific cases in which the static type checking
forced fixes for things that turned out to be real bugs (although
we didn't know that at the time, otherwise we'd have posted patches).
They were later fixed for trunk by:

    https://gcc.gnu.org/ml/gcc-patches/2016-07/msg01783.html
    https://gcc.gnu.org/ml/gcc-patches/2016-11/msg02983.html
    https://gcc.gnu.org/ml/gcc-patches/2016-11/msg02896.html

It also found problems that seemed to be latent, but the fixes for those
went into GCC 7, so there are none to go with this iteration of the series.
The most common sources of problems seemed to be using VOIDmode or BLKmode
where a scalar integer was expected (e.g. when getting the number of bits
in the value), and simplifying vector operations in ways that only make
sense for scalars.

The series is part of the SVE submission and includes most of the
changes in group C from:

    https://gcc.gnu.org/ml/gcc/2016-11/msg00033.html

Since SVE has variable-length vectors, the SVE series as a whole needs
to change the size of a vector mode from being a known compile-time
constant to being (possibly) a run-time invariant.  It then needs to
do the same for unconstrained machine_modes, which might or might not be
vectors.  Introducing these new constrained types for scalar and complex
modes means that we can continue to treat them as having a constant size.

Mostly this is just a tweaked version of the original series,
rebased onto current trunk.  There is one significant difference
though: the first iteration treated machine_mode as an all-encompassing
wrapper class whereas this version keeps it as an enum.  Treating it as
a wrapper class made it consistent with the other classes and meant that
it would be easier in future to use member functions to access mode
properties (e.g. "mode.size ()" rather than "GET_MODE_SIZE (mode)")
if that was thought to be a good thing.  However, Martin's recent
memset/memcpy warning shows that there are still many places that
expect machine_modes to be POD-ish, so in the end it seemed better
to leave machine_mode as an enum for now.

Also, I've now split the scalar_mode patch into 11 separate patches,
since it was very difficult to review/reread in its old form.

In terms of compile time, the series is actually a very slight win
for --enable-checking=release builds and a more marked win for
--enable-checking=yes,rtl.  That might seem unlikely, but there are
several possible reasons:

(1) The series makes all the machmode.h macros that used:

      __builtin_constant_p (M) ? foo_inline (M) : foo_array[M]

    forward to an ALWAYS_INLINE function, so that (a) M is only evaluated
    once and (b) __builtin_constant_p is applied to a variable, and so is
    deferred until later passes.  This helped the optimisation to fire in
    more cases and to continue firing when M is a class rather than a
    raw enum.

(2) The series has a tendency to evaluate modes once, rather than
    continually fetching them from (sometimes quite deep) rtx nests.
    Refetching a mode is a particular problem if a call comes between
    two uses, since the compiler then has to re-evaluate the whole thing.

(3) The series introduces many uses of new SCALAR_*TYPE_MODE macros,
    as alternatives to TYPE_MODE.  The new macros avoid the usual:

      (VECTOR_TYPE_P (TYPE_CHECK (NODE)) \
       ? vector_type_mode (NODE) : (NODE)->type_common.mode)

    and become direct field accesses in release builds.

    VECTOR_TYPE_P would be consistently false for these uses, and thus
    predictable at runtime.  However, we can't predict them to be false
    at compile time without profile feedback, since in other uses of
    TYPE_MODE the VECTOR_TYPE_P condition can be quite likely or even
    guaranteed.  This means (for example) that call-clobbered registers
    would usually be treated as clobbered by the condition as a whole.

I tested this by compiling the testsuite for:

    aarch64-linux-gnu alpha-linux-gnu arc-elf arm-linux-gnueabi
    arm-linux-gnueabihf avr-elf bfin-elf c6x-elf cr16-elf cris-elf
    epiphany-elf fr30-elf frv-linux-gnu ft32-elf h8300-elf
    hppa64-hp-hpux11.23 ia64-linux-gnu i686-pc-linux-gnu
    i686-apple-darwin iq2000-elf lm32-elf m32c-elf m32r-elf
    m68k-linux-gnu mcore-elf microblaze-elf mips-linux-gnu
    mipsisa64-linux-gnu mmix mn10300-elf moxie-rtems msp430-elf
    nds32le-elf nios2-linux-gnu nvptx-none pdp11 powerpc-linux-gnuspe
    powerpc-eabispe powerpc64-linux-gnu powerpc-ibm-aix7.0 riscv64-elf
    rl78-elf rx-elf s390-linux-gnu s390x-linux-gnu sh-linux-gnu
    sparc-linux-gnu sparc64-linux-gnu sparc-wrs-vxworks spu-elf
    tilegx-elf tilepro-elf xstormy16-elf v850-elf vax-netbsdelf
    visium-elf x86_64-darwin x86_64-linux-gnu xtensa-elf

and checking that there were no changes in assembly.  Also tested
in the normal way on aarch64-linux-gnu, powerc64-linux-gnu and
x86_64-linux-gnu.

Thanks,
Richard

^ permalink raw reply	[flat|nested] 175+ messages in thread

end of thread, other threads:[~2017-09-05  8:49 UTC | newest]

Thread overview: 175+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-13  8:35 [00/77] Add wrapper classes for machine_modes Richard Sandiford
2017-07-13  8:36 ` [01/77] Add an E_ prefix to mode names Richard Sandiford
2017-08-11 16:56   ` Jeff Law
2017-07-13  8:38 ` [03/77] Allow machine modes to be classes Richard Sandiford
2017-08-11 17:02   ` Jeff Law
2017-07-13  8:38 ` [02/77] Add an E_ prefix to mode names and update case statements Richard Sandiford
2017-08-11 17:01   ` Jeff Law
2017-07-13  8:39 ` [04/77] Add FOR_EACH iterators for modes Richard Sandiford
2017-08-11 17:30   ` Jeff Law
2017-08-11 17:51     ` Richard Sandiford
2017-08-11 17:57       ` Jeff Law
2017-08-11 18:09   ` Jeff Law
2017-07-13  8:39 ` [05/77] Small tweak to array_value_type Richard Sandiford
2017-08-11 17:50   ` Jeff Law
2017-07-13  8:40 ` [07/77] Add scalar_float_mode Richard Sandiford
2017-08-11 18:12   ` Jeff Law
2017-07-13  8:40 ` [06/77] Make GET_MODE_WIDER return an opt_mode Richard Sandiford
2017-08-11 18:11   ` Jeff Law
2017-08-11 19:38     ` Richard Sandiford
2017-08-28 18:35       ` Jeff Law
2017-08-28 19:13         ` Richard Sandiford
2017-08-28 20:56           ` Jeff Law
2017-08-29 15:29             ` Richard Sandiford
2017-08-29 15:42               ` Jeff Law
2017-08-29 15:53                 ` Richard Sandiford
2017-08-29 16:10                   ` Jeff Law
2017-07-13  8:41 ` [09/77] Add SCALAR_FLOAT_TYPE_MODE Richard Sandiford
2017-08-11 18:16   ` Jeff Law
2017-07-13  8:41 ` [08/77] Simplify gen_trunc/extend_conv_libfunc Richard Sandiford
2017-08-11 18:13   ` Jeff Law
2017-07-13  8:42 ` [11/77] Add a float_mode_for_size helper function Richard Sandiford
2017-08-11 18:19   ` Jeff Law
2017-07-13  8:42 ` [12/77] Use opt_scalar_float_mode when iterating over float modes Richard Sandiford
2017-08-11 19:14   ` Jeff Law
2017-07-13  8:42 ` [10/77] Make assemble_real take a scalar_float_mode Richard Sandiford
2017-08-11 18:16   ` Jeff Law
2017-07-13  8:43 ` [14/77] Make libgcc_floating_mode_supported_p " Richard Sandiford
2017-08-11 19:21   ` Jeff Law
2017-07-13  8:43 ` [13/77] Make floatn_mode return an opt_scalar_float_mode Richard Sandiford
2017-08-11 18:25   ` Jeff Law
2017-07-13  8:44 ` [16/77] Add scalar_int_mode_pod Richard Sandiford
2017-08-14 18:40   ` Jeff Law
2017-07-13  8:44 ` [17/77] Add an int_mode_for_size helper function Richard Sandiford
2017-08-14 18:51   ` Jeff Law
2017-07-13  8:44 ` [15/77] Add scalar_int_mode Richard Sandiford
2017-08-14 18:38   ` Jeff Law
2017-07-13  8:45 ` [19/77] Add a smallest_int_mode_for_size helper function Richard Sandiford
2017-08-14 19:29   ` Jeff Law
2017-07-13  8:45 ` [18/77] Make int_mode_for_mode return an opt_scalar_int_mode Richard Sandiford
2017-08-14 19:16   ` Jeff Law
2017-07-13  8:46 ` [20/77] Replace MODE_INT checks with is_int_mode Richard Sandiford
2017-08-14 19:32   ` Jeff Law
2017-07-13  8:46 ` [21/77] Replace SCALAR_INT_MODE_P checks with is_a <scalar_int_mode> Richard Sandiford
2017-08-14 20:21   ` Jeff Law
2017-07-13  8:46 ` [22/77] Replace !VECTOR_MODE_P " Richard Sandiford
2017-08-14 19:35   ` Jeff Law
2017-07-13  8:47 ` [24/77] Replace a != BLKmode check " Richard Sandiford
2017-08-14 19:50   ` Jeff Law
2017-07-13  8:47 ` [23/77] Replace != VOIDmode checks " Richard Sandiford
2017-08-14 19:50   ` Jeff Law
2017-07-13  8:48 ` [26/77] Use is_a <scalar_int_mode> in subreg/extract simplifications Richard Sandiford
2017-08-15 18:19   ` Jeff Law
2017-07-13  8:48 ` [25/77] Use is_a <scalar_int_mode> for bitmask optimisations Richard Sandiford
2017-08-14 20:06   ` Jeff Law
2017-07-13  8:48 ` [27/77] Use is_a <scalar_int_mode> before LOAD_EXTEND_OP Richard Sandiford
2017-08-14 20:47   ` Jeff Law
2017-07-13  8:49 ` [29/77] Make some *_loc_descriptor helpers take scalar_int_mode Richard Sandiford
2017-08-14 20:47   ` Jeff Law
2017-07-13  8:49 ` [28/77] Use is_a <scalar_int_mode> for miscellaneous types of test Richard Sandiford
2017-08-15 19:23   ` Jeff Law
2017-07-13  8:49 ` [30/77] Use scalar_int_mode for doubleword splits Richard Sandiford
2017-08-14 21:28   ` Jeff Law
2017-07-13  8:50 ` [32/77] Check is_a <scalar_int_mode> before calling valid_pointer_mode Richard Sandiford
2017-08-14 21:37   ` Jeff Law
2017-07-13  8:50 ` [33/77] Add a NARROWEST_INT_MODE macro Richard Sandiford
2017-08-14 23:46   ` Jeff Law
2017-07-13  8:50 ` [31/77] Use scalar_int_mode for move2add Richard Sandiford
2017-08-15 21:16   ` Jeff Law
2017-07-13  8:51 ` [34/77] Add a SCALAR_INT_TYPE_MODE macro Richard Sandiford
2017-08-15 21:19   ` Jeff Law
2017-07-13  8:51 ` [36/77] Use scalar_int_mode in the RTL iv routines Richard Sandiford
2017-08-16 17:27   ` Jeff Law
2017-07-13  8:51 ` [37/77] Use scalar_int_mode when emitting cstores Richard Sandiford
2017-08-15 23:29   ` Jeff Law
2017-07-13  8:51 ` [35/77] Add uses of as_a <scalar_int_mode> Richard Sandiford
2017-08-15 22:35   ` Jeff Law
2017-07-13  8:52 ` [38/77] Move SCALAR_INT_MODE_P out of strict_volatile_bitfield_p Richard Sandiford
2017-08-15 23:50   ` Jeff Law
2017-07-13  8:52 ` [39/77] Two changes to the get_best_mode interface Richard Sandiford
2017-08-16 17:50   ` Jeff Law
2017-07-13  8:52 ` [40/77] Use scalar_int_mode for extraction_insn fields Richard Sandiford
2017-08-16 18:25   ` Jeff Law
2017-07-13  8:53 ` [41/77] Split scalar integer handling out of force_to_mode Richard Sandiford
2017-08-16 18:29   ` Jeff Law
2017-07-13  8:53 ` [42/77] Use scalar_int_mode in simplify_shift_const_1 Richard Sandiford
2017-08-16 18:46   ` Jeff Law
2017-07-13  8:54 ` [46/77] Make widest_int_mode_for_size return a scalar_int_mode Richard Sandiford
2017-08-24  6:15   ` Jeff Law
2017-07-13  8:54 ` [43/77] Use scalar_int_mode in simplify_comparison Richard Sandiford
2017-08-24  4:29   ` Jeff Law
2017-07-13  8:54 ` [45/77] Make extract_left_shift take a scalar_int_mode Richard Sandiford
2017-08-24  4:30   ` Jeff Law
2017-07-13  8:54 ` [44/77] Make simplify_and_const_int " Richard Sandiford
2017-08-24  4:29   ` Jeff Law
2017-07-13  8:55 ` [49/77] Simplify nonzero/num_sign_bits hooks Richard Sandiford
2017-08-24  9:19   ` Jeff Law
2017-07-13  8:55 ` [47/77] Make subroutines of nonzero_bits operate on scalar_int_mode Richard Sandiford
2017-08-24  6:59   ` Jeff Law
2017-07-13  8:55 ` [48/77] Make subroutines of num_sign_bit_copies " Richard Sandiford
2017-08-24  9:19   ` Jeff Law
2017-07-13  8:56 ` [51/77] Use opt_scalar_int_mode when iterating over integer modes Richard Sandiford
2017-08-24 17:28   ` Jeff Law
2017-07-13  8:56 ` [52/77] Use scalar_int_mode in extract/store_bit_field Richard Sandiford
2017-08-24 18:21   ` Jeff Law
2017-07-13  8:56 ` [50/77] Add helper routines for SUBREG_PROMOTED_VAR_P subregs Richard Sandiford
2017-08-24  6:17   ` Jeff Law
2017-07-13  8:57 ` [54/77] Add explicit int checks for alternative optab implementations Richard Sandiford
2017-08-24 21:35   ` Jeff Law
2017-07-13  8:57 ` [53/77] Pass a mode to const_scalar_mask_from_tree Richard Sandiford
2017-08-24  6:21   ` Jeff Law
2017-07-13  8:58 ` [55/77] Use scalar_int_mode in simplify_const_unary_operation Richard Sandiford
2017-08-24 21:35   ` Jeff Law
2017-07-13  8:58 ` [57/77] Use scalar_int_mode in expand_expr_addr_expr Richard Sandiford
2017-08-24 21:36   ` Jeff Law
2017-07-13  8:58 ` [56/77] Use the more specific type when two modes are known to be equal Richard Sandiford
2017-08-24  6:22   ` Jeff Law
2017-07-13  8:59 ` [60/77] Pass scalar_int_modes to do_jump_by_parts_* Richard Sandiford
2017-08-24 21:52   ` Jeff Law
2017-07-13  8:59 ` [58/77] Use scalar_int_mode in a try_combine optimisation Richard Sandiford
2017-08-24 21:37   ` Jeff Law
2017-07-13  8:59 ` [59/77] Add a rtx_jump_table_data::get_data_mode helper Richard Sandiford
2017-08-24 21:39   ` Jeff Law
2017-07-13  9:00 ` [61/77] Use scalar_int_mode in the AArch64 port Richard Sandiford
2017-08-24 21:56   ` Jeff Law
2017-09-05  8:49   ` James Greenhalgh
2017-07-13  9:01 ` [62/77] Big machine_mode to scalar_int_mode replacement Richard Sandiford
2017-08-24 21:57   ` Jeff Law
2017-07-13  9:01 ` [63/77] Simplifications after type switch Richard Sandiford
2017-08-24 22:09   ` Jeff Law
2017-07-13  9:01 ` [64/77] Add a scalar_mode class Richard Sandiford
2017-08-25  5:03   ` Jeff Law
2017-07-13  9:02 ` [65/77] Add a SCALAR_TYPE_MODE macro Richard Sandiford
2017-08-25  5:04   ` Jeff Law
2017-07-13  9:02 ` [67/77] Use scalar_mode in fixed-value.* Richard Sandiford
2017-08-25  8:15   ` Jeff Law
2017-07-13  9:02 ` [66/77] Use scalar_mode for constant integers Richard Sandiford
2017-08-25  5:05   ` Jeff Law
2017-08-30 12:56     ` Richard Sandiford
2017-07-13  9:02 ` [68/77] Use scalar_mode for is_int_mode/is_float_mode pairs Richard Sandiford
2017-08-25  6:19   ` Jeff Law
2017-07-13  9:03 ` [71/77] Use opt_scalar_mode for mode iterators Richard Sandiford
2017-08-25 16:46   ` Jeff Law
2017-07-13  9:03 ` [70/77] Make expand_fix/float check for scalar modes Richard Sandiford
2017-08-25  8:53   ` Jeff Law
2017-07-13  9:03 ` [69/77] Split scalar-only part out of convert_mode Richard Sandiford
2017-08-25  8:21   ` Jeff Law
2017-07-13  9:04 ` [73/77] Pass scalar_mode to scalar_mode_supported_p Richard Sandiford
2017-08-25 16:46   ` Jeff Law
2017-07-13  9:04 ` [72/77] " Richard Sandiford
2017-08-25 16:46   ` Jeff Law
2017-07-13  9:05 ` [75/77] Use scalar_mode in the AArch64 port Richard Sandiford
2017-08-25 16:48   ` Jeff Law
2017-09-05  8:49   ` James Greenhalgh
2017-07-13  9:05 ` [77/77] Add a complex_mode class Richard Sandiford
2017-08-25 17:43   ` Jeff Law
2017-07-13  9:05 ` [76/77] Add a scalar_mode_pod class Richard Sandiford
2017-08-25 17:16   ` Jeff Law
2017-07-13  9:05 ` [74/77] Various small scalar_mode changes Richard Sandiford
2017-08-25 17:31   ` Jeff Law
2017-07-22 21:02 ` [00/77] Add wrapper classes for machine_modes Segher Boessenkool
2017-07-24  9:28   ` Richard Sandiford
2017-07-24 10:56     ` Segher Boessenkool
2017-07-24 12:53       ` Richard Sandiford
2017-07-24 13:42         ` Segher Boessenkool
2017-07-24 18:31           ` Richard Biener

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