This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Add autovectorize_vector_sizes target hook
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 6 Oct 2010 14:41:50 +0200 (CEST)
- Subject: [PATCH] Add autovectorize_vector_sizes target hook
For AVX auto-vectorization we have to deal with the asymmetry of
int vs. float vector support. The simplest thing to do is to
re-try vectorization with SSE only when asymmetric AVX vectorization
fails.
The autovectorize_vector_sizes target hook tells the vectorizer
which vector modes to try based on their size.
Bootstrapped and tested on x86_64-unknown-linux-gnu, I'll apply
this together with the other two patches if they are deemed ok.
Thanks,
Richard.
2010-10-06 Richard Guenther <rguenther@suse.de>
* target.def (autovectorize_vector_sizes): New target hook.
* targhooks.c (default_autovectorize_vector_sizes): New function.
* targhooks.h (default_autovectorize_vector_sizes): Declare.
* doc/tm.texi.in (TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES):
Document.
* doc/tm.texi: Update.
* config/i386/i386.c (ix86_autovectorize_vector_sizes): New function.
(TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES): Define.
Index: trunk/gcc/config/i386/i386.c
===================================================================
*** trunk.orig/gcc/config/i386/i386.c 2010-10-06 13:30:50.000000000 +0200
--- trunk/gcc/config/i386/i386.c 2010-10-06 13:32:58.000000000 +0200
*************** ix86_preferred_simd_mode (enum machine_m
*** 32993,32998 ****
--- 32993,33007 ----
return word_mode;
}
+ /* If AVX is enabled then try vectorizing with both 256bit and 128bit
+ vectors. */
+
+ static unsigned int
+ ix86_autovectorize_vector_sizes (void)
+ {
+ return TARGET_AVX ? 32 | 16 : 0;
+ }
+
/* Initialize the GCC target structure. */
#undef TARGET_RETURN_IN_MEMORY
#define TARGET_RETURN_IN_MEMORY ix86_return_in_memory
*************** ix86_preferred_simd_mode (enum machine_m
*** 33253,33258 ****
--- 33262,33270 ----
#undef TARGET_VECTORIZE_PREFERRED_SIMD_MODE
#define TARGET_VECTORIZE_PREFERRED_SIMD_MODE \
ix86_preferred_simd_mode
+ #undef TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES
+ #define TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES \
+ ix86_autovectorize_vector_sizes
#undef TARGET_SET_CURRENT_FUNCTION
#define TARGET_SET_CURRENT_FUNCTION ix86_set_current_function
Index: trunk/gcc/doc/tm.texi.in
===================================================================
*** trunk.orig/gcc/doc/tm.texi.in 2010-10-06 13:30:50.000000000 +0200
--- trunk/gcc/doc/tm.texi.in 2010-10-06 13:32:58.000000000 +0200
*************** equal to @code{word_mode}, because the v
*** 5766,5771 ****
--- 5766,5778 ----
transformations even in absence of specialized @acronym{SIMD} hardware.
@end deftypefn
+ @hook TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES
+ This hook should return a mask of sizes that should be iterated over
+ after trying to autovectorize using the vector size derived from the
+ mode returned by @code{TARGET_VECTORIZE_PREFERRED_SIMD_MODE}.
+ The default is zero which means to not iterate over other vector sizes.
+ @end deftypefn
+
@node Anchored Addresses
@section Anchored Addresses
@cindex anchored addresses
Index: trunk/gcc/target.def
===================================================================
*** trunk.orig/gcc/target.def 2010-10-06 13:30:50.000000000 +0200
--- trunk/gcc/target.def 2010-10-06 13:32:58.000000000 +0200
*************** DEFHOOK
*** 889,894 ****
--- 889,903 ----
(enum machine_mode mode),
default_preferred_simd_mode)
+ /* Returns a mask of vector sizes to iterate over when auto-vectorizing
+ after processing the preferred one derived from preferred_simd_mode. */
+ DEFHOOK
+ (autovectorize_vector_sizes,
+ "",
+ unsigned int,
+ (void),
+ default_autovectorize_vector_sizes)
+
HOOK_VECTOR_END (vectorize)
#undef HOOK_PREFIX
Index: trunk/gcc/targhooks.c
===================================================================
*** trunk.orig/gcc/targhooks.c 2010-10-06 13:30:50.000000000 +0200
--- trunk/gcc/targhooks.c 2010-10-06 13:32:58.000000000 +0200
*************** default_preferred_simd_mode (enum machin
*** 985,990 ****
--- 985,999 ----
return word_mode;
}
+ /* By default only the size derived from the preferred vector mode
+ is tried. */
+
+ unsigned int
+ default_autovectorize_vector_sizes (void)
+ {
+ return 0;
+ }
+
/* Determine whether or not a pointer mode is valid. Assume defaults
of ptr_mode or Pmode - can be overridden. */
bool
Index: trunk/gcc/targhooks.h
===================================================================
*** trunk.orig/gcc/targhooks.h 2010-10-06 13:30:50.000000000 +0200
--- trunk/gcc/targhooks.h 2010-10-06 13:32:58.000000000 +0200
*************** default_builtin_support_vector_misalignm
*** 87,92 ****
--- 87,93 ----
const_tree,
int, bool);
extern enum machine_mode default_preferred_simd_mode (enum machine_mode mode);
+ extern unsigned int default_autovectorize_vector_sizes (void);
/* These are here, and not in hooks.[ch], because not all users of
hooks.h include tm.h, and thus we don't have CUMULATIVE_ARGS. */
Index: trunk/gcc/doc/tm.texi
===================================================================
*** trunk.orig/gcc/doc/tm.texi 2010-10-06 13:06:25.000000000 +0200
--- trunk/gcc/doc/tm.texi 2010-10-06 13:33:16.000000000 +0200
*************** equal to @code{word_mode}, because the v
*** 5768,5773 ****
--- 5768,5780 ----
transformations even in absence of specialized @acronym{SIMD} hardware.
@end deftypefn
+ @deftypefn {Target Hook} {unsigned int} TARGET_VECTORIZE_AUTOVECTORIZE_VECTOR_SIZES (void)
+ This hook should return a mask of sizes that should be iterated over
+ after trying to autovectorize using the vector size derived from the
+ mode returned by @code{TARGET_VECTORIZE_PREFERRED_SIMD_MODE}.
+ The default is zero which means to not iterate over other vector sizes.
+ @end deftypefn
+
@node Anchored Addresses
@section Anchored Addresses
@cindex anchored addresses