Go to file
Richard Sandiford dfbddbeb1c Handle data dependence relations with different bases
This patch tries to calculate conservatively-correct distance
vectors for two references whose base addresses are not the same.
It sets a new flag DDR_COULD_BE_INDEPENDENT_P if the dependence
isn't guaranteed to occur.

The motivating example is:

  struct s { int x[8]; };
  void
  f (struct s *a, struct s *b)
  {
    for (int i = 0; i < 8; ++i)
      a->x[i] += b->x[i];
  }

in which the "a" and "b" accesses are either independent or have a
dependence distance of 0 (assuming -fstrict-aliasing).  Neither case
prevents vectorisation, so we can vectorise without an alias check.

I'd originally wanted to do the same thing for arrays as well, e.g.:

  void
  f (int a[][8], struct b[][8])
  {
    for (int i = 0; i < 8; ++i)
      a[0][i] += b[0][i];
  }

I think this is valid because C11 6.7.6.2/6 says:

  For two array types to be compatible, both shall have compatible
  element types, and if both size specifiers are present, and are
  integer constant expressions, then both size specifiers shall have
  the same constant value.

So if we access an array through an int (*)[8], it must have type X[8]
or X[], where X is compatible with int.  It doesn't seem possible in
either case for "a[0]" and "b[0]" to overlap when "a != b".

However, as the comment above "if (same_base_p)" explains, GCC is more
forgiving: it supports arbitrary overlap of arrays and allows arrays to
be accessed with different dimensionality.  There are examples of this
in PR50067.  The patch therefore only handles references that end in a
structure field access.

There are two ways of handling these dependences in the vectoriser:
use them to limit VF, or check at runtime as before.  I've gone for
the approach of checking at runtime if we can, to avoid limiting VF
unnecessarily, but falling back to a VF cap when runtime checks aren't
allowed.

The patch tests whether we queued an alias check with a dependence
distance of X and then picked a VF <= X, in which case it's safe to
drop the alias check.  Since vect_prune_runtime_alias_check_list
can be called twice with different VF for the same loop, it's no
longer safe to clear may_alias_ddrs on exit.  Instead we should use
comp_alias_ddrs to check whether versioning is necessary.

2017-08-04  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/
	* tree-data-ref.h (subscript): Add access_fn field.
	(data_dependence_relation): Add could_be_independent_p.
	(SUB_ACCESS_FN, DDR_COULD_BE_INDEPENDENT_P): New macros.
	(same_access_functions): Move to tree-data-ref.c.
	* tree-data-ref.c (ref_contains_union_access_p): New function.
	(access_fn_component_p): Likewise.
	(access_fn_components_comparable_p): Likewise.
	(dr_analyze_indices): Add a reference to access_fn_component_p.
	(dump_data_dependence_relation): Use SUB_ACCESS_FN instead of
	DR_ACCESS_FN.
	(constant_access_functions): Likewise.
	(add_other_self_distances): Likewise.
	(same_access_functions): Likewise.  (Moved from tree-data-ref.h.)
	(initialize_data_dependence_relation): Use XCNEW and remove
	explicit zeroing of DDR_REVERSED_P.  Look for a subsequence
	of access functions that have the same type.  Allow the
	subsequence to end with different bases in some circumstances.
	Record the chosen access functions in SUB_ACCESS_FN.
	(build_classic_dist_vector_1): Replace ddr_a and ddr_b with
	a_index and b_index.  Use SUB_ACCESS_FN instead of DR_ACCESS_FN.
	(subscript_dependence_tester_1): Likewise dra and drb.
	(build_classic_dist_vector): Update calls accordingly.
	(subscript_dependence_tester): Likewise.
	* tree-ssa-loop-prefetch.c (determine_loop_nest_reuse): Check
	DDR_COULD_BE_INDEPENDENT_P.
	* tree-vectorizer.h (LOOP_REQUIRES_VERSIONING_FOR_ALIAS): Test
	comp_alias_ddrs instead of may_alias_ddrs.
	* tree-vect-data-refs.c (vect_analyze_possibly_independent_ddr):
	New function.
	(vect_analyze_data_ref_dependence): Use it if
	DDR_COULD_BE_INDEPENDENT_P, but fall back to using the recorded
	distance vectors if that fails.
	(dependence_distance_ge_vf): New function.
	(vect_prune_runtime_alias_test_list): Use it.  Don't clear
	LOOP_VINFO_MAY_ALIAS_DDRS.

gcc/testsuite/
	* gcc.dg/vect/vect-alias-check-3.c: New test.
	* gcc.dg/vect/vect-alias-check-4.c: Likewise.
	* gcc.dg/vect/vect-alias-check-5.c: Likewise.

From-SVN: r250867
2017-08-04 10:39:44 +00:00
config Enable -flto in all PGO stages for bootstrap-lto-{,noplugin}.mk. 2017-06-19 13:20:20 +00:00
contrib Added Python implementation of mklog. 2017-08-02 21:01:08 +00:00
fixincludes config.gcc (*-*-vxworks*): Set use_gcc_stdint to "provide". 2017-06-12 12:10:12 +00:00
gcc Handle data dependence relations with different bases 2017-08-04 10:39:44 +00:00
gnattools configure.ac: Add ACX_NONCANONICAL_HOST. 2016-05-16 08:55:12 +00:00
gotools re PR go/81548 ("make distclean" does not clean all of gotools/) 2017-07-26 22:01:36 +00:00
include include/ChangeLog 2017-07-02 20:00:48 +00:00
INSTALL
intl config-ml.in: Remove references to GCJ. 2016-11-15 16:34:02 +00:00
libada re PR ada/80921 (cross compiling fails to build Ada shared libraries) 2017-06-01 10:51:15 +00:00
libatomic Load new scanlang.exp 2017-05-12 09:20:37 +00:00
libbacktrace Add PR number. 2017-08-02 08:45:55 -04:00
libcc1 Remove TYPE_METHODS. 2017-07-21 00:27:51 +00:00
libcilkrts os-unix-sysdep.c (__cilkrts_getticks): Adjust preprocessor test for SPARC/Linux. 2017-06-23 17:33:43 +00:00
libcpp libcpp: preserve ranges within macro expansions (PR c++/79300) 2017-07-07 18:49:09 +00:00
libdecnumber bid2dpd_dpd2bid.c (_bid_to_dpd32): Fix whitespace. 2017-06-29 11:35:03 -06:00
libffi re PR other/79046 (g++ -print-file-name=plugin uses full version number in path) 2017-01-21 09:47:11 +01:00
libgcc config.gcc (arm-wrs-vxworks*): Rework to handle arm-wrs-vxworks7 as well as arm-wrs-vxworks. 2017-08-01 14:14:21 +00:00
libgfortran re PR fortran/81581 (runtime checks for DIM argument of intrinsic SUM missing) 2017-07-31 09:34:36 +00:00
libgo re PR go/81617 (mksigtab.sh fails to resolve NSIG with glibc 2.26) 2017-08-03 18:09:12 +00:00
libgomp re PR c/45784 (gcc OpenMP - error: invalid controlling predicate) 2017-07-27 21:13:42 +02:00
libhsail-rt Minor BRIG/HSAIL frontend updates and bug fixes: 2017-05-04 05:50:21 +00:00
libiberty include/ChangeLog 2017-07-02 20:00:48 +00:00
libitm PR c++/80560 - warn on undefined memory operations involving non-trivial types 2017-06-15 21:48:59 -06:00
libmpx * mpxrt/mpxrt-utils.h (__mpxrt_stop): New prototype. 2017-01-30 15:26:24 +01:00
libobjc re PR tree-optimization/79256 (FAIL: gcc.dg/vect/pr25413a.c execution test) 2017-02-07 11:29:06 +00:00
liboffloadmic libgomp: Provide prototypes for functions implemented by libgomp plugins 2017-01-31 15:32:58 +01:00
libquadmath * math/powq.c (powq): Use uint32_t instead of u_int32_t. 2017-07-19 19:53:58 +00:00
libsanitizer re PR sanitizer/80998 (Implement -fsanitize=pointer-overflow) 2017-07-28 12:37:51 +02:00
libssp ssp.c (__guard_setup): Suppress unused variable warning. 2017-04-02 00:35:58 +00:00
libstdc++-v3 re PR libstdc++/81599 (Error in documentation of std::stack) 2017-07-31 13:44:16 +00:00
libvtv re PR other/79046 (g++ -print-file-name=plugin uses full version number in path) 2017-01-21 09:47:11 +01:00
lto-plugin re PR lto/81487 ([mingw32] ld.exe: error: asprintf failed) 2017-07-21 15:58:14 +00:00
maintainer-scripts gcc_release (XZ): Default to xz --best. 2017-05-23 23:14:10 +00:00
zlib re PR bootstrap/79771 (in-tree zlib breaks build) 2017-03-14 23:01:23 -06:00
.dir-locals.el
.gitattributes add basic .gitattributes files to notice whitespace issues 2016-04-23 02:37:43 +00:00
.gitignore .gitignore: Ignore in-tree prerequisites. 2016-09-09 17:20:55 -04:00
ABOUT-NLS
ChangeLog Add myself to MAINTAINERS. 2017-07-31 12:02:33 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in config-ml.in: Remove references to GCJ. 2016-11-15 16:34:02 +00:00
config.guess * config.guess: Import latest from upstream. 2017-03-18 18:22:06 +00:00
config.rpath
config.sub * config.sub: Import latest version. 2016-12-29 22:04:53 +11:00
configure configure.ac (target-libffi): Don't disable for AIX. 2017-07-28 14:56:28 -04:00
configure.ac configure.ac (target-libffi): Don't disable for AIX. 2017-07-28 14:56:28 -04:00
COPYING
COPYING3
COPYING3.LIB
COPYING.LIB
COPYING.RUNTIME
depcomp
install-sh
libtool-ldflags
libtool.m4
lt~obsolete.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
MAINTAINERS Update myself in MAINTAINERS 2017-07-31 11:37:27 -07:00
Makefile.def re PR bootstrap/81217 (Makefile:22754: warning: overriding recipe for target 'profiledbootstrap') 2017-06-28 07:54:14 +00:00
Makefile.in re PR bootstrap/81217 (Makefile:22754: warning: overriding recipe for target 'profiledbootstrap') 2017-06-28 07:54:14 +00:00
Makefile.tpl Introduce 4-stages profiledbootstrap to get a better profile. 2017-06-19 13:19:56 +00:00
missing
mkdep
mkinstalldirs
move-if-change
README
symlink-tree
ylwrap

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.