Patchwork Fix bug in hoisting when using -fgcse-las

login
register
mail settings
Submitter Maxim Kuvyrkov
Date July 28, 2010, 4:13 p.m.
Message ID <4C505746.5010707@codesourcery.com>
Download mbox | patch
Permalink /patch/60161/
State New
Headers show

Comments

Maxim Kuvyrkov - July 28, 2010, 4:13 p.m.
This patch fixes http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45107 .

The problem is due to mismatch in max_distance values for the same 
expression when it is processed on the LHS versus the RHS.

More specifically, the problem due to me not including -fgcse-las in the 
testing of hoisting improvements patches.

The attached patch fixes the bug.  It was tested by bootstrapping GCC 
with -fgcse-las in BOOT_CFLAGS.

OK to apply?
Jeff Law - July 28, 2010, 4:45 p.m.
On 07/28/10 10:13, Maxim Kuvyrkov wrote:
> This patch fixes http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45107 .
>
> The problem is due to mismatch in max_distance values for the same 
> expression when it is processed on the LHS versus the RHS.
>
> More specifically, the problem due to me not including -fgcse-las in 
> the testing of hoisting improvements patches.
>
> The attached patch fixes the bug.  It was tested by bootstrapping GCC 
> with -fgcse-las in BOOT_CFLAGS.
OK.
Jeff

Patch

diff --git a/gcc/gcse.c b/gcc/gcse.c
index 1124131..6e923f9 100644
--- a/gcc/gcse.c
+++ b/gcc/gcse.c
@@ -1471,6 +1471,7 @@  hash_scan_set (rtx pat, rtx insn, struct hash_table_d *table)
   else if (flag_gcse_las && REG_P (src) && MEM_P (dest))
       {
         unsigned int regno = REGNO (src);
+	int max_distance = 0;
 
         /* Do not do this for constant/copy propagation.  */
         if (! table->set_p
@@ -1482,7 +1483,7 @@  hash_scan_set (rtx pat, rtx insn, struct hash_table_d *table)
 	      do that easily for EH edges so disable GCSE on these for now.  */
 	   && !can_throw_internal (insn)
 	   /* Is SET_DEST something we want to gcse?  */
-	   && want_to_gcse_p (dest, NULL)
+	   && want_to_gcse_p (dest, &max_distance)
 	   /* Don't CSE a nop.  */
 	   && ! set_noop_p (pat)
 	   /* Don't GCSE if it has attached REG_EQUIV note.
@@ -1504,7 +1505,7 @@  hash_scan_set (rtx pat, rtx insn, struct hash_table_d *table)
 
 	       /* Record the memory expression (DEST) in the hash table.  */
 	       insert_expr_in_table (dest, GET_MODE (dest), insn,
-				     antic_p, avail_p, 0, table);
+				     antic_p, avail_p, max_distance, table);
              }
       }
 }
diff --git a/gcc/testsuite/gcc.dg/pr45107.c b/gcc/testsuite/gcc.dg/pr45107.c
new file mode 100644
index 0000000..05dbec3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr45107.c
@@ -0,0 +1,13 @@ 
+/* PR rtl-optimization/45107 */
+/* { dg-do compile } */
+/* { dg-options "-Os -fgcse-las" } */
+
+extern void bar(int *);
+
+int foo (int *p)
+{
+    int i = *p;
+    if (i != 1)
+      bar(&i);
+    *p = i;
+}