aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vect-patterns.c
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2018-07-03 10:03:17 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2018-07-03 10:03:17 +0000
commit4ef79c960aa0967cf0298dc496a30a40d86ebd3c (patch)
tree0ae63c6c6dc83b6cd7647a38c2a0757969ef2439 /gcc/tree-vect-patterns.c
parent370c2ebe8fa20e0812cd2d533d4ed38ee2d37c85 (diff)
downloadgcc-4ef79c960aa0967cf0298dc496a30a40d86ebd3c.zip
gcc-4ef79c960aa0967cf0298dc496a30a40d86ebd3c.tar.gz
gcc-4ef79c960aa0967cf0298dc496a30a40d86ebd3c.tar.bz2
[15/n] PR85694: Try to split existing casts in widened patterns
The main over-widening patch can introduce quite a few extra casts, and in many cases those casts simply "tap into" an intermediate point in an existing extension. E.g. if we have: unsigned char a; int ax = (int) a; and a later operation using ax is shortened to "unsigned short", we would need: unsigned short ax' = (unsigned short) a; The a->ax extension requires one set of unpacks to get to unsigned short and another set of unpacks to get to int. The first set are then duplicated for ax'. If both ax and ax' are needed, the a->ax' extension would end up counting twice during cost calculations. This patch rewrites the original: int ax = (int) a; into a pattern: unsigned short ax' = (unsigned short) a; int ax = (int) ax'; so that each extension only counts once. 2018-07-03 Richard Sandiford <richard.sandiford@arm.com> gcc/ * tree-vect-patterns.c (vect_split_statement): New function. (vect_convert_input): Use it to try to split an existing cast. gcc/testsuite/ * gcc.dg/vect/vect-over-widen-5.c: Test that the extensions get split into two for use by the over-widening pattern. * gcc.dg/vect/vect-over-widen-6.c: Likewise. * gcc.dg/vect/vect-over-widen-7.c: Likewise. * gcc.dg/vect/vect-over-widen-8.c: Likewise. * gcc.dg/vect/vect-over-widen-9.c: Likewise. * gcc.dg/vect/vect-over-widen-10.c: Likewise. * gcc.dg/vect/vect-over-widen-11.c: Likewise. * gcc.dg/vect/vect-over-widen-12.c: Likewise. * gcc.dg/vect/vect-over-widen-13.c: Likewise. * gcc.dg/vect/vect-over-widen-14.c: Likewise. * gcc.dg/vect/vect-over-widen-15.c: Likewise. * gcc.dg/vect/vect-over-widen-16.c: Likewise. * gcc.dg/vect/vect-over-widen-22.c: New test. From-SVN: r262334
Diffstat (limited to 'gcc/tree-vect-patterns.c')
-rw-r--r--gcc/tree-vect-patterns.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/gcc/tree-vect-patterns.c b/gcc/tree-vect-patterns.c
index 91076f4..a1649d8 100644
--- a/gcc/tree-vect-patterns.c
+++ b/gcc/tree-vect-patterns.c
@@ -634,6 +634,97 @@ vect_recog_temp_ssa_var (tree type, gimple *stmt)
return make_temp_ssa_name (type, stmt, "patt");
}
+/* STMT2_INFO describes a type conversion that could be split into STMT1
+ followed by a version of STMT2_INFO that takes NEW_RHS as its first
+ input. Try to do this using pattern statements, returning true on
+ success. */
+
+static bool
+vect_split_statement (stmt_vec_info stmt2_info, tree new_rhs,
+ gimple *stmt1, tree vectype)
+{
+ if (is_pattern_stmt_p (stmt2_info))
+ {
+ /* STMT2_INFO is part of a pattern. Get the statement to which
+ the pattern is attached. */
+ stmt_vec_info orig_stmt2_info
+ = vinfo_for_stmt (STMT_VINFO_RELATED_STMT (stmt2_info));
+ vect_init_pattern_stmt (stmt1, orig_stmt2_info, vectype);
+
+ if (dump_enabled_p ())
+ {
+ dump_printf_loc (MSG_NOTE, vect_location,
+ "Splitting pattern statement: ");
+ dump_gimple_stmt (MSG_NOTE, TDF_SLIM, stmt2_info->stmt, 0);
+ }
+
+ /* Since STMT2_INFO is a pattern statement, we can change it
+ in-situ without worrying about changing the code for the
+ containing block. */
+ gimple_assign_set_rhs1 (stmt2_info->stmt, new_rhs);
+
+ if (dump_enabled_p ())
+ {
+ dump_printf_loc (MSG_NOTE, vect_location, "into: ");
+ dump_gimple_stmt (MSG_NOTE, TDF_SLIM, stmt1, 0);
+ dump_printf_loc (MSG_NOTE, vect_location, "and: ");
+ dump_gimple_stmt (MSG_NOTE, TDF_SLIM, stmt2_info->stmt, 0);
+ }
+
+ gimple_seq *def_seq = &STMT_VINFO_PATTERN_DEF_SEQ (orig_stmt2_info);
+ if (STMT_VINFO_RELATED_STMT (orig_stmt2_info) == stmt2_info->stmt)
+ /* STMT2_INFO is the actual pattern statement. Add STMT1
+ to the end of the definition sequence. */
+ gimple_seq_add_stmt_without_update (def_seq, stmt1);
+ else
+ {
+ /* STMT2_INFO belongs to the definition sequence. Insert STMT1
+ before it. */
+ gimple_stmt_iterator gsi = gsi_for_stmt (stmt2_info->stmt, def_seq);
+ gsi_insert_before_without_update (&gsi, stmt1, GSI_SAME_STMT);
+ }
+ return true;
+ }
+ else
+ {
+ /* STMT2_INFO doesn't yet have a pattern. Try to create a
+ two-statement pattern now. */
+ gcc_assert (!STMT_VINFO_RELATED_STMT (stmt2_info));
+ tree lhs_type = TREE_TYPE (gimple_get_lhs (stmt2_info->stmt));
+ tree lhs_vectype = get_vectype_for_scalar_type (lhs_type);
+ if (!lhs_vectype)
+ return false;
+
+ if (dump_enabled_p ())
+ {
+ dump_printf_loc (MSG_NOTE, vect_location,
+ "Splitting statement: ");
+ dump_gimple_stmt (MSG_NOTE, TDF_SLIM, stmt2_info->stmt, 0);
+ }
+
+ /* Add STMT1 as a singleton pattern definition sequence. */
+ gimple_seq *def_seq = &STMT_VINFO_PATTERN_DEF_SEQ (stmt2_info);
+ vect_init_pattern_stmt (stmt1, stmt2_info, vectype);
+ gimple_seq_add_stmt_without_update (def_seq, stmt1);
+
+ /* Build the second of the two pattern statements. */
+ tree new_lhs = vect_recog_temp_ssa_var (lhs_type, NULL);
+ gassign *new_stmt2 = gimple_build_assign (new_lhs, NOP_EXPR, new_rhs);
+ vect_set_pattern_stmt (new_stmt2, stmt2_info, lhs_vectype);
+
+ if (dump_enabled_p ())
+ {
+ dump_printf_loc (MSG_NOTE, vect_location,
+ "into pattern statements: ");
+ dump_gimple_stmt (MSG_NOTE, TDF_SLIM, stmt1, 0);
+ dump_printf_loc (MSG_NOTE, vect_location, "and: ");
+ dump_gimple_stmt (MSG_NOTE, TDF_SLIM, new_stmt2, 0);
+ }
+
+ return true;
+ }
+}
+
/* Convert UNPROM to TYPE and return the result, adding new statements
to STMT_INFO's pattern definition statements if no better way is
available. VECTYPE is the vector form of TYPE. */
@@ -662,6 +753,18 @@ vect_convert_input (stmt_vec_info stmt_info, tree type,
tree new_op = vect_recog_temp_ssa_var (type, NULL);
gassign *new_stmt = gimple_build_assign (new_op, NOP_EXPR, unprom->op);
+ /* If the operation is the input to a vectorizable cast, try splitting
+ that cast into two, taking the required result as a mid-way point. */
+ if (unprom->caster)
+ {
+ tree lhs = gimple_get_lhs (unprom->caster->stmt);
+ if (TYPE_PRECISION (TREE_TYPE (lhs)) > TYPE_PRECISION (type)
+ && TYPE_PRECISION (type) > TYPE_PRECISION (unprom->type)
+ && (TYPE_UNSIGNED (unprom->type) || !TYPE_UNSIGNED (type))
+ && vect_split_statement (unprom->caster, new_op, new_stmt, vectype))
+ return new_op;
+ }
+
/* If OP is an external value, see if we can insert the new statement
on an incoming edge. */
if (unprom->dt == vect_external_def)