public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Handle CONSTRUCTOR in operand_equal_p
@ 2015-10-14 16:27 Jan Hubicka
  2015-10-14 17:26 ` Jeff Law
  2015-10-14 18:42 ` Richard Biener
  0 siblings, 2 replies; 9+ messages in thread
From: Jan Hubicka @ 2015-10-14 16:27 UTC (permalink / raw)
  To: gcc-patches, rguenther

Hi,
this patch adds the CONSTRUCTOR case discussed while back.  Only empty
constructors are matched, as those are only appearing in gimple operand.
I tested that during bootstrap about 7500 matches are for empty ctors.
There are couple hundred for non-empty probably used on generic. 

Bootstrapped/regtested x86_64-linux, OK?

Honza

	* fold-const.c (operand_equal_p): Match empty constructors.
Index: fold-const.c
===================================================================
--- fold-const.c	(revision 228735)
+++ fold-const.c	(working copy)
@@ -2890,6 +2891,11 @@ operand_equal_p (const_tree arg0, const_
 	return operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 0),
 				flags | OEP_ADDRESS_OF
 				| OEP_CONSTANT_ADDRESS_OF);
+      case CONSTRUCTOR:
+	/* In GIMPLE empty constructors are allowed in initializers of
+	   vector types.  */
+	return (!vec_safe_length (CONSTRUCTOR_ELTS (arg0))
+		&& !vec_safe_length (CONSTRUCTOR_ELTS (arg1)));
       default:
 	break;
       }

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

* Re: Handle CONSTRUCTOR in operand_equal_p
  2015-10-14 16:27 Handle CONSTRUCTOR in operand_equal_p Jan Hubicka
@ 2015-10-14 17:26 ` Jeff Law
  2015-10-14 17:35   ` Jan Hubicka
  2015-10-14 18:42 ` Richard Biener
  1 sibling, 1 reply; 9+ messages in thread
From: Jeff Law @ 2015-10-14 17:26 UTC (permalink / raw)
  To: Jan Hubicka, gcc-patches, rguenther

On 10/14/2015 10:27 AM, Jan Hubicka wrote:
> Hi,
> this patch adds the CONSTRUCTOR case discussed while back.  Only empty
> constructors are matched, as those are only appearing in gimple operand.
> I tested that during bootstrap about 7500 matches are for empty ctors.
> There are couple hundred for non-empty probably used on generic.
>
> Bootstrapped/regtested x86_64-linux, OK?
>
> Honza
>
> 	* fold-const.c (operand_equal_p): Match empty constructors.
OK.  It'd be useful to have a test which shows that matching these 
results in some kind of difference we can see in the dump files.

jeff

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

* Re: Handle CONSTRUCTOR in operand_equal_p
  2015-10-14 17:26 ` Jeff Law
@ 2015-10-14 17:35   ` Jan Hubicka
  0 siblings, 0 replies; 9+ messages in thread
From: Jan Hubicka @ 2015-10-14 17:35 UTC (permalink / raw)
  To: Jeff Law; +Cc: Jan Hubicka, gcc-patches, rguenther

> On 10/14/2015 10:27 AM, Jan Hubicka wrote:
> >Hi,
> >this patch adds the CONSTRUCTOR case discussed while back.  Only empty
> >constructors are matched, as those are only appearing in gimple operand.
> >I tested that during bootstrap about 7500 matches are for empty ctors.
> >There are couple hundred for non-empty probably used on generic.
> >
> >Bootstrapped/regtested x86_64-linux, OK?
> >
> >Honza
> >
> >	* fold-const.c (operand_equal_p): Match empty constructors.
> OK.  It'd be useful to have a test which shows that matching these
> results in some kind of difference we can see in the dump files.

I will try to think of something.  My main motivation is to get ipa-icf-gimple
and operand_equal_p into sync and hopefully comonize the logic.  Having testcase
then will be a lot easier (any function with empty constructor will do)

Honza
> 
> jeff

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

* Re: Handle CONSTRUCTOR in operand_equal_p
  2015-10-14 16:27 Handle CONSTRUCTOR in operand_equal_p Jan Hubicka
  2015-10-14 17:26 ` Jeff Law
@ 2015-10-14 18:42 ` Richard Biener
  2015-10-14 23:55   ` Jan Hubicka
  1 sibling, 1 reply; 9+ messages in thread
From: Richard Biener @ 2015-10-14 18:42 UTC (permalink / raw)
  To: Jan Hubicka, gcc-patches

On October 14, 2015 6:27:02 PM GMT+02:00, Jan Hubicka <hubicka@ucw.cz> wrote:
>Hi,
>this patch adds the CONSTRUCTOR case discussed while back.  Only empty
>constructors are matched, as those are only appearing in gimple
>operand.
>I tested that during bootstrap about 7500 matches are for empty ctors.
>There are couple hundred for non-empty probably used on generic. 
>
>Bootstrapped/regtested x86_64-linux, OK?
>
>Honza
>
>	* fold-const.c (operand_equal_p): Match empty constructors.
>Index: fold-const.c
>===================================================================
>--- fold-const.c	(revision 228735)
>+++ fold-const.c	(working copy)
>@@ -2890,6 +2891,11 @@ operand_equal_p (const_tree arg0, const_
>	return operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1,
>0),
> 				flags | OEP_ADDRESS_OF
> 				| OEP_CONSTANT_ADDRESS_OF);
>+      case CONSTRUCTOR:
>+	/* In GIMPLE empty constructors are allowed in initializers of
>+	   vector types.  */

The comment is wrong (or at least odd),
On gimple an empty vector constructor should be folded to a VECTOR_CST.

>+	return (!vec_safe_length (CONSTRUCTOR_ELTS (arg0))
>+		&& !vec_safe_length (CONSTRUCTOR_ELTS (arg1)));
>       default:
> 	break;
>       }


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

* Re: Handle CONSTRUCTOR in operand_equal_p
  2015-10-14 18:42 ` Richard Biener
@ 2015-10-14 23:55   ` Jan Hubicka
  2015-10-15  6:57     ` Richard Biener
  0 siblings, 1 reply; 9+ messages in thread
From: Jan Hubicka @ 2015-10-14 23:55 UTC (permalink / raw)
  To: Richard Biener; +Cc: Jan Hubicka, gcc-patches

> On October 14, 2015 6:27:02 PM GMT+02:00, Jan Hubicka <hubicka@ucw.cz> wrote:
> >Hi,
> >this patch adds the CONSTRUCTOR case discussed while back.  Only empty
> >constructors are matched, as those are only appearing in gimple
> >operand.
> >I tested that during bootstrap about 7500 matches are for empty ctors.
> >There are couple hundred for non-empty probably used on generic. 
> >
> >Bootstrapped/regtested x86_64-linux, OK?
> >
> >Honza
> >
> >	* fold-const.c (operand_equal_p): Match empty constructors.
> >Index: fold-const.c
> >===================================================================
> >--- fold-const.c	(revision 228735)
> >+++ fold-const.c	(working copy)
> >@@ -2890,6 +2891,11 @@ operand_equal_p (const_tree arg0, const_
> >	return operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1,
> >0),
> > 				flags | OEP_ADDRESS_OF
> > 				| OEP_CONSTANT_ADDRESS_OF);
> >+      case CONSTRUCTOR:
> >+	/* In GIMPLE empty constructors are allowed in initializers of
> >+	   vector types.  */
> 
> The comment is wrong (or at least odd),
> On gimple an empty vector constructor should be folded to a VECTOR_CST.

Hmm, I tought we have a={} i.e. for clearing whole structure.
If we never have constructors appearing as gimple operands, I guess we don't
really need the code at gimple level (because at least so far ipa-icf has
separate path to compare constructors).

Honza
> 
> >+	return (!vec_safe_length (CONSTRUCTOR_ELTS (arg0))
> >+		&& !vec_safe_length (CONSTRUCTOR_ELTS (arg1)));
> >       default:
> > 	break;
> >       }
> 

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

* Re: Handle CONSTRUCTOR in operand_equal_p
  2015-10-14 23:55   ` Jan Hubicka
@ 2015-10-15  6:57     ` Richard Biener
  2015-10-21 19:10       ` Jan Hubicka
  0 siblings, 1 reply; 9+ messages in thread
From: Richard Biener @ 2015-10-15  6:57 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: gcc-patches

On October 15, 2015 1:55:09 AM GMT+02:00, Jan Hubicka <hubicka@ucw.cz> wrote:
>> On October 14, 2015 6:27:02 PM GMT+02:00, Jan Hubicka
><hubicka@ucw.cz> wrote:
>> >Hi,
>> >this patch adds the CONSTRUCTOR case discussed while back.  Only
>empty
>> >constructors are matched, as those are only appearing in gimple
>> >operand.
>> >I tested that during bootstrap about 7500 matches are for empty
>ctors.
>> >There are couple hundred for non-empty probably used on generic. 
>> >
>> >Bootstrapped/regtested x86_64-linux, OK?
>> >
>> >Honza
>> >
>> >	* fold-const.c (operand_equal_p): Match empty constructors.
>> >Index: fold-const.c
>> >===================================================================
>> >--- fold-const.c	(revision 228735)
>> >+++ fold-const.c	(working copy)
>> >@@ -2890,6 +2891,11 @@ operand_equal_p (const_tree arg0, const_
>> >	return operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1,
>> >0),
>> > 				flags | OEP_ADDRESS_OF
>> > 				| OEP_CONSTANT_ADDRESS_OF);
>> >+      case CONSTRUCTOR:
>> >+	/* In GIMPLE empty constructors are allowed in initializers of
>> >+	   vector types.  */
>> 
>> The comment is wrong (or at least odd),
>> On gimple an empty vector constructor should be folded to a
>VECTOR_CST.
>
>Hmm, I tought we have a={} i.e. for clearing whole structure.

Yes we do, but then the comment should refer to aggregate types.

>If we never have constructors appearing as gimple operands, I guess we
>don't
>really need the code at gimple level (because at least so far ipa-icf
>has
>separate path to compare constructors).
>
>Honza
>> 
>> >+	return (!vec_safe_length (CONSTRUCTOR_ELTS (arg0))
>> >+		&& !vec_safe_length (CONSTRUCTOR_ELTS (arg1)));
>> >       default:
>> > 	break;
>> >       }
>> 


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

* Re: Handle CONSTRUCTOR in operand_equal_p
  2015-10-15  6:57     ` Richard Biener
@ 2015-10-21 19:10       ` Jan Hubicka
  2015-10-22  7:39         ` Richard Biener
  0 siblings, 1 reply; 9+ messages in thread
From: Jan Hubicka @ 2015-10-21 19:10 UTC (permalink / raw)
  To: Richard Biener; +Cc: Jan Hubicka, gcc-patches

Hi,
this is updated patch I am going to commit.  As discussed, we also need to match
non-empty CONSTRUCTOR of vectors, but those should never be having CONSTANT flags
set, so they need care in the other path trhough operand_equal_p, so I will post
separate patch for that.

I updated the comment per Richard's comment and added a testcase.  Vuriously
enoug we fold "val? (struct a){} : (struct a){}" only in PRE (tailmerging).
W/o the patch even .optimized dump has the test and we fold it away only after
lowering to RTL:
ret (int val)
{
  struct a D.1764;

  <bb 2>:
  if (val_2(D) != 0)
    goto <bb 3>;
  else
    goto <bb 4>;

  <bb 3>:
  D.1764 = {};
  goto <bb 5>;

  <bb 4>:
  D.1764 = {};

  <bb 5>:
  return D.1764;

}

ret:
.LFB0:
        .cfi_startproc
        xorl    %eax, %eax
        ret
        .cfi_endproc

With the patch we get:

ret (int val)
{
  struct a D.1764;

  <bb 2>:
  D.1764 = {};
  return D.1764;

}

Honza

	* fold-const.c (operand_equal_p): Add code matching empty
	constructors.
	* gcc.dg/tree-ssa/operand-equal-1.c: Verify that empty constructors
	are matched.

Index: fold-const.c
===================================================================
--- fold-const.c	(revision 229133)
+++ fold-const.c	(working copy)
@@ -2892,6 +2892,11 @@ operand_equal_p (const_tree arg0, const_
 	return operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 0),
 				flags | OEP_ADDRESS_OF
 				| OEP_CONSTANT_ADDRESS_OF);
+      case CONSTRUCTOR:
+	/* In GIMPLE empty constructors are allowed in initializers of
+	   aggregates.  */
+	return (!vec_safe_length (CONSTRUCTOR_ELTS (arg0))
+		&& !vec_safe_length (CONSTRUCTOR_ELTS (arg1)));
       default:
 	break;
       }
Index: testsuite/gcc.dg/tree-ssa/operand-equal-1.c
===================================================================
--- testsuite/gcc.dg/tree-ssa/operand-equal-1.c	(revision 0)
+++ testsuite/gcc.dg/tree-ssa/operand-equal-1.c	(revision 0)
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-pre" } */
+struct a {int a,b;};
+struct a ret(int val)
+{
+   return val? (struct a){} : (struct a){};
+}
+/* { dg-final { scan-tree-dump-not "if " "pre"} } */

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

* Re: Handle CONSTRUCTOR in operand_equal_p
  2015-10-21 19:10       ` Jan Hubicka
@ 2015-10-22  7:39         ` Richard Biener
  2015-10-23  5:43           ` Jan Hubicka
  0 siblings, 1 reply; 9+ messages in thread
From: Richard Biener @ 2015-10-22  7:39 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: gcc-patches

On Wed, 21 Oct 2015, Jan Hubicka wrote:

> Hi,
> this is updated patch I am going to commit.  As discussed, we also need to match
> non-empty CONSTRUCTOR of vectors, but those should never be having CONSTANT flags
> set, so they need care in the other path trhough operand_equal_p, so I will post
> separate patch for that.
> 
> I updated the comment per Richard's comment and added a testcase.  Vuriously
> enoug we fold "val? (struct a){} : (struct a){}" only in PRE (tailmerging).
> W/o the patch even .optimized dump has the test and we fold it away only after
> lowering to RTL:
> ret (int val)
> {
>   struct a D.1764;
> 
>   <bb 2>:
>   if (val_2(D) != 0)
>     goto <bb 3>;
>   else
>     goto <bb 4>;
> 
>   <bb 3>:
>   D.1764 = {};
>   goto <bb 5>;
> 
>   <bb 4>:
>   D.1764 = {};
> 
>   <bb 5>:
>   return D.1764;
> 
> }
> 
> ret:
> .LFB0:
>         .cfi_startproc
>         xorl    %eax, %eax
>         ret
>         .cfi_endproc
> 
> With the patch we get:
> 
> ret (int val)
> {
>   struct a D.1764;
> 
>   <bb 2>:
>   D.1764 = {};
>   return D.1764;
> 
> }

But only via GENERIC folding I suppose.  Yes, we don't value-number
aggregates and generally PRE (and DOM via excessive jump-threading)
is the only pass that remotely handles this kind of situation.

code hoisting/sinking would maybe catch this but as this involves
memory I'm not sure the implementation ontop of PRE that is stuck
in some PR would catch it.

Richard.

> Honza
> 
> 	* fold-const.c (operand_equal_p): Add code matching empty
> 	constructors.
> 	* gcc.dg/tree-ssa/operand-equal-1.c: Verify that empty constructors
> 	are matched.
> 
> Index: fold-const.c
> ===================================================================
> --- fold-const.c	(revision 229133)
> +++ fold-const.c	(working copy)
> @@ -2892,6 +2892,11 @@ operand_equal_p (const_tree arg0, const_
>  	return operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 0),
>  				flags | OEP_ADDRESS_OF
>  				| OEP_CONSTANT_ADDRESS_OF);
> +      case CONSTRUCTOR:
> +	/* In GIMPLE empty constructors are allowed in initializers of
> +	   aggregates.  */
> +	return (!vec_safe_length (CONSTRUCTOR_ELTS (arg0))
> +		&& !vec_safe_length (CONSTRUCTOR_ELTS (arg1)));
>        default:
>  	break;
>        }
> Index: testsuite/gcc.dg/tree-ssa/operand-equal-1.c
> ===================================================================
> --- testsuite/gcc.dg/tree-ssa/operand-equal-1.c	(revision 0)
> +++ testsuite/gcc.dg/tree-ssa/operand-equal-1.c	(revision 0)
> @@ -0,0 +1,8 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-pre" } */
> +struct a {int a,b;};
> +struct a ret(int val)
> +{
> +   return val? (struct a){} : (struct a){};
> +}
> +/* { dg-final { scan-tree-dump-not "if " "pre"} } */
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)

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

* Re: Handle CONSTRUCTOR in operand_equal_p
  2015-10-22  7:39         ` Richard Biener
@ 2015-10-23  5:43           ` Jan Hubicka
  0 siblings, 0 replies; 9+ messages in thread
From: Jan Hubicka @ 2015-10-23  5:43 UTC (permalink / raw)
  To: Richard Biener; +Cc: Jan Hubicka, gcc-patches

> 
> But only via GENERIC folding I suppose.  Yes, we don't value-number
> aggregates and generally PRE (and DOM via excessive jump-threading)
> is the only pass that remotely handles this kind of situation.

I actually think it is tail merging unifying the code, but I did not
really look too deep into it.

Honza
> 
> code hoisting/sinking would maybe catch this but as this involves
> memory I'm not sure the implementation ontop of PRE that is stuck
> in some PR would catch it.
> 
> Richard.
> 
> > Honza
> > 
> > 	* fold-const.c (operand_equal_p): Add code matching empty
> > 	constructors.
> > 	* gcc.dg/tree-ssa/operand-equal-1.c: Verify that empty constructors
> > 	are matched.
> > 
> > Index: fold-const.c
> > ===================================================================
> > --- fold-const.c	(revision 229133)
> > +++ fold-const.c	(working copy)
> > @@ -2892,6 +2892,11 @@ operand_equal_p (const_tree arg0, const_
> >  	return operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 0),
> >  				flags | OEP_ADDRESS_OF
> >  				| OEP_CONSTANT_ADDRESS_OF);
> > +      case CONSTRUCTOR:
> > +	/* In GIMPLE empty constructors are allowed in initializers of
> > +	   aggregates.  */
> > +	return (!vec_safe_length (CONSTRUCTOR_ELTS (arg0))
> > +		&& !vec_safe_length (CONSTRUCTOR_ELTS (arg1)));
> >        default:
> >  	break;
> >        }
> > Index: testsuite/gcc.dg/tree-ssa/operand-equal-1.c
> > ===================================================================
> > --- testsuite/gcc.dg/tree-ssa/operand-equal-1.c	(revision 0)
> > +++ testsuite/gcc.dg/tree-ssa/operand-equal-1.c	(revision 0)
> > @@ -0,0 +1,8 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-O2 -fdump-tree-pre" } */
> > +struct a {int a,b;};
> > +struct a ret(int val)
> > +{
> > +   return val? (struct a){} : (struct a){};
> > +}
> > +/* { dg-final { scan-tree-dump-not "if " "pre"} } */
> > 
> > 
> 
> -- 
> Richard Biener <rguenther@suse.de>
> SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)

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

end of thread, other threads:[~2015-10-23  5:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-14 16:27 Handle CONSTRUCTOR in operand_equal_p Jan Hubicka
2015-10-14 17:26 ` Jeff Law
2015-10-14 17:35   ` Jan Hubicka
2015-10-14 18:42 ` Richard Biener
2015-10-14 23:55   ` Jan Hubicka
2015-10-15  6:57     ` Richard Biener
2015-10-21 19:10       ` Jan Hubicka
2015-10-22  7:39         ` Richard Biener
2015-10-23  5:43           ` Jan Hubicka

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