public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Stubbs <ams@codesourcery.com>
To: Richard Guenther <richard.guenther@gmail.com>
Cc: Michael Matz <matz@suse.de>,
	gcc-patches@gcc.gnu.org,  patches@linaro.org
Subject: Re: [PATCH (3/7)] Widening multiply-and-accumulate pattern matching
Date: Thu, 07 Jul 2011 10:27:00 -0000	[thread overview]
Message-ID: <4E1589D8.2060108@codesourcery.com> (raw)
In-Reply-To: <CAFiYyc3WczNWC19j-dWWRtDdOk=9E7vRtqidDpv8BW3V=W1Fpw@mail.gmail.com>

On 07/07/11 10:58, Richard Guenther wrote:
> I think you should assume that series of widenings, (int)(short)char_variable
> are already combined.  Thus I believe you only need to consider a single
> conversion in valid_types_for_madd_p.

Hmm, I'm not so sure. I'll look into it a bit further.

> +/* Check the input types, TYPE1 and TYPE2 to a widening multiply,
>
> what are those types?  Is TYPE1 the result type and TYPE2 the
> operand type?  If so why

TYPE1 and TYPE2 are the inputs to the multiply. I thought I explained 
that in the comment before the function.

> +  initial_bitsize = TYPE_PRECISION (type1) + TYPE_PRECISION (type2);
>
> this?!

The result of the multiply will be this many bits wide. This may be 
narrower than the type that holds it.

E.g., 16-bit * 8-bit gives a result at most 24-bits wide, which will 
usually be held in a 32- or 64-bit variable.

> +  initial_unsigned = TYPE_UNSIGNED (type1)&&  TYPE_UNSIGNED (type2);
>
> that also looks odd.  So probably TYPE1 isn't the result type.  If they
> are the types of the operands, then what operand is EXPR for?

EXPR, as the comment says, is the addition that follows the multiply.

> -  if (TREE_CODE (rhs1) == SSA_NAME)
> +  for (tmp = rhs1, rhs1_code = ERROR_MARK;
> +       TREE_CODE (tmp) == SSA_NAME
> +&&  (CONVERT_EXPR_CODE_P (rhs1_code) || rhs1_code == ERROR_MARK);
> +       tmp = gimple_assign_rhs1 (rhs1_stmt))
>       {
> -      rhs1_stmt = SSA_NAME_DEF_STMT (rhs1);
> -      if (is_gimple_assign (rhs1_stmt))
> -       rhs1_code = gimple_assign_rhs_code (rhs1_stmt);
> +      rhs1_stmt = SSA_NAME_DEF_STMT (tmp);
> +      if (!is_gimple_assign (rhs1_stmt))
> +       break;
> +      rhs1_code = gimple_assign_rhs_code (rhs1_stmt);
>       }
>
> the result looks a bit like spaghetti code ... and lacks a comment
> on what it is trying to do.  It looks like it sees through an arbitrary
> number of conversions - possibly ones that will make the
> macc invalid, as for (short)int-var * short-var + int-var.  So you'll
> be pessimizing code by doing that unconditionally.  As I said
> above you should at most consider one intermediate conversion.

Ok, I need to add a comment here. The code does indeed look back through 
an arbitrary number of conversions. It is searching for the last real 
operation before the addition, hoping to find a multiply.

> I believe the code should be arranged such that only valid
> conversions are looked through in the first place.  Valid, in
> that the resulting types should still match the macc constraints.

Well, it might be possible to discard some conversions initially, but 
until the multiply is found, and it's input types are known, we can't 
know for certain what conversions are valid.

I think I need to explain what's going on here more clearly.

   1. It finds an addition statement. It's not known yet whether it is 
part of a multiply-and-accumulate, or not.

   2. It follows the conversion chain back from each operand to see if 
it finds a multiply, or widening multiply statement.

   3. If it finds a non-widening multiply, it checks it to see if it 
could be widening multiply-and-accumulate (it will already have been 
rejected as a widening multiply on it's own, but the addition might be 
in a wider mode, or the target might provide multiply-and-accumulate 
insns that don't have corresponding widening multiply insns).

   4. (This is the new bit!) It looks to see if there are any 
conversions between the multiply and addition that can safely be ignored.

   5. If we get here, then emit any necessary conversion statements, and 
convert the addition to a WIDEN_MULT_PLUS_EXPR.

Before these changes, any conversion between the multiply and addition 
statements would prevent optimization, even though there are many cases 
where the conversions are valid, and even inserted automatically.

I'm going to go away and find out whether there are really any cases 
where there can legitimately be more than one conversion, and at least 
update my patch with better commenting.

Thanks for you review.

Andrew

  reply	other threads:[~2011-07-07 10:27 UTC|newest]

Thread overview: 107+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-23 14:38 [PATCH (0/7)] Improve use of Widening Multiplies Andrew Stubbs
2011-06-23 14:39 ` [PATCH (1/7)] New optab framework for widening multiplies Andrew Stubbs
2011-07-09 15:38   ` Andrew Stubbs
2011-07-14 15:29     ` Andrew Stubbs
2011-07-22 13:01     ` Bernd Schmidt
2011-07-22 13:50       ` Andrew Stubbs
2011-07-22 14:01         ` Bernd Schmidt
2011-07-22 15:52           ` Andrew Stubbs
2011-08-19 14:41             ` Andrew Stubbs
2011-08-19 14:55               ` Richard Guenther
2011-08-19 15:07                 ` Andrew Stubbs
2011-08-19 16:40                   ` Andrew Stubbs
2011-06-23 14:41 ` [PATCH (2/7)] Widening multiplies by more than one mode Andrew Stubbs
2011-07-12 10:15   ` Andrew Stubbs
2011-07-12 11:05     ` Richard Guenther
2011-07-12 11:14       ` Richard Guenther
2011-07-12 11:38         ` Andrew Stubbs
2011-07-12 11:51           ` Richard Guenther
2011-07-21 19:51         ` Joseph S. Myers
2011-07-22  8:58           ` Andrew Stubbs
2011-07-14 14:17       ` Andrew Stubbs
2011-07-14 14:24         ` Richard Guenther
2011-08-19 14:45           ` Andrew Stubbs
2011-06-23 14:42 ` [PATCH (3/7)] Widening multiply-and-accumulate pattern matching Andrew Stubbs
2011-06-23 16:28   ` Richard Guenther
2011-06-24  8:14     ` Andrew Stubbs
2011-06-24  9:31       ` Richard Guenther
2011-06-24 14:08         ` Stubbs, Andrew
2011-06-24 16:13           ` Richard Guenther
2011-06-24 18:22             ` Stubbs, Andrew
2011-06-25  9:58               ` Richard Guenther
2011-06-28 11:32             ` Andrew Stubbs
2011-06-28 12:48               ` Richard Guenther
2011-06-28 16:37                 ` Michael Matz
2011-06-28 16:48                   ` Andrew Stubbs
2011-06-28 17:09                     ` Michael Matz
2011-07-01 11:58                       ` Stubbs, Andrew
2011-07-01 12:25                         ` Richard Guenther
2011-07-04 14:23                           ` Andrew Stubbs
2011-07-07 10:00                             ` Richard Guenther
2011-07-07 10:27                               ` Andrew Stubbs [this message]
2011-07-07 12:18                                 ` Andrew Stubbs
2011-07-07 12:34                                   ` Richard Guenther
2011-07-07 12:49                                     ` Richard Guenther
2011-07-08 12:55                                       ` Andrew Stubbs
2011-07-08 13:22                                         ` Richard Guenther
2011-07-11 17:01                               ` Andrew Stubbs
2011-07-12 11:05                                 ` Richard Guenther
2011-08-19 14:50                                   ` Andrew Stubbs
2011-07-14 14:26                                 ` Andrew Stubbs
2011-07-19  0:36                                   ` Janis Johnson
2011-07-19  9:01                                     ` Andrew Stubbs
2011-07-01 12:33                         ` Paolo Bonzini
2011-07-01 13:31                           ` Stubbs, Andrew
2011-07-01 14:41                             ` Paolo Bonzini
2011-07-01 14:55                               ` Stubbs, Andrew
2011-07-01 15:54                                 ` Paolo Bonzini
2011-07-01 18:18                                   ` Stubbs, Andrew
2011-07-01 15:10                             ` Stubbs, Andrew
2011-07-01 16:40                     ` Bernd Schmidt
2011-06-23 21:55   ` Janis Johnson
2011-06-23 14:43 ` [PATCH (4/7)] Unsigned multiplies using wider signed multiplies Andrew Stubbs
2011-06-28 13:28   ` Andrew Stubbs
2011-06-28 14:49     ` Andrew Stubbs
2011-07-04 14:27       ` Andrew Stubbs
2011-07-07 10:10         ` Richard Guenther
2011-07-07 10:42           ` Andrew Stubbs
2011-07-07 11:08             ` Richard Guenther
2011-07-12 14:10         ` Andrew Stubbs
2011-07-14 14:28           ` Andrew Stubbs
2011-07-14 14:31             ` Richard Guenther
2011-08-19 14:51               ` Andrew Stubbs
2011-06-28 13:30   ` Paolo Bonzini
2011-06-23 14:44 ` [PATCH (5/7)] Widening multiplies for mis-matched mode inputs Andrew Stubbs
2011-06-28 15:44   ` Andrew Stubbs
2011-07-04 14:29     ` Andrew Stubbs
2011-07-07 10:11       ` Richard Guenther
2011-07-14 14:34         ` Andrew Stubbs
2011-07-14 14:35           ` Richard Guenther
2011-08-19 14:54             ` Andrew Stubbs
2011-06-23 14:51 ` [PATCH (6/7)] More widening multiply-and-accumulate pattern matching Andrew Stubbs
2011-06-28 15:49   ` Andrew Stubbs
2011-07-04 14:32     ` Andrew Stubbs
2011-07-07 10:20       ` Richard Guenther
2011-07-14 14:35         ` Andrew Stubbs
2011-07-14 14:41           ` Richard Guenther
2011-08-19 15:03             ` Andrew Stubbs
2011-10-13 16:25               ` Matthew Gretton-Dann
2011-06-23 14:54 ` [PATCH (7/7)] Mixed-sign multiplies using narrowest mode Andrew Stubbs
2011-06-28 17:02   ` Andrew Stubbs
2011-07-14 14:44     ` Andrew Stubbs
2011-07-14 14:48       ` Richard Guenther
2011-08-19 15:56         ` Andrew Stubbs
2011-06-25 16:14 ` [PATCH (0/7)] Improve use of Widening Multiplies Bernd Schmidt
2011-06-27  9:16   ` Andrew Stubbs
2011-07-18 14:34 ` [PATCH (8/7)] Fix a bug in multiply-and-accumulate Andrew Stubbs
2011-07-18 16:09   ` Richard Guenther
2011-07-21 13:48     ` Andrew Stubbs
2011-08-19 16:22       ` Andrew Stubbs
2011-07-21 13:14 ` [PATCH (9/7)] Widening multiplies with constant inputs Andrew Stubbs
2011-07-21 14:34   ` Richard Guenther
2011-07-22 12:28     ` Andrew Stubbs
2011-07-22 12:32       ` Andrew Stubbs
2011-07-22 12:34         ` Richard Guenther
2011-07-22 16:06           ` Andrew Stubbs
2011-08-19 16:24             ` Andrew Stubbs
2011-08-19 16:52               ` H.J. Lu

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=4E1589D8.2060108@codesourcery.com \
    --to=ams@codesourcery.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=matz@suse.de \
    --cc=patches@linaro.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).