This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Vector shuffling


On Fri, Sep 30, 2011 at 7:18 PM, Richard Henderson <rth@redhat.com> wrote:
>> I hope that the new version looks a little bit better.
>
> Nearly ok. ?Some trivial fixes, and then please commit.
>
>> + ?rtx_v0 = expand_normal (v0);
>> + ?rtx_mask = expand_normal (mask);
>> +
>> + ?create_output_operand (&ops[0], target, mode);
>> + ?create_input_operand (&ops[3], rtx_mask, mode);
>> +
>> + ?if (operand_equal_p (v0, v1, 0))
>> + ? ?{
>> + ? ? ?rtx_v0 = expand_normal (v0);
>> + ? ? ?if (!insn_operand_matches(icode, 1, rtx_v0))
>> + ? ? ? ?rtx_v0 = force_reg (mode, rtx_v0);
>> +
>> + ? ? ?gcc_checking_assert(insn_operand_matches(icode, 2, rtx_v0));
>> +
>> + ? ? ?create_fixed_operand (&ops[1], rtx_v0);
>> + ? ? ?create_fixed_operand (&ops[2], rtx_v0);
>> + ? ?}
>> + ?else
>> + ? ?{
>> + ? ? ?create_input_operand (&ops[1], expand_normal (v0), mode);
>> + ? ? ?create_input_operand (&ops[2], expand_normal (v1), mode);
>> + ? ?}
>
> The first line should be removed. ?Otherwise you're expanding v0 twice.
>
>> +(define_expand "vshuffle<mode>"
>> + ?[(match_operand:V_128 0 "register_operand" "")
>> + ? (match_operand:V_128 1 "general_operand" "")
>> + ? (match_operand:V_128 2 "general_operand" "")
>> + ? (match_operand:<sseshuffint> 3 "general_operand" "")]
>> + ?"TARGET_SSSE3 || TARGET_AVX"
>> +{
>> + ?bool ok = ix86_expand_vshuffle (operands);
>> + ?gcc_assert (ok);
>> + ?DONE;
>> +})
>
> Operands 1, 2, and 3 should use register_operand. ?That will avoid...
>
>> + ?op0 = force_reg (mode, op0);
>> + ?op1 = force_reg (mode, op0);
>> + ?mask = force_reg (maskmode, mask);
>
> ... these lines in ix86_expand_vshuffle and the obvious typo for op1.
>
>> + ? ? ?fprintf (stderr, "-- here in %s \n", __func__);
>
> Remove the debugging lines.
>
>
> r~
>

Ok, in the attachment there is a patch which fixes mentioned errors.

ChangeLog:

	gcc/
	* optabs.c (expand_vec_shuffle_expr_p): New function. Checks
	if given expression can be expanded by the target.
	(expand_vec_shuffle_expr): New function. Expand VEC_SHUFFLE_EXPR
	using target vector instructions.
	* optabs.h: New optab vshuffle.
	(expand_vec_shuffle_expr_p): New prototype.
	(expand_vec_shuffle_expr): New prototype.
	(vshuffle_optab): New optab.
	* genopinit.c: Adjust to support vecshuffle.
	* c-tree.h (c_build_vec_shuffle_expr): New prototype.
	* expr.c (expand_expr_real_2): Adjust.
	* c-typeck.c: (c_build_vec_shuffle_expr): Build a VEC_SHUFFLE_EXPR
	recognizing the cases of two and three arguments.
	(convert_arguments) (build_binary_op)
	(scalar_to_vector) (build_array_ref): Spurious whitespace.
	* gimplify.c (gimplify_exp): Adjusted to support VEC_SHUFFLE_EXPR.
	* tree.def: New tree code VEC_SHUFFLE_EXPR.
	* tree-inline.c (estimate_operator_cost): Recognize VEC_SHUFFLE_EXPR.
	* tree-vect-generic.c (vector_element): New function. Returns an
	element of the vector at the given position.
	(lower_vec_shuffle): Checks if VEC_SHUFLLE_EXPR is supported
	by the backend or expand an expression piecewise.
	(expand_vector_operations_1): Adjusted.
	(gate_expand_vector_operations_noop): New gate function.
	* Makefile.in (tree-vect-generic.o): New include.
	* gimple.c (get_gimple_rhs_num_ops): Adjust.
	* tree-cfg.c (verify_gimple_assign_trenary): Verify VEC_SHUFFLE_EXPR.
	* passes.c: Move veclower down.
	* tree-pretty-print.c (dump_generic_node): Recognize
	VEC_SHUFFLE_EXPR as valid expression.
	* c-parser.c (c_parser_get_builtin_args): Helper function for the
	builtins with variable number of arguments.
	(c_parser_postfix_expression): Use a new helper function for
	RID_CHOOSE_EXPR, RID_BUILTIN_COMPLEX and RID_BUILTIN_SHUFFLE.
	* tree-ssa-operands: Adjust.
	
	c-family/
	* c-common.c: New __builtin_shuffle keyword.
	* c-common.h: New __builtin_shuffle keyword.

	gcc/config/i386
	* sse.md: (sseshuffint) New mode_attr. Correspondence between the
	vector and the type of the mask when shuffling.
	(vecshuffle<mode>): New expansion.
	* i386-protos.h (ix86_expand_vshuffle): New prototype.
	* i386.c (ix86_expand_vshuffle): Expand vshuffle using pshufb.
	(ix86_vectorize_builtin_vec_perm_ok): Adjust.

	gcc/doc
	* extend.texi: Adjust.

	gcc/testsuite
	* gcc.c-torture/execute/vect-shuffle-2.c: New test.
	* gcc.c-torture/execute/vect-shuffle-4.c: New test.
	* gcc.c-torture/execute/vect-shuffle-1.c: New test.
	* gcc.dg/builtin-complex-err-1.c: Adjust.

bootstrapped and tested on x86_64-unknown-linux-gnu.

Unfortunately I don't have permissions to commit to the trunk.


Thanks,
Artem.

Attachment: vec-shuffle.v19.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]