public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Make SRA produce integer replacements for enumeration types
@ 2011-09-06 17:41 Martin Jambor
  2011-09-07  8:09 ` Richard Guenther
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Jambor @ 2011-09-06 17:41 UTC (permalink / raw)
  To: GCC Patches; +Cc: Richard Guenther

Hi,

the patch below makes SRA produce intere type replacements when it
currently produces enumeration type ones because this then may cause
VRP to assume wrong bounds (PR 49911).

I do not know how to create a testcase for the PR this should solve
because I could not reproduce it on yesterday's trunk checkout.

The patch is against trunk, where it successfully passes bootstrap and
testing on x86_64-linux, but applies well also to 4.6 and 4.5 branches
and there has been a request to commit them there as well so I'd like
to do so (after testing it on them which I have not done yet).

OK?

Thanks,

Martin


2011-09-05  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/49911
	* tree-sra.c (analyze_access_subtree): Change type of to-be-replaced
	enumerations to the corresponding plain integer type.

Index: src/gcc/tree-sra.c
===================================================================
--- src.orig/gcc/tree-sra.c
+++ src/gcc/tree-sra.c
@@ -2075,13 +2075,25 @@ analyze_access_subtree (struct access *r
 	  || ((root->grp_scalar_read || root->grp_assignment_read)
 	      && (root->grp_scalar_write || root->grp_assignment_write))))
     {
+      bool new_integer_type;
+      if (TREE_CODE (root->type) == ENUMERAL_TYPE)
+	{
+	  tree rt = root->type;
+	  root->type = build_nonstandard_integer_type (TYPE_PRECISION (rt),
+						       TYPE_UNSIGNED (rt));
+	  new_integer_type = true;
+	}
+      else
+	new_integer_type = false;
+
       if (dump_file && (dump_flags & TDF_DETAILS))
 	{
 	  fprintf (dump_file, "Marking ");
 	  print_generic_expr (dump_file, root->base, 0);
-	  fprintf (dump_file, " offset: %u, size: %u: ",
+	  fprintf (dump_file, " offset: %u, size: %u ",
 		   (unsigned) root->offset, (unsigned) root->size);
-	  fprintf (dump_file, " to be replaced.\n");
+	  fprintf (dump_file, " to be replaced%s.\n",
+		   new_integer_type ? " with an integer": "");
 	}
 
       root->grp_to_be_replaced = 1;

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

* Re: [PATCH] Make SRA produce integer replacements for enumeration types
  2011-09-06 17:41 [PATCH] Make SRA produce integer replacements for enumeration types Martin Jambor
@ 2011-09-07  8:09 ` Richard Guenther
  2011-09-07 14:31   ` Martin Jambor
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Guenther @ 2011-09-07  8:09 UTC (permalink / raw)
  To: Martin Jambor; +Cc: GCC Patches

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2340 bytes --]

On Tue, 6 Sep 2011, Martin Jambor wrote:

> Hi,
> 
> the patch below makes SRA produce intere type replacements when it
> currently produces enumeration type ones because this then may cause
> VRP to assume wrong bounds (PR 49911).
> 
> I do not know how to create a testcase for the PR this should solve
> because I could not reproduce it on yesterday's trunk checkout.
> 
> The patch is against trunk, where it successfully passes bootstrap and
> testing on x86_64-linux, but applies well also to 4.6 and 4.5 branches
> and there has been a request to commit them there as well so I'd like
> to do so (after testing it on them which I have not done yet).
> 
> OK?

Ok.  Can you add the testcase from the PR?

Thanks,
Richard.

> Thanks,
> 
> Martin
> 
> 
> 2011-09-05  Martin Jambor  <mjambor@suse.cz>
> 
> 	PR tree-optimization/49911
> 	* tree-sra.c (analyze_access_subtree): Change type of to-be-replaced
> 	enumerations to the corresponding plain integer type.
> 
> Index: src/gcc/tree-sra.c
> ===================================================================
> --- src.orig/gcc/tree-sra.c
> +++ src/gcc/tree-sra.c
> @@ -2075,13 +2075,25 @@ analyze_access_subtree (struct access *r
>  	  || ((root->grp_scalar_read || root->grp_assignment_read)
>  	      && (root->grp_scalar_write || root->grp_assignment_write))))
>      {
> +      bool new_integer_type;
> +      if (TREE_CODE (root->type) == ENUMERAL_TYPE)
> +	{
> +	  tree rt = root->type;
> +	  root->type = build_nonstandard_integer_type (TYPE_PRECISION (rt),
> +						       TYPE_UNSIGNED (rt));
> +	  new_integer_type = true;
> +	}
> +      else
> +	new_integer_type = false;
> +
>        if (dump_file && (dump_flags & TDF_DETAILS))
>  	{
>  	  fprintf (dump_file, "Marking ");
>  	  print_generic_expr (dump_file, root->base, 0);
> -	  fprintf (dump_file, " offset: %u, size: %u: ",
> +	  fprintf (dump_file, " offset: %u, size: %u ",
>  		   (unsigned) root->offset, (unsigned) root->size);
> -	  fprintf (dump_file, " to be replaced.\n");
> +	  fprintf (dump_file, " to be replaced%s.\n",
> +		   new_integer_type ? " with an integer": "");
>  	}
>  
>        root->grp_to_be_replaced = 1;
> 
> 

-- 
Richard Guenther <rguenther@suse.de>
SUSE / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer

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

* Re: [PATCH] Make SRA produce integer replacements for enumeration types
  2011-09-07  8:09 ` Richard Guenther
@ 2011-09-07 14:31   ` Martin Jambor
  0 siblings, 0 replies; 3+ messages in thread
From: Martin Jambor @ 2011-09-07 14:31 UTC (permalink / raw)
  To: gcc-patches

Hi,

On Wed, Sep 07, 2011 at 10:08:29AM +0200, Richard Guenther wrote:
> On Tue, 6 Sep 2011, Martin Jambor wrote:
> > the patch below makes SRA produce intere type replacements when it
> > currently produces enumeration type ones because this then may cause
> > VRP to assume wrong bounds (PR 49911).
> > 
> > I do not know how to create a testcase for the PR this should solve
> > because I could not reproduce it on yesterday's trunk checkout.
> > 
> > The patch is against trunk, where it successfully passes bootstrap and
> > testing on x86_64-linux, but applies well also to 4.6 and 4.5 branches
> > and there has been a request to commit them there as well so I'd like
> > to do so (after testing it on them which I have not done yet).
> > 
> > OK?
> 
> Ok.  Can you add the testcase from the PR?
> 

Well, as I said, it does not fail even wothout the patch but why not.
This is the patch I wichh commit in a few moments.

Thanks,

Martin

2011-09-07  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/49911
	* tree-sra.c (analyze_access_subtree): Change type of to-be-replaced
	enumerations to the corresponding plain integer type.

	* testsuite/g++.dg/tree-ssa/pr49911.C: New test.

Index: src/gcc/tree-sra.c
===================================================================
--- src.orig/gcc/tree-sra.c
+++ src/gcc/tree-sra.c
@@ -2075,13 +2075,25 @@ analyze_access_subtree (struct access *r
 	  || ((root->grp_scalar_read || root->grp_assignment_read)
 	      && (root->grp_scalar_write || root->grp_assignment_write))))
     {
+      bool new_integer_type;
+      if (TREE_CODE (root->type) == ENUMERAL_TYPE)
+	{
+	  tree rt = root->type;
+	  root->type = build_nonstandard_integer_type (TYPE_PRECISION (rt),
+						       TYPE_UNSIGNED (rt));
+	  new_integer_type = true;
+	}
+      else
+	new_integer_type = false;
+
       if (dump_file && (dump_flags & TDF_DETAILS))
 	{
 	  fprintf (dump_file, "Marking ");
 	  print_generic_expr (dump_file, root->base, 0);
-	  fprintf (dump_file, " offset: %u, size: %u: ",
+	  fprintf (dump_file, " offset: %u, size: %u ",
 		   (unsigned) root->offset, (unsigned) root->size);
-	  fprintf (dump_file, " to be replaced.\n");
+	  fprintf (dump_file, " to be replaced%s.\n",
+		   new_integer_type ? " with an integer": "");
 	}
 
       root->grp_to_be_replaced = 1;
Index: src/gcc/testsuite/g++.dg/tree-ssa/pr49911.C
===================================================================
--- /dev/null
+++ src/gcc/testsuite/g++.dg/tree-ssa/pr49911.C
@@ -0,0 +1,41 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-rtti -fno-exceptions -fno-strict-aliasing -fdump-tree-vrp2" } */
+
+
+extern  void JS_Assert();
+typedef enum {
+eax,         ecx,         edx,         ebx,         esp,         ebp,
+esi,         edi     }
+RegisterID;
+union StateRemat {
+  RegisterID reg_;
+  int offset_;
+};
+static StateRemat FromRegister(RegisterID reg) {
+  StateRemat sr;
+  sr.reg_ = reg;
+  return sr;
+}
+static StateRemat FromAddress3(int address) {
+  StateRemat sr;
+    sr.offset_ = address;
+  //sr.offset_ = 0;
+  if (address < 46 &&    address >= 0) {
+    JS_Assert();
+  }
+  return sr;
+}
+struct FrameState {
+  StateRemat dataRematInfo2(bool y, int z) {
+    if (y)         return FromRegister(RegisterID(1));
+    return FromAddress3(z);
+  }
+};
+FrameState frame;
+StateRemat x;
+void jsop_setelem(bool y, int z) {
+  x = frame.dataRematInfo2(y, z);
+}
+
+/* { dg-final { scan-tree-dump-times "Folding predicate.*45" 0 "vrp2"} } */
+/* { dg-final { cleanup-tree-dump "vrp2" } } */

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

end of thread, other threads:[~2011-09-07 14:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-06 17:41 [PATCH] Make SRA produce integer replacements for enumeration types Martin Jambor
2011-09-07  8:09 ` Richard Guenther
2011-09-07 14:31   ` Martin Jambor

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