]> git.ipfire.org Git - thirdparty/gcc.git/commit
middle-end: Support not decomposing specific divisions during vectorization.
authorTamar Christina <tamar.christina@arm.com>
Mon, 14 Nov 2022 15:43:48 +0000 (15:43 +0000)
committerTamar Christina <tamar.christina@arm.com>
Mon, 14 Nov 2022 17:41:32 +0000 (17:41 +0000)
commit8beff04a325ba3c3707d8a6dd954ec881193d655
tree5500b57540f9a13b22f7dae5a4e9db85349049c0
parentb2bb611d90d01f64a2456c29de2a2ca1211ac134
middle-end: Support not decomposing specific divisions during vectorization.

In plenty of image and video processing code it's common to modify pixel values
by a widening operation and then scale them back into range by dividing by 255.

e.g.:

   x = y / (2 ^ (bitsize (y)/2)-1

This patch adds a new target hook can_special_div_by_const, similar to
can_vec_perm which can be called to check if a target will handle a particular
division in a special way in the back-end.

The vectorizer will then vectorize the division using the standard tree code
and at expansion time the hook is called again to generate the code for the
division.

Alot of the changes in the patch are to pass down the tree operands in all paths
that can lead to the divmod expansion so that the target hook always has the
type of the expression you're expanding since the types can change the
expansion.

gcc/ChangeLog:

* expmed.h (expand_divmod): Pass tree operands down in addition to RTX.
* expmed.cc (expand_divmod): Likewise.
* explow.cc (round_push, align_dynamic_address): Likewise.
* expr.cc (force_operand, expand_expr_divmod): Likewise.
* optabs.cc (expand_doubleword_mod, expand_doubleword_divmod):
Likewise.
* target.h: Include tree-core.
* target.def (can_special_div_by_const): New.
* targhooks.cc (default_can_special_div_by_const): New.
* targhooks.h (default_can_special_div_by_const): New.
* tree-vect-generic.cc (expand_vector_operation): Use it.
* doc/tm.texi.in: Document it.
* doc/tm.texi: Regenerate.
* tree-vect-patterns.cc (vect_recog_divmod_pattern): Check for support.
* tree-vect-stmts.cc (vectorizable_operation): Likewise.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/vect-div-bitmask-1.c: New test.
* gcc.dg/vect/vect-div-bitmask-2.c: New test.
* gcc.dg/vect/vect-div-bitmask-3.c: New test.
* gcc.dg/vect/vect-div-bitmask.h: New file.
18 files changed:
gcc/doc/tm.texi
gcc/doc/tm.texi.in
gcc/explow.cc
gcc/expmed.cc
gcc/expmed.h
gcc/expr.cc
gcc/optabs.cc
gcc/target.def
gcc/target.h
gcc/targhooks.cc
gcc/targhooks.h
gcc/testsuite/gcc.dg/vect/vect-div-bitmask-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-div-bitmask-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-div-bitmask-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-div-bitmask.h [new file with mode: 0644]
gcc/tree-vect-generic.cc
gcc/tree-vect-patterns.cc
gcc/tree-vect-stmts.cc