Skip to content
Snippets Groups Projects
Commit 4150bcd2 authored by Tamar Christina's avatar Tamar Christina
Browse files

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.
parent e84e5d03
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment