Go to file
Richard Sandiford e3969868d6 Fix SSA update when vectorisation adds a vdef to a read-only loop
This patch fixes an awkward corner case in which:

(a) we apply if-conversion to a loop;

(b) the original scalar loop doesn't have a vdef, and thus doesn't
    need a virtual phi;

(c) the vectorised main loop does need a vdef and a virtual phi (see below);

(d) we also vectorise the epilogue; and

(e) the vectorised epilogue still needs a scalar epilogue

The specific case in which (c) applies is if a read-only loop is
vectorised using IFN_LOAD_LANES, which uses clobber statements to
mark the lifetime of the temporary array.

The vectoriser relies on the SSA renamer to update virtual operands.
All would probably be well if it postponed this update until after
it had vectorised both the main loop and the epilogue loop.  However,
when vectorising the epilogue, vect_do_peeling does:

  create_lcssa_for_virtual_phi (loop);
  update_ssa (TODO_update_ssa_only_virtuals);

(with "loop" in this case being the to-be-vectorised epilogue loop).
So the vectoriser puts the virtual operand into SSA form for the
vectorised main loop as a separate step, during the early stages
of vectorising the epilogue.

I wasn't sure at first why that update_ssa was there.  It looked
initially like it was related to create_lcssa_for_virtual_phi,
which seemed strange when create_lcssa_for_virtual_phi keeps the
SSA form up-to-date.  But before r241099 it had the following comment,
which AFAICT is still the reason:

  /* We might have a queued need to update virtual SSA form.  As we
     delete the update SSA machinery below after doing a regular
     incremental SSA update during loop copying make sure we don't
     lose that fact.
     ???  Needing to update virtual SSA form by renaming is unfortunate
     but not all of the vectorizer code inserting new loads / stores
     properly assigns virtual operands to those statements.  */

The patch restores that comment since IMO it's helpful.

(a), (d) and (e) mean that we copy the original un-if-converted scalar
loop to act as the scalar epilogue.  The update_ssa above means that this
copying needs to cope with any new virtual SSA names in the main loop.
The code to do that (reasonably) assumed that one of two things was true:

(1) the scalar loop and the vector loops don't have vdefs, and so no
    virtual operand update is needed.  The definition that applies
    on entry to the loops is the same in all cases.

(2) the scalar loop and the vector loops have virtual phis, and so --
    after applying create_lcssa_for_virtual_phi on the to-be-vectorised
    epilogue loop -- the virtual operand update can be handled in the
    same way as for normal SSA names.

But (b) and (c) together mean that the scalar loop and the
still-to-be-vectorised epilogue loop have no virtual phi that (2)
can use.  We'd therefore keep the original vuses when duplicating,
rather than updating them to the definition that applies on exit
from the epilogue loop.  (Since the epilogue is still unvectorised
and has no vdefs, the definition that applies on exit is the same
as the one that applies on entry.)

This patch therefore adds a third case: the scalar loop and
to-be-vectorised epilogue have no virtual defs, but the main loop does.

2019-12-31  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
	* tree-vect-loop-manip.c (create_lcssa_for_virtual_phi): Return
	the incoming virtual operand definition.
	(vect_do_peeling): When vectorizing an epilogue loop, handle the
	case in which the main loop has a virtual phi and the epilogue
	and scalar loops don't.  Restore an earlier comment about the
	update_ssa call.

gcc/testsuite/
	* gcc.dg/vect/vect-epilogues-2.c: New test.

From-SVN: r279802
2019-12-31 08:28:24 +00:00
config
contrib
fixincludes re PR libgomp/93066 (libgomp/target.c:525:46: error: expected expression before ')' token) 2019-12-30 20:33:17 +00:00
gcc Fix SSA update when vectorisation adds a vdef to a read-only loop 2019-12-31 08:28:24 +00:00
gnattools
gotools
include Add OpenACC 2.6 `acc_get_property' support 2019-12-22 19:54:09 +00:00
INSTALL
intl
libada
libatomic
libbacktrace
libcc1 decl2.c (delete_sanity): Add location_t parameter and use it throughout. 2019-12-30 13:23:40 +00:00
libcpp
libdecnumber
libffi
libgcc Introduce an internal API for VxWorks version checks 2019-12-30 21:42:26 +00:00
libgfortran
libgo re PR go/93020 (Final patches to build gcc-10 on GNU/Hurd) 2019-12-24 05:05:32 +00:00
libgomp re PR bootstrap/93074 (build FAIL with --enable-offload-targets=nvptx-none) 2019-12-28 10:26:03 +01:00
libhsail-rt
libiberty
libitm
libobjc
liboffloadmic Add OpenACC 2.6 `acc_get_property' support 2019-12-22 19:54:09 +00:00
libphobos
libquadmath
libsanitizer
libssp
libstdc++-v3 VxWorks has_nanosleep for libstdc++ enable-libstdcxx-time auto 2019-12-30 22:36:14 +00:00
libvtv
lto-plugin
maintainer-scripts
zlib
.dir-locals.el
.gitattributes
.gitignore
ABOUT-NLS
ar-lib
ChangeLog Add myself to MAINTAINERS 2019-12-20 10:43:47 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in
config.guess
config.rpath
config.sub
configure
configure.ac
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 Add myself to MAINTAINERS 2019-12-20 10:43:47 +00:00
Makefile.def
Makefile.in
Makefile.tpl
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README
symlink-tree
test-driver
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.