https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108314

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
(gdb) p debug_gimple_stmt (stmt)
t_5 = .FOLD_EXTRACT_LAST (t_14, _41, );

there's a missing call argument, the call is built here:

#0  vectorizable_condition (vinfo=0x3b67200, stmt_info=0x3c3d160, 
    gsi=0x7fffffffcad0, vec_stmt=0x7fffffffc8a8, slp_node=0x0, cost_vec=0x0)
    at /home/rguenther/src/trunk/gcc/tree-vect-stmts.cc:10763
10763             new_stmt = gimple_build_call_internal
(gdb) l
10758         gimple *new_stmt;
10759         if (reduction_type == EXTRACT_LAST_REDUCTION)
10760           {
10761             gimple *old_stmt = vect_orig_stmt (stmt_info)->stmt;
10762             tree lhs = gimple_get_lhs (old_stmt);
10763             new_stmt = gimple_build_call_internal
10764                 (IFN_FOLD_EXTRACT_LAST, 3, else_clause, vec_compare,
10765                  vec_then_clause);
10766             gimple_call_set_lhs (new_stmt, lhs);
10767             SSA_NAME_DEF_STMT (lhs) = new_stmt;
(gdb) p vec_then_clause
$13 = <tree 0x0>

which is because we run into

              else if (bitop2 == BIT_NOT_EXPR)
                {
                  /* Instead of doing ~x ? y : z do x ? z : y.  */
                  vec_compare = new_temp;
                  std::swap (vec_then_clause, vec_else_clause);

but vec_else_clause isn't initialized for EXTRACT_LAST_REDUCTION.  Instead
we should swap with else_clause here?

It seems to me I've seen this before ...

Note that if we swap we fail to expand the internal function which seems to
want the scalar/vector args in specific places and _not_ support this
inversion.  So instead avoid doing this optimization.

Reply via email to