]> git.ipfire.org Git - thirdparty/gcc.git/commit
middle-end: lower COND_EXPR into gimple form in vect_recog_bool_pattern
authorTamar Christina <tamar.christina@arm.com>
Sun, 22 Sep 2024 12:38:49 +0000 (13:38 +0100)
committerTamar Christina <tamar.christina@arm.com>
Sun, 22 Sep 2024 12:38:49 +0000 (13:38 +0100)
commit4150bcd205ebb60b949224758c05012c0dfab7a7
treed4022ce44f8a4856faf85f65102a90d7bfc2422b
parente84e5d034124c6733d3b36d8623c56090d4d17f7
middle-end: lower COND_EXPR into gimple form in vect_recog_bool_pattern

Currently the vectorizer cheats when lowering COND_EXPR during bool recog.
In the cases where the conditonal is loop invariant or non-boolean it instead
converts the operation back into GENERIC and hides much of the operation from
the analysis part of the vectorizer.

i.e.

  a ? b : c

is transformed into:

  a != 0 ? b : c

however by doing so we can't perform any optimization on the mask as they aren't
explicit until quite late during codegen.

To fix this this patch lowers booleans earlier and so ensures that we are always
in GIMPLE.

For when the value is a loop invariant boolean we have to generate an additional
conversion from bool to the integer mask form.

This is done by creating a loop invariant a ? -1 : 0 with the target mask
precision and then doing a normal != 0 comparison on that.

To support this the patch also adds the ability to during pattern matching
create a loop invariant pattern that won't be seen by the vectorizer and will
instead me materialized inside the loop preheader in the case of loops, or in
the case of BB vectorization it materializes it in the first BB in the region.

gcc/ChangeLog:

* tree-vect-patterns.cc (append_inv_pattern_def_seq): New.
(vect_recog_bool_pattern): Lower COND_EXPRs.
* tree-vect-slp.cc (vect_slp_region): Materialize loop invariant
statements.
* tree-vect-loop.cc (vect_transform_loop): Likewise.
* tree-vect-stmts.cc (vectorizable_comparison_1): Remove
VECT_SCALAR_BOOLEAN_TYPE_P handling for vectype.
* tree-vectorizer.cc (vec_info::vec_info): Initialize
inv_pattern_def_seq.
* tree-vectorizer.h (LOOP_VINFO_INV_PATTERN_DEF_SEQ): New.
(class vec_info): Add inv_pattern_def_seq.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/bb-slp-conditional_store_1.c: New test.
* gcc.dg/vect/vect-conditional_store_5.c: New test.
* gcc.dg/vect/vect-conditional_store_6.c: New test.
gcc/testsuite/gcc.dg/vect/bb-slp-conditional_store_1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-conditional_store_5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/vect-conditional_store_6.c [new file with mode: 0644]
gcc/tree-vect-loop.cc
gcc/tree-vect-patterns.cc
gcc/tree-vect-slp.cc
gcc/tree-vect-stmts.cc
gcc/tree-vectorizer.cc
gcc/tree-vectorizer.h