From 81fd62d1378b7ddc1fa0967cbddcdcdcdd2d8d8c Mon Sep 17 00:00:00 2001 From: Tamar Christina Date: Sun, 12 Mar 2023 18:42:04 +0000 Subject: middle-end: Implement preferred_div_as_shifts_over_mult [PR108583] This now implements a hook preferred_div_as_shifts_over_mult that indicates whether a target prefers that the vectorizer decomposes division as shifts rather than multiplication when possible. In order to be able to use this we need to check whether the current precision has enough bits to do the operation without any of the additions overflowing. We use range information to determine this and only do the operation if we're sure am overflow won't occur. This now uses ranger to do this range check. This seems to work better than vect_get_range_info which uses range_query, but I have not switched the interface of vect_get_range_info over in this PR fix. As Andy said before initializing a ranger instance is cheap but not free, and if the intention is to call it often during a pass it should be instantiated at pass startup and passed along to the places that need it. This is a big refactoring and doesn't seem right to do in this PR. But we should in GCC 14. Currently we only instantiate it after a long series of much cheaper checks. gcc/ChangeLog: PR target/108583 * target.def (preferred_div_as_shifts_over_mult): New. * doc/tm.texi.in: Document it. * doc/tm.texi: Regenerate. * targhooks.cc (default_preferred_div_as_shifts_over_mult): New. * targhooks.h (default_preferred_div_as_shifts_over_mult): New. * tree-vect-patterns.cc (vect_recog_divmod_pattern): Use it. gcc/testsuite/ChangeLog: PR target/108583 * gcc.dg/vect/vect-div-bitmask-4.c: New test. * gcc.dg/vect/vect-div-bitmask-5.c: New test. --- gcc/targhooks.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gcc/targhooks.h') diff --git a/gcc/targhooks.h b/gcc/targhooks.h index 555160d..cf3d310 100644 --- a/gcc/targhooks.h +++ b/gcc/targhooks.h @@ -53,6 +53,8 @@ extern scalar_int_mode default_unwind_word_mode (void); extern unsigned HOST_WIDE_INT default_shift_truncation_mask (machine_mode); extern unsigned int default_min_divisions_for_recip_mul (machine_mode); +extern bool default_preferred_div_as_shifts_over_mult + (const_tree); extern int default_mode_rep_extended (scalar_int_mode, scalar_int_mode); extern tree default_stack_protect_guard (void); -- cgit v1.1