public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: "Kumar, Venkataramanan" <Venkataramanan.Kumar@amd.com>
Cc: "Richard Beiner (richard.guenther@gmail.com)"
	<richard.guenther@gmail.com>,
	       "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [RFC] [Patch]:  Try and vectorize with shift for mult expr with power 2 integer constant.
Date: Tue, 28 Jul 2015 20:24:00 -0000	[thread overview]
Message-ID: <20150728195340.GX1780@tucnak.redhat.com> (raw)
In-Reply-To: <7794A52CE4D579448B959EED7DD0A4723DD1F787@satlexdag06.amd.com>

Hi!

> This is just an initial patch and tries to optimize integer type power 2
> constants.  I wanted to get feedback on this .  I bootstrapped and reg
> tested on aarch64-none-linux-gnu .

Thanks for working on it.
ChangeLog entry for the patch is missing, probably also some testcases.

> @@ -90,6 +94,7 @@ static vect_recog_func_ptr vect_vect_recog_func_ptrs[NUM_PATTERNS] = {
>  	vect_recog_rotate_pattern,
>  	vect_recog_vector_vector_shift_pattern,
>  	vect_recog_divmod_pattern,
> +        vect_recog_multconst_pattern,
>  	vect_recog_mixed_size_cond_pattern,
>  	vect_recog_bool_pattern};

Please watch formatting, the other lines are tab indented, so please use a
tab rather than 8 spaces.

> @@ -2147,6 +2152,87 @@ vect_recog_vector_vector_shift_pattern (vec<gimple> *stmts,
>    return pattern_stmt;
>  }
>  

Function comment is missing here.

> +static gimple
> +vect_recog_multconst_pattern (vec<gimple> *stmts,
> +                           tree *type_in, tree *type_out)

About the function name, wonder if just vect_recog_mult_pattern wouldn't be
enough.

> +  rhs_code = gimple_assign_rhs_code (last_stmt);
> +  switch (rhs_code)
> +    {
> +    case MULT_EXPR:
> +      break;
> +    default:
> +      return NULL;
> +    }

This looks too weird, I'd just do
  if (gimple_assign_rhs_code (last_stmt) != MULT_EXPR)
    return NULL;
(you handle just one pattern).

> +  /* If the target can handle vectorized multiplication natively,
> +     don't attempt to optimize this.  */
> +  optab = optab_for_tree_code (rhs_code, vectype, optab_default);

Supposedly you can use MULT_EXPR directly here.

> +  /* If target cannot handle vector left shift then we cannot 
> +     optimize and bail out.  */ 
> +  optab = optab_for_tree_code (LSHIFT_EXPR, vectype, optab_vector);
> +  if (!optab
> +      || optab_handler (optab, TYPE_MODE (vectype)) == CODE_FOR_nothing)
> +        return NULL;
> +
> +  if (integer_pow2p (oprnd1))
> +    {
> +      /* Pattern detected.  */
> +      if (dump_enabled_p ())
> +	dump_printf_loc (MSG_NOTE, vect_location,
> +			 "vect_recog_multconst_pattern: detected:\n");
> +
> +      tree shift;
> +      shift = build_int_cst (itype, tree_log2 (oprnd1));
> +      pattern_stmt = gimple_build_assign (vect_recog_temp_ssa_var (itype, NULL),
> +					  LSHIFT_EXPR, oprnd0, shift);
> +      if (dump_enabled_p ())
> +	dump_gimple_stmt_loc (MSG_NOTE, vect_location, TDF_SLIM, pattern_stmt,
> +                              0);
> +      stmts->safe_push (last_stmt);
> +      *type_in = vectype;
> +      *type_out = vectype;
> +      return pattern_stmt;
> +    } 

Trailing whitespace.
The integer_pow2p case (have you checked signed multiply by INT_MIN?)
is only one of the cases you can actually handle, you can look at
expand_mult for many other cases - e.g. multiplication by negated powers of
2, or call choose_mult_variant and handle whatever it returns.

	Jakub

WARNING: multiple messages have this Message-ID
From: Jakub Jelinek <jakub@redhat.com>
To: "Kumar, Venkataramanan" <Venkataramanan.Kumar@amd.com>
Cc: "Richard Beiner (richard.guenther@gmail.com)"
	<richard.guenther@gmail.com>,
	       "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [RFC] [Patch]:  Try and vectorize with shift for mult expr with power 2 integer constant.
Date: Tue, 28 Jul 2015 20:34:00 -0000	[thread overview]
Message-ID: <20150728195340.GX1780@tucnak.redhat.com> (raw)
Message-ID: <20150728203400.ePJEaaIFUoS4pIBAyJc-_dCZu8ysOYDpkZSvFPn4LG4@z> (raw)
In-Reply-To: <7794A52CE4D579448B959EED7DD0A4723DD1F787@satlexdag06.amd.com>

Hi!

> This is just an initial patch and tries to optimize integer type power 2
> constants.  I wanted to get feedback on this .  I bootstrapped and reg
> tested on aarch64-none-linux-gnu .

Thanks for working on it.
ChangeLog entry for the patch is missing, probably also some testcases.

> @@ -90,6 +94,7 @@ static vect_recog_func_ptr vect_vect_recog_func_ptrs[NUM_PATTERNS] = {
>  	vect_recog_rotate_pattern,
>  	vect_recog_vector_vector_shift_pattern,
>  	vect_recog_divmod_pattern,
> +        vect_recog_multconst_pattern,
>  	vect_recog_mixed_size_cond_pattern,
>  	vect_recog_bool_pattern};

Please watch formatting, the other lines are tab indented, so please use a
tab rather than 8 spaces.

> @@ -2147,6 +2152,87 @@ vect_recog_vector_vector_shift_pattern (vec<gimple> *stmts,
>    return pattern_stmt;
>  }
>  

Function comment is missing here.

> +static gimple
> +vect_recog_multconst_pattern (vec<gimple> *stmts,
> +                           tree *type_in, tree *type_out)

About the function name, wonder if just vect_recog_mult_pattern wouldn't be
enough.

> +  rhs_code = gimple_assign_rhs_code (last_stmt);
> +  switch (rhs_code)
> +    {
> +    case MULT_EXPR:
> +      break;
> +    default:
> +      return NULL;
> +    }

This looks too weird, I'd just do
  if (gimple_assign_rhs_code (last_stmt) != MULT_EXPR)
    return NULL;
(you handle just one pattern).

> +  /* If the target can handle vectorized multiplication natively,
> +     don't attempt to optimize this.  */
> +  optab = optab_for_tree_code (rhs_code, vectype, optab_default);

Supposedly you can use MULT_EXPR directly here.

> +  /* If target cannot handle vector left shift then we cannot 
> +     optimize and bail out.  */ 
> +  optab = optab_for_tree_code (LSHIFT_EXPR, vectype, optab_vector);
> +  if (!optab
> +      || optab_handler (optab, TYPE_MODE (vectype)) == CODE_FOR_nothing)
> +        return NULL;
> +
> +  if (integer_pow2p (oprnd1))
> +    {
> +      /* Pattern detected.  */
> +      if (dump_enabled_p ())
> +	dump_printf_loc (MSG_NOTE, vect_location,
> +			 "vect_recog_multconst_pattern: detected:\n");
> +
> +      tree shift;
> +      shift = build_int_cst (itype, tree_log2 (oprnd1));
> +      pattern_stmt = gimple_build_assign (vect_recog_temp_ssa_var (itype, NULL),
> +					  LSHIFT_EXPR, oprnd0, shift);
> +      if (dump_enabled_p ())
> +	dump_gimple_stmt_loc (MSG_NOTE, vect_location, TDF_SLIM, pattern_stmt,
> +                              0);
> +      stmts->safe_push (last_stmt);
> +      *type_in = vectype;
> +      *type_out = vectype;
> +      return pattern_stmt;
> +    } 

Trailing whitespace.
The integer_pow2p case (have you checked signed multiply by INT_MIN?)
is only one of the cases you can actually handle, you can look at
expand_mult for many other cases - e.g. multiplication by negated powers of
2, or call choose_mult_variant and handle whatever it returns.

	Jakub

  reply	other threads:[~2015-07-28 20:01 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-28 15:30 Kumar, Venkataramanan
2015-07-28 20:24 ` Jakub Jelinek [this message]
2015-07-28 20:34   ` Jakub Jelinek
2015-08-02 11:03   ` Kumar, Venkataramanan
2015-08-03 18:11     ` Jeff Law
2015-08-04  8:52       ` Kumar, Venkataramanan
2015-08-04 10:37         ` Richard Biener
     [not found]           ` <87vbcvjg1y.fsf@e105548-lin.cambridge.arm.com>
     [not found]             ` <CAFiYyc3VLXyjmfCuizFVsQ2nLDjyd_Dr=Po1_qyJ9wcrgCmiWA@mail.gmail.com>
2015-08-04 14:22               ` Richard Biener
2015-08-04 14:28                 ` Richard Sandiford
2015-08-04 16:07                   ` Richard Biener
2015-08-04 16:27                     ` Richard Sandiford
2015-08-04 16:49           ` Kumar, Venkataramanan
2015-08-05  8:51             ` Richard Biener
2015-08-05  9:34               ` Kumar, Venkataramanan
2015-08-05 11:41             ` Richard Biener
2015-08-06 12:04               ` Kumar, Venkataramanan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150728195340.GX1780@tucnak.redhat.com \
    --to=jakub@redhat.com \
    --cc=Venkataramanan.Kumar@amd.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).