[16/n] PR85694: Add detection of averaging operations
authorRichard Sandiford <richard.sandiford@arm.com>
Tue, 3 Jul 2018 10:03:44 +0000 (10:03 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Tue, 3 Jul 2018 10:03:44 +0000 (10:03 +0000)
commit0267732baeb06ec100c1d610197bb88aae1c5123
tree611c2aafe9c38ce62a4090cc7799136e0a16ad12
parent4ef79c960aa0967cf0298dc496a30a40d86ebd3c
[16/n] PR85694: Add detection of averaging operations

This patch adds detection of average instructions:

       a = (((wide) b + (wide) c) >> 1);
   --> a = (wide) .AVG_FLOOR (b, c);

       a = (((wide) b + (wide) c + 1) >> 1);
   --> a = (wide) .AVG_CEIL (b, c);

in cases where users of "a" need only the low half of the result,
making the cast to (wide) redundant.  The heavy lifting was done by
earlier patches.

This showed up another problem in vectorizable_call: if the call is a
pattern definition statement rather than the main pattern statement,
the type of vectorised call might be different from the type of the
original statement.

2018-07-03  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
PR tree-optimization/85694
* doc/md.texi (avgM3_floor, uavgM3_floor, avgM3_ceil)
(uavgM3_ceil): Document new optabs.
* doc/sourcebuild.texi (vect_avg_qi): Document new target selector.
* internal-fn.def (IFN_AVG_FLOOR, IFN_AVG_CEIL): New internal
functions.
* optabs.def (savg_floor_optab, uavg_floor_optab, savg_ceil_optab)
(savg_ceil_optab): New optabs.
* tree-vect-patterns.c (vect_recog_average_pattern): New function.
(vect_vect_recog_func_ptrs): Add it.
* tree-vect-stmts.c (vectorizable_call): Get the type of the zero
constant directly from the associated lhs.

gcc/testsuite/
PR tree-optimization/85694
* lib/target-supports.exp (check_effective_target_vect_avg_qi): New
proc.
* gcc.dg/vect/vect-avg-1.c: New test.
* gcc.dg/vect/vect-avg-2.c: Likewise.
* gcc.dg/vect/vect-avg-3.c: Likewise.
* gcc.dg/vect/vect-avg-4.c: Likewise.
* gcc.dg/vect/vect-avg-5.c: Likewise.
* gcc.dg/vect/vect-avg-6.c: Likewise.
* gcc.dg/vect/vect-avg-7.c: Likewise.
* gcc.dg/vect/vect-avg-8.c: Likewise.
* gcc.dg/vect/vect-avg-9.c: Likewise.
* gcc.dg/vect/vect-avg-10.c: Likewise.
* gcc.dg/vect/vect-avg-11.c: Likewise.
* gcc.dg/vect/vect-avg-12.c: Likewise.
* gcc.dg/vect/vect-avg-13.c: Likewise.
* gcc.dg/vect/vect-avg-14.c: Likewise.

From-SVN: r262335
23 files changed:
gcc/ChangeLog
gcc/doc/md.texi
gcc/doc/sourcebuild.texi
gcc/internal-fn.def
gcc/optabs.def
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/vect/vect-avg-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-avg-10.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-avg-11.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-avg-12.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-avg-13.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-avg-14.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-avg-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-avg-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-avg-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-avg-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-avg-6.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-avg-7.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-avg-8.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-avg-9.c [new file with mode: 0644]
gcc/testsuite/lib/target-supports.exp
gcc/tree-vect-patterns.c
gcc/tree-vect-stmts.c