public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PR82816: Widening multiplies of bitfields
@ 2017-11-03 15:40 Richard Sandiford
  2017-11-04  9:45 ` Richard Sandiford
  2017-11-06 11:53 ` Richard Biener
  0 siblings, 2 replies; 3+ messages in thread
From: Richard Sandiford @ 2017-11-03 15:40 UTC (permalink / raw)
  To: gcc-patches

In this PR we tried to create a widening multiply of two 3-bit numbers,
but that isn't a widening multiply at the optab/rtl level, since both
the input and output still have the same mode.

We could trap this either in is_widening_mult_p or (as the patch does)
in the routines that actually ask for an optab.  The latter seemed
more natural since is_widening_mult_p doesn't otherwise care about modes.

Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64-linux-gnu.
OK to install?

Richard


2017-11-03  Richard Sandiford  <richard.sandiford@linaro.org>
	    Alan Hayward  <alan.hayward@arm.com>
	    David Sherwood  <david.sherwood@arm.com>

gcc/
	PR tree-optimization/82816
	* tree-ssa-math-opts.c (convert_mult_to_widen): Return false
	if the modes of the two types are the same.
	(convert_plusminus_to_widen): Likewise.

gcc/testsuite/
	* gcc.c-torture/compile/pr82816.c: New test.

Index: gcc/tree-ssa-math-opts.c
===================================================================
--- gcc/tree-ssa-math-opts.c	2017-11-01 12:29:40.203534002 +0000
+++ gcc/tree-ssa-math-opts.c	2017-11-03 11:18:03.046411241 +0000
@@ -3259,6 +3259,9 @@ convert_mult_to_widen (gimple *stmt, gim
 
   to_mode = SCALAR_INT_TYPE_MODE (type);
   from_mode = SCALAR_INT_TYPE_MODE (type1);
+  if (to_mode == from_mode)
+    return false;
+
   from_unsigned1 = TYPE_UNSIGNED (type1);
   from_unsigned2 = TYPE_UNSIGNED (type2);
 
@@ -3449,6 +3452,9 @@ convert_plusminus_to_widen (gimple_stmt_
 
   to_mode = SCALAR_TYPE_MODE (type);
   from_mode = SCALAR_TYPE_MODE (type1);
+  if (to_mode == from_mode)
+    return false;
+
   from_unsigned1 = TYPE_UNSIGNED (type1);
   from_unsigned2 = TYPE_UNSIGNED (type2);
   optype = type1;
Index: gcc/testsuite/gcc.c-torture/compile/pr82816.c
===================================================================
--- /dev/null	2017-11-03 10:40:07.002381728 +0000
+++ gcc/testsuite/gcc.c-torture/compile/pr82816.c	2017-11-03 11:18:03.045411265 +0000
@@ -0,0 +1,12 @@
+struct A
+{
+  int b:3;
+} d, e;
+
+int c;
+
+void f ()
+{
+  char g = d.b * e.b;
+  c = g;
+}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PR82816: Widening multiplies of bitfields
  2017-11-03 15:40 PR82816: Widening multiplies of bitfields Richard Sandiford
@ 2017-11-04  9:45 ` Richard Sandiford
  2017-11-06 11:53 ` Richard Biener
  1 sibling, 0 replies; 3+ messages in thread
From: Richard Sandiford @ 2017-11-04  9:45 UTC (permalink / raw)
  To: gcc-patches

Richard Sandiford <richard.sandiford@linaro.org> writes:
> In this PR we tried to create a widening multiply of two 3-bit numbers,
> but that isn't a widening multiply at the optab/rtl level, since both
> the input and output still have the same mode.
>
> We could trap this either in is_widening_mult_p or (as the patch does)
> in the routines that actually ask for an optab.  The latter seemed
> more natural since is_widening_mult_p doesn't otherwise care about modes.
>
> Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64-linux-gnu.
> OK to install?
>
> Richard
>
>
> 2017-11-03  Richard Sandiford  <richard.sandiford@linaro.org>
> 	    Alan Hayward  <alan.hayward@arm.com>
> 	    David Sherwood  <david.sherwood@arm.com>

Oops, I instinctively used the SVE ChangeLog Header of the Day
for this patch too, but it was just me for this one.  (In case it
seemed strange that it took three people to write four lines...)

> gcc/
> 	PR tree-optimization/82816
> 	* tree-ssa-math-opts.c (convert_mult_to_widen): Return false
> 	if the modes of the two types are the same.
> 	(convert_plusminus_to_widen): Likewise.
>
> gcc/testsuite/
> 	* gcc.c-torture/compile/pr82816.c: New test.
>
> Index: gcc/tree-ssa-math-opts.c
> ===================================================================
> --- gcc/tree-ssa-math-opts.c	2017-11-01 12:29:40.203534002 +0000
> +++ gcc/tree-ssa-math-opts.c	2017-11-03 11:18:03.046411241 +0000
> @@ -3259,6 +3259,9 @@ convert_mult_to_widen (gimple *stmt, gim
>  
>    to_mode = SCALAR_INT_TYPE_MODE (type);
>    from_mode = SCALAR_INT_TYPE_MODE (type1);
> +  if (to_mode == from_mode)
> +    return false;
> +
>    from_unsigned1 = TYPE_UNSIGNED (type1);
>    from_unsigned2 = TYPE_UNSIGNED (type2);
>  
> @@ -3449,6 +3452,9 @@ convert_plusminus_to_widen (gimple_stmt_
>  
>    to_mode = SCALAR_TYPE_MODE (type);
>    from_mode = SCALAR_TYPE_MODE (type1);
> +  if (to_mode == from_mode)
> +    return false;
> +
>    from_unsigned1 = TYPE_UNSIGNED (type1);
>    from_unsigned2 = TYPE_UNSIGNED (type2);
>    optype = type1;
> Index: gcc/testsuite/gcc.c-torture/compile/pr82816.c
> ===================================================================
> --- /dev/null	2017-11-03 10:40:07.002381728 +0000
> +++ gcc/testsuite/gcc.c-torture/compile/pr82816.c	2017-11-03 11:18:03.045411265 +0000
> @@ -0,0 +1,12 @@
> +struct A
> +{
> +  int b:3;
> +} d, e;
> +
> +int c;
> +
> +void f ()
> +{
> +  char g = d.b * e.b;
> +  c = g;
> +}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: PR82816: Widening multiplies of bitfields
  2017-11-03 15:40 PR82816: Widening multiplies of bitfields Richard Sandiford
  2017-11-04  9:45 ` Richard Sandiford
@ 2017-11-06 11:53 ` Richard Biener
  1 sibling, 0 replies; 3+ messages in thread
From: Richard Biener @ 2017-11-06 11:53 UTC (permalink / raw)
  To: GCC Patches, Richard Sandiford

On Fri, Nov 3, 2017 at 4:40 PM, Richard Sandiford
<richard.sandiford@linaro.org> wrote:
> In this PR we tried to create a widening multiply of two 3-bit numbers,
> but that isn't a widening multiply at the optab/rtl level, since both
> the input and output still have the same mode.
>
> We could trap this either in is_widening_mult_p or (as the patch does)
> in the routines that actually ask for an optab.  The latter seemed
> more natural since is_widening_mult_p doesn't otherwise care about modes.
>
> Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64-linux-gnu.
> OK to install?

Hum.  I _think_ we should go one step further and disallow
types that do not match their mode precision.

Anyway, patch is ok.

Thanks,
Richard.

> Richard
>
>
> 2017-11-03  Richard Sandiford  <richard.sandiford@linaro.org>
>             Alan Hayward  <alan.hayward@arm.com>
>             David Sherwood  <david.sherwood@arm.com>
>
> gcc/
>         PR tree-optimization/82816
>         * tree-ssa-math-opts.c (convert_mult_to_widen): Return false
>         if the modes of the two types are the same.
>         (convert_plusminus_to_widen): Likewise.
>
> gcc/testsuite/
>         * gcc.c-torture/compile/pr82816.c: New test.
>
> Index: gcc/tree-ssa-math-opts.c
> ===================================================================
> --- gcc/tree-ssa-math-opts.c    2017-11-01 12:29:40.203534002 +0000
> +++ gcc/tree-ssa-math-opts.c    2017-11-03 11:18:03.046411241 +0000
> @@ -3259,6 +3259,9 @@ convert_mult_to_widen (gimple *stmt, gim
>
>    to_mode = SCALAR_INT_TYPE_MODE (type);
>    from_mode = SCALAR_INT_TYPE_MODE (type1);
> +  if (to_mode == from_mode)
> +    return false;
> +
>    from_unsigned1 = TYPE_UNSIGNED (type1);
>    from_unsigned2 = TYPE_UNSIGNED (type2);
>
> @@ -3449,6 +3452,9 @@ convert_plusminus_to_widen (gimple_stmt_
>
>    to_mode = SCALAR_TYPE_MODE (type);
>    from_mode = SCALAR_TYPE_MODE (type1);
> +  if (to_mode == from_mode)
> +    return false;
> +
>    from_unsigned1 = TYPE_UNSIGNED (type1);
>    from_unsigned2 = TYPE_UNSIGNED (type2);
>    optype = type1;
> Index: gcc/testsuite/gcc.c-torture/compile/pr82816.c
> ===================================================================
> --- /dev/null   2017-11-03 10:40:07.002381728 +0000
> +++ gcc/testsuite/gcc.c-torture/compile/pr82816.c       2017-11-03 11:18:03.045411265 +0000
> @@ -0,0 +1,12 @@
> +struct A
> +{
> +  int b:3;
> +} d, e;
> +
> +int c;
> +
> +void f ()
> +{
> +  char g = d.b * e.b;
> +  c = g;
> +}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-11-06 11:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-03 15:40 PR82816: Widening multiplies of bitfields Richard Sandiford
2017-11-04  9:45 ` Richard Sandiford
2017-11-06 11:53 ` Richard Biener

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).