public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [PTR-PLUS] Fix up  forwprop testcase
       [not found] <OF823E30DC.B37CFD23-ON882572E0.0003D305-882572E0.000449D9@LocalDomain>
@ 2007-05-19  0:48 ` Andrew_Pinski
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew_Pinski @ 2007-05-19  0:48 UTC (permalink / raw)
  To: Andrew_Pinski; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 581 bytes --]

Andrew Pinski/R&D/SCEA wrote on 05/18/2007 05:46:50 PM:
> 
> Thanks,
> Andrew Pinski
> 
> ChangeLog:
> 
>  * tree-ssa-forwprop.c
>  (forward_propagate_addr_into_variable_array_index):
>  Don't expect there to be a cast for the index as that does not exist 
anymore.
>  (forward_propagate_addr_expr_1): Check for
>  POINTER_PLUS_EXPR instead of PLUS_EXPR.
>  Don't check for the first operand of the
>  POINTER_PLUS_EXPR was the index as it
>  cannot be.
> 
>  * gcc.dg/tree-ssa/forwprop-1.c: New testcase.


And here is the patch which I forgot to include.

Thanks,
Andrew Pinski


[-- Attachment #2: fixforwprop.diff.txt --]
[-- Type: text/plain, Size: 3545 bytes --]

Index: testsuite/gcc.dg/tree-ssa/forwprop-1.c
===================================================================
--- testsuite/gcc.dg/tree-ssa/forwprop-1.c	(revision 0)
+++ testsuite/gcc.dg/tree-ssa/forwprop-1.c	(revision 0)
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-forwprop" }  */
+
+/* We should be able to optimize this to b->t[i] = 1 during
+   early optimizations.  */
+
+struct a
+{
+  int t[10];
+};
+
+void f(struct a * b, __SIZE_TYPE__ i)
+{
+  int *c = b->t;
+  c[i] = 1;
+}
+
+/* { dg-final { scan-tree-dump "t\\\[i.*\\\] = 1;" "forwprop1" { xfail *-*-* } } } */
+/* { dg-final { scan-tree-dump "t\\\[i.*\\\] = 1;" "forwprop2" } } */
+/* { dg-final { cleanup-tree-dump "forwprop?" } } */
+
Index: tree-ssa-forwprop.c
===================================================================
--- tree-ssa-forwprop.c	(revision 124812)
+++ tree-ssa-forwprop.c	(working copy)
@@ -499,24 +499,6 @@ forward_propagate_addr_into_variable_arr
 {
   tree index;
 
-  /* The offset must be defined by a simple GIMPLE_MODIFY_STMT statement.  */
-  if (TREE_CODE (offset) != GIMPLE_MODIFY_STMT)
-    return false;
-
-  /* The RHS of the statement which defines OFFSET must be a gimple
-     cast of another SSA_NAME.  */
-  offset = GIMPLE_STMT_OPERAND (offset, 1);
-  if (!is_gimple_cast (offset))
-    return false;
-
-  offset = TREE_OPERAND (offset, 0);
-  if (TREE_CODE (offset) != SSA_NAME)
-    return false;
-
-  /* Get the defining statement of the offset before type
-     conversion.  */
-  offset = SSA_NAME_DEF_STMT (offset);
-
   /* The statement which defines OFFSET before type conversion
      must be a simple GIMPLE_MODIFY_STMT.  */
   if (TREE_CODE (offset) != GIMPLE_MODIFY_STMT)
@@ -635,13 +617,12 @@ forward_propagate_addr_expr_1 (tree name
       || !integer_zerop (TREE_OPERAND (array_ref, 1)))
     return false;
 
-  /* FIXME: this should be changed to POINTER_PLUS_EXPR.  */
   /* If the use of the ADDR_EXPR must be a PLUS_EXPR, or else there
      is nothing to do. */
-  if (TREE_CODE (rhs) != PLUS_EXPR)
+  if (TREE_CODE (rhs) != POINTER_PLUS_EXPR)
     return false;
 
-  /* Try to optimize &x[0] + C where C is a multiple of the size
+  /* Try to optimize &x[0] p+ C where C is a multiple of the size
      of the elements in X into &x[C/element size].  */
   if (TREE_OPERAND (rhs, 0) == name
       && TREE_CODE (TREE_OPERAND (rhs, 1)) == INTEGER_CST)
@@ -665,7 +646,7 @@ forward_propagate_addr_expr_1 (tree name
 	}
     }
 
-  /* Try to optimize &x[0] + OFFSET where OFFSET is defined by
+  /* Try to optimize &x[0] p+ OFFSET where OFFSET is defined by
      converting a multiplication of an index by the size of the
      array elements, then the result is converted into the proper
      type for the arithmetic.  */
@@ -682,21 +663,6 @@ forward_propagate_addr_expr_1 (tree name
 							      def_rhs, use_stmt);
       return res;
     }
-	      
-  /* Same as the previous case, except the operands of the PLUS_EXPR
-     were reversed.  */
-  if (TREE_OPERAND (rhs, 1) == name
-      && TREE_CODE (TREE_OPERAND (rhs, 0)) == SSA_NAME
-      /* Avoid problems with IVopts creating PLUS_EXPRs with a
-	 different type than their operands.  */
-      && lang_hooks.types_compatible_p (TREE_TYPE (name), TREE_TYPE (rhs)))
-    {
-      bool res;
-      tree offset_stmt = SSA_NAME_DEF_STMT (TREE_OPERAND (rhs, 0));
-      res = forward_propagate_addr_into_variable_array_index (offset_stmt, lhs,
-							      def_rhs, use_stmt);
-      return res;
-    }
   return false;
 }
 

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

* [PTR-PLUS] Fix up  forwprop testcase
@ 2007-05-19  0:47 Andrew_Pinski
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew_Pinski @ 2007-05-19  0:47 UTC (permalink / raw)
  To: gcc-patches

Hi,
  This fixes up the new forwprop testcase which I added to the trunk.  The 
problem here was that we were checking for PLUS_EXPR and then also 
checking for a cast which is no longer there.


Committed after a bootstrap/test on i686-linux-gnu with 2 regressions (the 
2 regressions are due to forwprop doing a better job and data-ref not 
understanding the IR any more, see PR 31995 and 31996 for more details and 
a testcase for the mainline).

Thanks,
Andrew Pinski

ChangeLog:

        * tree-ssa-forwprop.c
        (forward_propagate_addr_into_variable_array_index):
        Don't expect there to be a cast for the index as that does not 
exist anymore.
        (forward_propagate_addr_expr_1): Check for
        POINTER_PLUS_EXPR instead of PLUS_EXPR.
        Don't check for the first operand of the
        POINTER_PLUS_EXPR was the index as it
        cannot be.

        * gcc.dg/tree-ssa/forwprop-1.c: New testcase.

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

end of thread, other threads:[~2007-05-19  0:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <OF823E30DC.B37CFD23-ON882572E0.0003D305-882572E0.000449D9@LocalDomain>
2007-05-19  0:48 ` [PTR-PLUS] Fix up forwprop testcase Andrew_Pinski
2007-05-19  0:47 Andrew_Pinski

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