This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: RFC: Add ADDR_EXPR lowering (PR tree-optimization/66718)
- From: Richard Biener <rguenther at suse dot de>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Marek Polacek <polacek at redhat dot com>,GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 03 Jul 2015 19:13:38 +0200
- Subject: Re: RFC: Add ADDR_EXPR lowering (PR tree-optimization/66718)
- Authentication-results: sourceware.org; auth=none
- References: <20150703132147 dot GD10139 at redhat dot com> <alpine dot LSU dot 2 dot 11 dot 1507031536070 dot 9923 at zhemvz dot fhfr dot qr> <20150703140626 dot GN10247 at tucnak dot redhat dot com>
On July 3, 2015 4:06:26 PM GMT+02:00, Jakub Jelinek <jakub@redhat.com> wrote:
>On Fri, Jul 03, 2015 at 03:41:29PM +0200, Richard Biener wrote:
>> > The fallout (at least on x86_64) is surprisingly small, i.e. none,
>just
>> > gcc.dg/vect/pr59984.c test (using -fopenmp-simd) ICEs, but that is
>due
>> > to a bug in the vectorizer. Jakub has a patch and knows the
>details.
>> > As the test shows, we're now able to vectorize ADDR_EXPR of
>non-invariants
>> > (that was the motivation of this pass).
>
>Here is the fix for that.
>
>The problem is that for simd clone calls, if they have void return
>type,
>STMT_VINFO_VECTYPE is NULL. If vectorize_simd_clone_call succeeds,
>that is fine, but if it doesn't, we can fall into all the other
>vectorizable_* functions, and some of them compute some variables
>IMHO prematurely. It doesn't make sense to compute nunits/ncopies
>etc. if stmt isn't even an assignment etc.
>So, this patch adjusts the few routines that had this problem,
>so that we check is_gimple_assign and gimple_assign_rhs_code or
>whatever
>is the quick GIMPLE test those functions use to find if stmt is of
>interest
>to them, and only when it is, compute whatever they need later.
>As NULL STMT_VINFO_VECTYPE can happen only for calls, all these
>functions
>don't ICE anymore.
>
>Ok for trunk if it passes bootstrap/regtest?
OK.
Thanks,
Richard.
>In the pr59984.c testcase, with Marek's patch and this patch, one loop
>in
>test is already vectorized (the ICE was on the other one), I'll work on
>recognizing multiples of GOMP_SIMD_LANE () as linear next, so that we
>vectorize also the loop with bar. Without Marek's patch we weren't
>vectorizing any of the two loops.
>
>2015-07-03 Jakub Jelinek <jakub@redhat.com>
>
> PR tree-optimization/66718
> * tree-vect-stmts.c (vectorizable_assignment, vectorizable_store,
> vectorizable_load, vectorizable_condition): Move vectype,
> nunits, ncopies computation after checking what kind of statement
> stmt is.
>
>--- gcc/tree-vect-stmts.c.jj 2015-06-30 14:08:45.000000000 +0200
>+++ gcc/tree-vect-stmts.c 2015-07-03 14:06:28.843573210 +0200
>@@ -4043,13 +4043,11 @@ vectorizable_assignment (gimple stmt, gi
> tree scalar_dest;
> tree op;
> stmt_vec_info stmt_info = vinfo_for_stmt (stmt);
>- tree vectype = STMT_VINFO_VECTYPE (stmt_info);
> loop_vec_info loop_vinfo = STMT_VINFO_LOOP_VINFO (stmt_info);
> tree new_temp;
> tree def;
> gimple def_stmt;
>enum vect_def_type dt[2] = {vect_unknown_def_type,
>vect_unknown_def_type};
>- unsigned int nunits = TYPE_VECTOR_SUBPARTS (vectype);
> int ncopies;
> int i, j;
> vec<tree> vec_oprnds = vNULL;
>@@ -4060,16 +4058,6 @@ vectorizable_assignment (gimple stmt, gi
> enum tree_code code;
> tree vectype_in;
>
>- /* Multiple types in SLP are handled by creating the appropriate
>number of
>- vectorized stmts for each SLP node. Hence, NCOPIES is always 1 in
>- case of SLP. */
>- if (slp_node || PURE_SLP_STMT (stmt_info))
>- ncopies = 1;
>- else
>- ncopies = LOOP_VINFO_VECT_FACTOR (loop_vinfo) / nunits;
>-
>- gcc_assert (ncopies >= 1);
>-
> if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
> return false;
>
>@@ -4095,6 +4083,19 @@ vectorizable_assignment (gimple stmt, gi
> if (code == VIEW_CONVERT_EXPR)
> op = TREE_OPERAND (op, 0);
>
>+ tree vectype = STMT_VINFO_VECTYPE (stmt_info);
>+ unsigned int nunits = TYPE_VECTOR_SUBPARTS (vectype);
>+
>+ /* Multiple types in SLP are handled by creating the appropriate
>number of
>+ vectorized stmts for each SLP node. Hence, NCOPIES is always 1 in
>+ case of SLP. */
>+ if (slp_node || PURE_SLP_STMT (stmt_info))
>+ ncopies = 1;
>+ else
>+ ncopies = LOOP_VINFO_VECT_FACTOR (loop_vinfo) / nunits;
>+
>+ gcc_assert (ncopies >= 1);
>+
> if (!vect_is_simple_use_1 (op, stmt, loop_vinfo, bb_vinfo,
> &def_stmt, &def, &dt[0], &vectype_in))
> {
>@@ -5006,7 +5007,6 @@ vectorizable_store (gimple stmt, gimple_
> tree vec_oprnd = NULL_TREE;
> stmt_vec_info stmt_info = vinfo_for_stmt (stmt);
>struct data_reference *dr = STMT_VINFO_DATA_REF (stmt_info), *first_dr
>= NULL;
>- tree vectype = STMT_VINFO_VECTYPE (stmt_info);
> tree elem_type;
> loop_vec_info loop_vinfo = STMT_VINFO_LOOP_VINFO (stmt_info);
> struct loop *loop = NULL;
>@@ -5020,7 +5020,6 @@ vectorizable_store (gimple stmt, gimple_
> tree dataref_ptr = NULL_TREE;
> tree dataref_offset = NULL_TREE;
> gimple ptr_incr = NULL;
>- unsigned int nunits = TYPE_VECTOR_SUBPARTS (vectype);
> int ncopies;
> int j;
> gimple next_stmt, first_stmt = NULL;
>@@ -5039,28 +5038,6 @@ vectorizable_store (gimple stmt, gimple_
> bb_vec_info bb_vinfo = STMT_VINFO_BB_VINFO (stmt_info);
> tree aggr_type;
>
>- if (loop_vinfo)
>- loop = LOOP_VINFO_LOOP (loop_vinfo);
>-
>- /* Multiple types in SLP are handled by creating the appropriate
>number of
>- vectorized stmts for each SLP node. Hence, NCOPIES is always 1 in
>- case of SLP. */
>- if (slp || PURE_SLP_STMT (stmt_info))
>- ncopies = 1;
>- else
>- ncopies = LOOP_VINFO_VECT_FACTOR (loop_vinfo) / nunits;
>-
>- gcc_assert (ncopies >= 1);
>-
>- /* FORNOW. This restriction should be relaxed. */
>- if (loop && nested_in_vect_loop_p (loop, stmt) && ncopies > 1)
>- {
>- if (dump_enabled_p ())
>- dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
>- "multiple types in nested loop.\n");
>- return false;
>- }
>-
> if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
> return false;
>
>@@ -5086,6 +5063,32 @@ vectorizable_store (gimple stmt, gimple_
> return false;
>
> gcc_assert (gimple_assign_single_p (stmt));
>+
>+ tree vectype = STMT_VINFO_VECTYPE (stmt_info);
>+ unsigned int nunits = TYPE_VECTOR_SUBPARTS (vectype);
>+
>+ if (loop_vinfo)
>+ loop = LOOP_VINFO_LOOP (loop_vinfo);
>+
>+ /* Multiple types in SLP are handled by creating the appropriate
>number of
>+ vectorized stmts for each SLP node. Hence, NCOPIES is always 1 in
>+ case of SLP. */
>+ if (slp || PURE_SLP_STMT (stmt_info))
>+ ncopies = 1;
>+ else
>+ ncopies = LOOP_VINFO_VECT_FACTOR (loop_vinfo) / nunits;
>+
>+ gcc_assert (ncopies >= 1);
>+
>+ /* FORNOW. This restriction should be relaxed. */
>+ if (loop && nested_in_vect_loop_p (loop, stmt) && ncopies > 1)
>+ {
>+ if (dump_enabled_p ())
>+ dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
>+ "multiple types in nested loop.\n");
>+ return false;
>+ }
>+
> op = gimple_assign_rhs1 (stmt);
> if (!vect_is_simple_use (op, stmt, loop_vinfo, bb_vinfo, &def_stmt,
> &def, &dt))
>@@ -5834,7 +5837,6 @@ vectorizable_load (gimple stmt, gimple_s
> struct loop *containing_loop = (gimple_bb (stmt))->loop_father;
> bool nested_in_vect_loop = false;
>struct data_reference *dr = STMT_VINFO_DATA_REF (stmt_info), *first_dr
>= NULL;
>- tree vectype = STMT_VINFO_VECTYPE (stmt_info);
> tree elem_type;
> tree new_temp;
> machine_mode mode;
>@@ -5844,7 +5846,6 @@ vectorizable_load (gimple stmt, gimple_s
> tree dataref_ptr = NULL_TREE;
> tree dataref_offset = NULL_TREE;
> gimple ptr_incr = NULL;
>- int nunits = TYPE_VECTOR_SUBPARTS (vectype);
> int ncopies;
> int i, j, group_size = -1, group_gap_adj;
> tree msq = NULL_TREE, lsq;
>@@ -5872,6 +5873,37 @@ vectorizable_load (gimple stmt, gimple_s
> int gather_scale = 1;
> enum vect_def_type gather_dt = vect_unknown_def_type;
>
>+ if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
>+ return false;
>+
>+ if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def)
>+ return false;
>+
>+ /* Is vectorizable load? */
>+ if (!is_gimple_assign (stmt))
>+ return false;
>+
>+ scalar_dest = gimple_assign_lhs (stmt);
>+ if (TREE_CODE (scalar_dest) != SSA_NAME)
>+ return false;
>+
>+ code = gimple_assign_rhs_code (stmt);
>+ if (code != ARRAY_REF
>+ && code != BIT_FIELD_REF
>+ && code != INDIRECT_REF
>+ && code != COMPONENT_REF
>+ && code != IMAGPART_EXPR
>+ && code != REALPART_EXPR
>+ && code != MEM_REF
>+ && TREE_CODE_CLASS (code) != tcc_declaration)
>+ return false;
>+
>+ if (!STMT_VINFO_DATA_REF (stmt_info))
>+ return false;
>+
>+ tree vectype = STMT_VINFO_VECTYPE (stmt_info);
>+ int nunits = TYPE_VECTOR_SUBPARTS (vectype);
>+
> if (loop_vinfo)
> {
> loop = LOOP_VINFO_LOOP (loop_vinfo);
>@@ -5914,34 +5946,6 @@ vectorizable_load (gimple stmt, gimple_s
> return false;
> }
>
>- if (!STMT_VINFO_RELEVANT_P (stmt_info) && !bb_vinfo)
>- return false;
>-
>- if (STMT_VINFO_DEF_TYPE (stmt_info) != vect_internal_def)
>- return false;
>-
>- /* Is vectorizable load? */
>- if (!is_gimple_assign (stmt))
>- return false;
>-
>- scalar_dest = gimple_assign_lhs (stmt);
>- if (TREE_CODE (scalar_dest) != SSA_NAME)
>- return false;
>-
>- code = gimple_assign_rhs_code (stmt);
>- if (code != ARRAY_REF
>- && code != BIT_FIELD_REF
>- && code != INDIRECT_REF
>- && code != COMPONENT_REF
>- && code != IMAGPART_EXPR
>- && code != REALPART_EXPR
>- && code != MEM_REF
>- && TREE_CODE_CLASS (code) != tcc_declaration)
>- return false;
>-
>- if (!STMT_VINFO_DATA_REF (stmt_info))
>- return false;
>-
> elem_type = TREE_TYPE (vectype);
> mode = TYPE_MODE (vectype);
>
>@@ -7021,7 +7025,6 @@ vectorizable_condition (gimple stmt, gim
> tree vec_dest = NULL_TREE;
> tree cond_expr, then_clause, else_clause;
> stmt_vec_info stmt_info = vinfo_for_stmt (stmt);
>- tree vectype = STMT_VINFO_VECTYPE (stmt_info);
> tree comp_vectype = NULL_TREE;
> tree vec_cond_lhs = NULL_TREE, vec_cond_rhs = NULL_TREE;
> tree vec_then_clause = NULL_TREE, vec_else_clause = NULL_TREE;
>@@ -7030,7 +7033,6 @@ vectorizable_condition (gimple stmt, gim
> loop_vec_info loop_vinfo = STMT_VINFO_LOOP_VINFO (stmt_info);
> tree def;
> enum vect_def_type dt, dts[4];
>- int nunits = TYPE_VECTOR_SUBPARTS (vectype);
> int ncopies;
> enum tree_code code;
> stmt_vec_info prev_stmt_info = NULL;
>@@ -7042,15 +7044,6 @@ vectorizable_condition (gimple stmt, gim
> vec<tree> vec_oprnds3 = vNULL;
> tree vec_cmp_type;
>
>- if (slp_node || PURE_SLP_STMT (stmt_info))
>- ncopies = 1;
>- else
>- ncopies = LOOP_VINFO_VECT_FACTOR (loop_vinfo) / nunits;
>-
>- gcc_assert (ncopies >= 1);
>- if (reduc_index && ncopies > 1)
>- return false; /* FORNOW */
>-
> if (reduc_index && STMT_SLP_TYPE (stmt_info))
> return false;
>
>@@ -7080,6 +7073,18 @@ vectorizable_condition (gimple stmt, gim
> if (code != COND_EXPR)
> return false;
>
>+ tree vectype = STMT_VINFO_VECTYPE (stmt_info);
>+ int nunits = TYPE_VECTOR_SUBPARTS (vectype);
>+
>+ if (slp_node || PURE_SLP_STMT (stmt_info))
>+ ncopies = 1;
>+ else
>+ ncopies = LOOP_VINFO_VECT_FACTOR (loop_vinfo) / nunits;
>+
>+ gcc_assert (ncopies >= 1);
>+ if (reduc_index && ncopies > 1)
>+ return false; /* FORNOW */
>+
> cond_expr = gimple_assign_rhs1 (stmt);
> then_clause = gimple_assign_rhs2 (stmt);
> else_clause = gimple_assign_rhs3 (stmt);
>
>
> Jakub