Linus Torvalds wrote:
>
> On Sun, 14 Aug 2005, Oleg Nesterov wrote:
> >
> > Without this patch evaluate_iterator() evaluates
> > stmt->iterator_pre_condition twice.
>
> If you do this, please (a) verify that linearize.c still does the right
> thing for for-loops, and (b) remove the special cases that see if
> "pre_condition == post_condition".

I think that only linearize.c should be changed, but linearize.c is
beyond my understanding completely.

pseudo_t linearize_statement:
....
  1986          case STMT_ITERATOR: {
....
  2001                  if (pre_condition == post_condition) {
  2002                          loop_top = alloc_basic_block(ep, stmt->pos);
  2003                          set_activeblock(ep, loop_top);
  2004                  }
  2005
  2006                  if (pre_condition)
  2007                          linearize_cond_branch(ep, pre_condition, 
loop_body, loop_end);


Looking at parse_{for,while,do}_statement i think that

        (pre_condition != NULL) ALWAYS_EQUAL_TO (pre_condition == 
post_condition)

except may be "for (;;)", when both conditions == NULL. No?

I am sending the patch, but I doubt it is correct. However, ./test-linearize
shows the same output before and after patch with this code:

        int cond(void), func();

        static void t1(void)
        {
                for (;;) func();
        }

        static void t2(void)
        {
                for (; cond(); ) func();
        }

Oleg.

--- git-snapshot-20050814/parse.c~2_forpost     2005-08-15 21:44:43.000000000 
+0400
+++ git-snapshot-20050814/parse.c       2005-08-15 22:30:45.000000000 +0400
@@ -1200,7 +1200,7 @@ static struct token *parse_for_statement
        stmt->iterator_pre_statement = make_statement(e1);
        stmt->iterator_pre_condition = e2;
        stmt->iterator_post_statement = make_statement(e3);
-       stmt->iterator_post_condition = e2;
+       stmt->iterator_post_condition = NULL;
        stmt->iterator_statement = iterator;
        end_iterator(stmt);
 
@@ -1217,7 +1217,7 @@ static struct token *parse_while_stateme
        token = statement(token, &iterator);
 
        stmt->iterator_pre_condition = expr;
-       stmt->iterator_post_condition = expr;
+       stmt->iterator_post_condition = NULL;
        stmt->iterator_statement = iterator;
        end_iterator(stmt);
 
--- git-snapshot-20050814/linearize.c~2_forpost 2005-08-12 02:14:53.000000000 
+0400
+++ git-snapshot-20050814/linearize.c   2005-08-15 23:28:29.000000000 +0400
@@ -1997,14 +1997,12 @@ pseudo_t linearize_statement(struct entr
                loop_body = loop_top = alloc_basic_block(ep, stmt->pos);
                loop_continue = alloc_basic_block(ep, stmt->pos);
                loop_end = alloc_basic_block(ep, stmt->pos);
- 
-               if (pre_condition == post_condition) {
+
+               if (pre_condition) {
                        loop_top = alloc_basic_block(ep, stmt->pos);
                        set_activeblock(ep, loop_top);
-               }
-
-               if (pre_condition) 
                        linearize_cond_branch(ep, pre_condition, loop_body, 
loop_end);
+               }
 
                bind_label(stmt->iterator_continue, loop_continue, stmt->pos);
                bind_label(stmt->iterator_break, loop_end, stmt->pos);
@@ -2015,7 +2013,7 @@ pseudo_t linearize_statement(struct entr
 
                set_activeblock(ep, loop_continue);
                linearize_statement(ep, post_statement);
-               if (!post_condition || pre_condition == post_condition)
+               if (!post_condition)
                        add_goto(ep, loop_top);
                else
                        linearize_cond_branch(ep, post_condition, loop_top, 
loop_end);
-
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to