From d43a252e2fa612b14fa7f6f4dec3320c8b313a1c Mon Sep 17 00:00:00 2001 From: Alan Lawrence Date: Mon, 27 Oct 2014 14:20:52 +0000 Subject: Add new optabs for reducing vectors to scalars PR tree-optimization/61114 * doc/md.texi (Standard Names): Add reduc_(plus,[us](min|max))|scal optabs, and note in reduc_[us](plus|min|max) to prefer the former. * expr.c (expand_expr_real_2): Use reduc_..._scal if available, fall back to old reduc_... + BIT_FIELD_REF only if not. * optabs.c (optab_for_tree_code): for REDUC_(MAX,MIN,PLUS)_EXPR, return the reduce-to-scalar (reduc_..._scal) optab. (scalar_reduc_to_vector): New. * optabs.def (reduc_smax_scal_optab, reduc_smin_scal_optab, reduc_plus_scal_optab, reduc_umax_scal_optab, reduc_umin_scal_optab): New. * optabs.h (scalar_reduc_to_vector): Declare. * tree-vect-loop.c (vectorizable_reduction): Look for optabs reducing to either scalar or vector. From-SVN: r216737 --- gcc/expr.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'gcc/expr.c') diff --git a/gcc/expr.c b/gcc/expr.c index e9cabbe..a5bf13a 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -9052,6 +9052,24 @@ expand_expr_real_2 (sepops ops, rtx target, enum machine_mode tmode, op0 = expand_normal (treeop0); this_optab = optab_for_tree_code (code, type, optab_default); enum machine_mode vec_mode = TYPE_MODE (TREE_TYPE (treeop0)); + + if (optab_handler (this_optab, vec_mode) != CODE_FOR_nothing) + { + struct expand_operand ops[2]; + enum insn_code icode = optab_handler (this_optab, vec_mode); + + create_output_operand (&ops[0], target, mode); + create_input_operand (&ops[1], op0, vec_mode); + if (maybe_expand_insn (icode, 2, ops)) + { + target = ops[0].value; + if (GET_MODE (target) != mode) + return gen_lowpart (tmode, target); + return target; + } + } + /* Fall back to optab with vector result, and then extract scalar. */ + this_optab = scalar_reduc_to_vector (this_optab, type); temp = expand_unop (vec_mode, this_optab, op0, NULL_RTX, unsignedp); gcc_assert (temp); /* The tree code produces a scalar result, but (somewhat by convention) -- cgit v1.1