public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Question on cfg_remove_useless_stmts_bb
@ 2004-08-18 11:52 Richard Kenner
  2004-09-01  6:22 ` Jeffrey A Law
  0 siblings, 1 reply; 11+ messages in thread
From: Richard Kenner @ 2004-08-18 11:52 UTC (permalink / raw)
  To: law; +Cc: gcc

    the fact that it wasn't obvious to you is a good indication that I
    should have had more comments in that code.

Actually, there's still some confusion there.  Now that you've pointed it
out, from the way I read that code, VAL is always either a PARM_DECL or
a VAR_DECL.  So why test !TREE_CONSTANT (val)?

And why exclude a constant anyway

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

* Re: Question on cfg_remove_useless_stmts_bb
  2004-08-18 11:52 Question on cfg_remove_useless_stmts_bb Richard Kenner
@ 2004-09-01  6:22 ` Jeffrey A Law
  0 siblings, 0 replies; 11+ messages in thread
From: Jeffrey A Law @ 2004-09-01  6:22 UTC (permalink / raw)
  To: Richard Kenner; +Cc: gcc

On Wed, 2004-08-18 at 05:42, Richard Kenner wrote:
>     the fact that it wasn't obvious to you is a good indication that I
>     should have had more comments in that code.
> 
> Actually, there's still some confusion there.  Now that you've pointed it
> out, from the way I read that code, VAL is always either a PARM_DECL or
> a VAR_DECL.  So why test !TREE_CONSTANT (val)?
VAL can certainly be a constant.  Consider

if (a == 42)

Which should match:

      if (TREE_CODE (cond) == EQ_EXPR
          && (TREE_CODE (TREE_OPERAND (cond, 0)) == VAR_DECL
              || TREE_CODE (TREE_OPERAND (cond, 0)) == PARM_DECL)
          && (TREE_CODE (TREE_OPERAND (cond, 1)) == VAR_DECL
              || TREE_CODE (TREE_OPERAND (cond, 1)) == PARM_DECL
              || TREE_CONSTANT (TREE_OPERAND (cond, 1))))


FWIW, this is one of the things that could likely go away if we
don't translate trees out of SSA form -- this code exists merely
to clean up trivial redundancies created by the out-of-ssa
translation pass.

Jeff

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

* Re: Question on cfg_remove_useless_stmts_bb
@ 2004-08-18 11:51 Richard Kenner
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Kenner @ 2004-08-18 11:51 UTC (permalink / raw)
  To: law; +Cc: gcc

    You might want to add a suitable comment while you're in there

Most certainly.

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

* Re: Question on cfg_remove_useless_stmts_bb
  2004-08-17 16:49 Richard Kenner
@ 2004-08-18  8:42 ` Jeffrey A Law
  0 siblings, 0 replies; 11+ messages in thread
From: Jeffrey A Law @ 2004-08-18  8:42 UTC (permalink / raw)
  To: Richard Kenner; +Cc: gcc

On Tue, 2004-08-17 at 09:59, Richard Kenner wrote:
>     VAL can only be a _DECL node or a constant.  
> 
> I missed that part.  Thanks.
> 
> So I'll test and then commit that trivial change.
Sounds good.  You might want to add a suitable comment while you're
in there -- the fact that it wasn't obvious to you is a good
indication that I should have had more comments in that code.

jeff

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

* Re: Question on cfg_remove_useless_stmts_bb
@ 2004-08-17 16:49 Richard Kenner
  2004-08-18  8:42 ` Jeffrey A Law
  0 siblings, 1 reply; 11+ messages in thread
From: Richard Kenner @ 2004-08-17 16:49 UTC (permalink / raw)
  To: law; +Cc: gcc

    VAL can only be a _DECL node or a constant.  

I missed that part.  Thanks.

So I'll test and then commit that trivial change.

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

* Re: Question on cfg_remove_useless_stmts_bb
  2004-08-17 12:31 Richard Kenner
@ 2004-08-17 15:49 ` Jeffrey A Law
  0 siblings, 0 replies; 11+ messages in thread
From: Jeffrey A Law @ 2004-08-17 15:49 UTC (permalink / raw)
  To: Richard Kenner; +Cc: gcc

On Tue, 2004-08-17 at 04:57, Richard Kenner wrote:
>       if (TREE_CODE (stmt) == ASM_EXPR
>           || (TREE_CODE (stmt) == MODIFY_EXPR
>               && (TREE_OPERAND (stmt, 0) == var
>                   || TREE_CODE (stmt, 0) == val)))
> 
>     Ought to do the trick.
> 
> In this case, yes, but I'm not convinced that it's complete.  Couldn't
> VAL be a more complex expression here and we have to verify that none of
> its operands were modified?  That issue is basically the other motivation
> for my query (the primary one being, of course, "how did this ever work?"!).
VAL can only be a _DECL node or a constant.  

  if (TREE_CODE (cond) == VAR_DECL || TREE_CODE (cond) == PARM_DECL)
    {
      var = cond;
      val = (bb->pred->flags & EDGE_FALSE_VALUE
             ? boolean_false_node : boolean_true_node);
    }
  else if (TREE_CODE (cond) == TRUTH_NOT_EXPR
           && (TREE_CODE (TREE_OPERAND (cond, 0)) == VAR_DECL
               || TREE_CODE (TREE_OPERAND (cond, 0)) == PARM_DECL))
    {
      var = TREE_OPERAND (cond, 0);
      val = (bb->pred->flags & EDGE_FALSE_VALUE
             ? boolean_true_node : boolean_false_node);
    }
  else
    {
      if (bb->pred->flags & EDGE_FALSE_VALUE)
        cond = invert_truthvalue (cond);
      if (TREE_CODE (cond) == EQ_EXPR
          && (TREE_CODE (TREE_OPERAND (cond, 0)) == VAR_DECL
              || TREE_CODE (TREE_OPERAND (cond, 0)) == PARM_DECL)
          && (TREE_CODE (TREE_OPERAND (cond, 1)) == VAR_DECL
              || TREE_CODE (TREE_OPERAND (cond, 1)) == PARM_DECL
              || TREE_CONSTANT (TREE_OPERAND (cond, 1))))
        {
          var = TREE_OPERAND (cond, 0);
          val = TREE_OPERAND (cond, 1);
        }
      else
        return;
 

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

* Re: Question on cfg_remove_useless_stmts_bb
@ 2004-08-17 12:31 Richard Kenner
  2004-08-17 15:49 ` Jeffrey A Law
  0 siblings, 1 reply; 11+ messages in thread
From: Richard Kenner @ 2004-08-17 12:31 UTC (permalink / raw)
  To: law; +Cc: gcc

      if (TREE_CODE (stmt) == ASM_EXPR
          || (TREE_CODE (stmt) == MODIFY_EXPR
              && (TREE_OPERAND (stmt, 0) == var
                  || TREE_CODE (stmt, 0) == val)))

    Ought to do the trick.

In this case, yes, but I'm not convinced that it's complete.  Couldn't
VAL be a more complex expression here and we have to verify that none of
its operands were modified?  That issue is basically the other motivation
for my query (the primary one being, of course, "how did this ever work?"!).

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

* Re: Question on cfg_remove_useless_stmts_bb
  2004-08-13 19:59 Richard Kenner
  2004-08-13 20:19 ` Diego Novillo
@ 2004-08-17  8:26 ` Jeffrey A Law
  1 sibling, 0 replies; 11+ messages in thread
From: Jeffrey A Law @ 2004-08-17  8:26 UTC (permalink / raw)
  To: Richard Kenner; +Cc: gcc

On Fri, 2004-08-13 at 13:53, Richard Kenner wrote:
> I'm getting a failure on c-torture/execute/930513-2.c with -O3 and what's
> happening is that the out of ssa pass is looking at 
> 
>   if (j != i) goto <L1>; else goto <L2>;
> 
>     ...
> 
> <L2>:;
>   i = i + 1;
>   j = i;
> 
> 
> The cfg_remove_useless_stmts_bb knows that J and I are equal.  So when it
> gets to the "j = i" assignment, it deletes it.  The problem is that it
> doesn't notice that "i = i + 1" clobbers the equality relation.
Ah, yes, the code ought to be checking that both I (VAR) & J (VAL) are
not clobbered.  I was pretty sure it did that, but I can't find the
code which verifies that VAL isn't clobbered.

I would think that changing
  if (TREE_CODE (stmt) == ASM_EXPR
      || (TREE_CODE (stmt) == MODIFY_EXPR
          && TREE_OPERAND (stmt, 0) == var)

To

  if (TREE_CODE (stmt) == ASM_EXPR
      || (TREE_CODE (stmt) == MODIFY_EXPR
          && (TREE_OPERAND (stmt, 0) == var
              || TREE_CODE (stmt, 0) == val)))

Ought to do the trick.

jeff


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

* Re: Question on cfg_remove_useless_stmts_bb
@ 2004-08-13 21:29 Richard Kenner
  0 siblings, 0 replies; 11+ messages in thread
From: Richard Kenner @ 2004-08-13 21:29 UTC (permalink / raw)
  To: dnovillo; +Cc: gcc

    On a clean tree?  

No, on my tree.  But I still need to understand what's causing it,
hence my questions.

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

* Re: Question on cfg_remove_useless_stmts_bb
  2004-08-13 19:59 Richard Kenner
@ 2004-08-13 20:19 ` Diego Novillo
  2004-08-17  8:26 ` Jeffrey A Law
  1 sibling, 0 replies; 11+ messages in thread
From: Diego Novillo @ 2004-08-13 20:19 UTC (permalink / raw)
  To: Richard Kenner; +Cc: gcc

On Fri, 2004-08-13 at 15:53, Richard Kenner wrote:
> I'm getting a failure on c-torture/execute/930513-2.c with -O3 and what's
> happening is that the out of ssa pass is looking at 
> 
On a clean tree?  This test worked fine last night on all of x86,
x86-64, alpha, ppc and ia64.


Diego.

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

* Question on cfg_remove_useless_stmts_bb
@ 2004-08-13 19:59 Richard Kenner
  2004-08-13 20:19 ` Diego Novillo
  2004-08-17  8:26 ` Jeffrey A Law
  0 siblings, 2 replies; 11+ messages in thread
From: Richard Kenner @ 2004-08-13 19:59 UTC (permalink / raw)
  To: gcc

I'm getting a failure on c-torture/execute/930513-2.c with -O3 and what's
happening is that the out of ssa pass is looking at 

  if (j != i) goto <L1>; else goto <L2>;

    ...

<L2>:;
  i = i + 1;
  j = i;


The cfg_remove_useless_stmts_bb knows that J and I are equal.  So when it
gets to the "j = i" assignment, it deletes it.  The problem is that it
doesn't notice that "i = i + 1" clobbers the equality relation.

I don't think it's sufficient to test for an assignment to VAL here because
I think VAL can be an expression since we are no longer in GIMPLE, but
I'm not sure.

Hence my question.

I don't know why this test isn't failing for everybody, so I suspect this
is some sort of latent bug somehow.  (Or else I'm missing something,
which is quite possible.)

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

end of thread, other threads:[~2004-09-01  6:22 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-18 11:52 Question on cfg_remove_useless_stmts_bb Richard Kenner
2004-09-01  6:22 ` Jeffrey A Law
  -- strict thread matches above, loose matches on Subject: below --
2004-08-18 11:51 Richard Kenner
2004-08-17 16:49 Richard Kenner
2004-08-18  8:42 ` Jeffrey A Law
2004-08-17 12:31 Richard Kenner
2004-08-17 15:49 ` Jeffrey A Law
2004-08-13 21:29 Richard Kenner
2004-08-13 19:59 Richard Kenner
2004-08-13 20:19 ` Diego Novillo
2004-08-17  8:26 ` Jeffrey A Law

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