[tree-ssa-branch] SIMPLE grammar change in for() loops [patch]

Diego Novillo dnovillo@redhat.com
Sun Sep 1 19:06:00 GMT 2002


While debugging CCP I found it annoying that we may have variable
definitions in a sequence expression:

	for (i = 0, j = 0, k = 0; i < 10; i = i + 1)
		j = k + i;

The above for loop is in SIMPLE form but it forces CCP to
understand definition references in an expression sequence.
It's much easier if in CCP we can assume that every definition is
of the form 'lhs = rhs'.

This patch modifies the SIMPLE grammar slightly so that the above
loop loses the expression sequence.  Anything that makes the
optimizer life's easier can only be good, but if anyone has any
strong preference for the status quo, please let me know.

Another minor modification introduced by the patch is to mark
CLEANUP_STMTs and ASM_STMTs not SIMPLE so that the DFA analyzer
can introduce clobbering definitions for anything that it doesn't
understand (another patch to fix this latter part is still in the
pipeline).

We should really simplify ASM_STMTs, BTW.


Bootstrapped and tested on x86.


Diego.


	* c-simplify.c (simplify_stmt): Mark CLEANUP_STMTs and ASM_STMTs
	not SIMPLE.
	(simplify_for_stmt): Do not allow expression sequences in
	FOR_INIT_STMT and FOR_EXPR nodes.
	* tree-simple.c: Document difference with original SIMPLE grammar.


Index: c-simplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/c-simplify.c,v
retrieving revision 1.1.4.20
diff -d -u -p -r1.1.4.20 c-simplify.c
--- c-simplify.c	27 Aug 2002 00:01:00 -0000	1.1.4.20
+++ c-simplify.c	2 Sep 2002 01:48:40 -0000
@@ -277,12 +277,12 @@ simplify_stmt (stmt_p)
 	case CLEANUP_STMT:
 	  /* XXX: need to clean up CLEANUP_STMT.  Idea: turn it into
 	     an statement-expression and simplify that.  */
+	  walk_tree (&CLEANUP_EXPR (stmt), mark_not_simple_r, NULL, NULL);
 	  break;
 
 	/* Statements that need no simplification.  */
 	case LABEL_STMT:
 	case GOTO_STMT:
-	case ASM_STMT:
 	case CASE_LABEL:
 	case CONTINUE_STMT:
 	case BREAK_STMT:
@@ -290,6 +290,15 @@ simplify_stmt (stmt_p)
 	  stmt_p = &TREE_CHAIN (stmt);
 	  goto cont;
 
+	/* FIXME: ASM_STMTs should probably be simplified.  But, is it
+		  safe?  */
+	case ASM_STMT:
+	  walk_tree (&ASM_INPUTS (stmt), mark_not_simple_r, NULL, NULL);
+	  walk_tree (&ASM_OUTPUTS (stmt), mark_not_simple_r, NULL, NULL);
+	  walk_tree (&ASM_CLOBBERS (stmt), mark_not_simple_r, NULL, NULL);
+	  stmt_p = &TREE_CHAIN (stmt);
+	  goto cont;
+
 	case FILE_STMT:
 	  input_filename = FILE_STMT_FILENAME (stmt);
 	  stmt_p = &TREE_CHAIN (stmt);
@@ -460,9 +469,9 @@ simplify_for_stmt (stmt, pre_p)
   expr_s = FOR_EXPR (stmt);
 
   /* Check if we need to do anything.  */
-  init_is_simple = (init_s == NULL_TREE || is_simple_exprseq (init_s));
+  init_is_simple = (init_s == NULL_TREE || is_simple_expr (init_s));
   cond_is_simple = (cond_s == NULL_TREE || is_simple_condexpr (cond_s));
-  expr_is_simple = (expr_s == NULL_TREE || is_simple_exprseq (expr_s));
+  expr_is_simple = (expr_s == NULL_TREE || is_simple_expr (expr_s));
 
   if (init_is_simple && cond_is_simple && expr_is_simple)
     {
@@ -477,10 +486,7 @@ simplify_for_stmt (stmt, pre_p)
   pre_expr_s = NULL_TREE;
   post_expr_s = NULL_TREE;
 
-  /* Simplify FOR_INIT_STMT.  Note that we always simplify it, even if it's
-     in SIMPLE form already.  This is because we need to insert PRE_COND_S
-     right after the initialization statements, and if PRE_COND_S contains
-     statement trees, we cannot add them to a COMPOUND_EXPR:
+  /* Simplify FOR_INIT_STMT. 
 
 	BEFORE				AFTER
 
@@ -488,12 +494,7 @@ simplify_for_stmt (stmt, pre_p)
 					init_s;
 					post_init_s;
 					pre_cond_s;
-	for (init; cond; ...)		for ( ; cond_s; ...)
-
-     FIXME: Since FOR_INIT_STMT can be a COMPOUND_EXPR, it should be possible
-	    to emit PRE_INIT_S, INIT_S, POST_INIT_S and PRE_COND_S into a
-	    COMPOUND_EXPR inside FOR_INIT_STMT.  However, this is not
-	    possible if any of these elements contains statement trees.  */
+	for (init; cond; ...)		for ( ; cond_s; ...)  */
   walk_tree (&init_s, mostly_copy_tree_r, NULL, NULL);
   simplify_expr (&init_s, &pre_init_s, &post_init_s, is_simple_expr,
 		 fb_rvalue);
@@ -511,7 +512,7 @@ simplify_for_stmt (stmt, pre_p)
 
   /* Simplify FOR_EXPR.  Note that if FOR_EXPR needs to be simplified,
      it's converted into a simple_expr because we need to move it out of
-     the loop header (see previous FIXME note for future enhancement).  */
+     the loop header.  */
   if (!expr_is_simple)
     {
       walk_tree (&expr_s, mostly_copy_tree_r, NULL, NULL);
Index: tree-simple.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-simple.c,v
retrieving revision 1.1.4.11
diff -d -u -p -r1.1.4.11 tree-simple.c
--- tree-simple.c	16 Aug 2002 15:50:33 -0000	1.1.4.11
+++ tree-simple.c	2 Sep 2002 01:48:46 -0000
@@ -51,7 +51,15 @@ Boston, MA 02111-1307, USA.  */
 	      | IF '(' condexpr ')' stmt ELSE stmt
 	      | WHILE '(' condexpr ')' stmt
 	      | DO stmt WHILE '(' condexpr ')'
-	      | FOR '('exprseq ';' condexpr ';'exprseq ')' stmt
+	      | FOR '(' expr ';' condexpr ';' expr ')' stmt
+	      		|
+			+-> Original SIMPLE grammar allows exprseq here,
+			    but this makes life more difficult to some
+			    optimizers that need to learn to deal with
+			    expression sequences instead of SIMPLE
+			    assignments (e.g., CCP when examining V_DEF
+			    references)
+	      	
 	      | SWITCH '(' val ')' casestmts
 	      | ';'
 



More information about the Gcc-patches mailing list