public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [tree-ssa] Dce & infinite loops
@ 2004-03-18 14:51 Richard Guenther
  2004-03-18 15:26 ` Paolo Carlini
  0 siblings, 1 reply; 25+ messages in thread
From: Richard Guenther @ 2004-03-18 14:51 UTC (permalink / raw)
  To: Diego Novillo; +Cc: Steven Bosscher, Zdenek Dvorak, gcc

On Thu, 2004-03-18 at 07:31, Steven Bosscher wrote:

> Removing an infinte loop is indeed wrong.  Hence this comment
> in tree-ssa-dce.c:
>
>   /* Some blocks don't have an immediate post dominator.  This can
happen
>      for example with infinite loops.  Removing an infinite loop is an
>      inappropriate transformation anyway...  */
>
> If we remove that infinite loop, you found a bug.
>

Diego wrote:
> I've always hated this custom.  Is this a language mandate?  Or just
> "we've always done it this way"?  Why not tell the user to use a
> volatile index variable if they want the infinite loop?

People - you may never remove infinite loops because that would change
program behavior for f.i.:

int main() {
  printf("1");
  for (;;) ;
  printf("1");
  return 0;
}

The "best" (or worst to someone for sure) would be, if the C standard says
infinite loops result in undefined behavior (as program never terminates),
to reject the program.  But never silently delete them.

For optimizing away empty (but finite) loops, this is certainly correct,
though maybe not what Joe average kernel hacker would expect ;) I.e.
issuing a warning if doing that is highly appreciated.

Richard.

--
Richard Guenther <richard dot guenther at uni-tuebingen dot de>
WWW: http://www.tat.physik.uni-tuebingen.de/~rguenth/

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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 14:51 [tree-ssa] Dce & infinite loops Richard Guenther
@ 2004-03-18 15:26 ` Paolo Carlini
  0 siblings, 0 replies; 25+ messages in thread
From: Paolo Carlini @ 2004-03-18 15:26 UTC (permalink / raw)
  To: Richard Guenther; +Cc: Diego Novillo, Steven Bosscher, Zdenek Dvorak, gcc

Richard Guenther wrote:

>For optimizing away empty (but finite) loops, this is certainly correct,
>though maybe not what Joe average kernel hacker would expect ;) I.e.
>issuing a warning if doing that is highly appreciated.
>  
>
I find important this point about warnings because a loop may be written 
as not
empty, then become empty as a result of previous optimizations: this may
become quite common thanks to the new powerful SSA machineries.

But this is a general issue, I think: some optimizations (the 
"interesting" ones?)
may happen only thanks to previous optimizations and feedback to the user in
the "dangerous" (and "unexpected"!) cases is appreciated, isn't it?

Or just put everything under -ffast-math or something similar?

Something we lack, perhaps, is -fast, not just -ffast-math, which is not 
really
the same thing as this kind of interesting discussion shows!

Paolo.

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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 18:11                 ` Dale Johannesen
@ 2004-03-18 21:45                   ` Alex Rosenberg
  0 siblings, 0 replies; 25+ messages in thread
From: Alex Rosenberg @ 2004-03-18 21:45 UTC (permalink / raw)
  To: egcs

On Mar 18, 2004, at 9:47 AM, Dale Johannesen wrote:

> Of course this refers only to finite empty loops; infinite ones cannot
> be removed, as several people have said.  (As a semi-practical
> matter, you can use these to wait for an external signal from ^C
> or the like.)

One cause of infinite loops is a common error:

while (!flag) { }

where flag should have been declared volatile.

For that reason, I'd like to see a warning when the compiler sees a 
trivially reduced infinite loop (L1: goto L1) in some later pass.

+------------------------------------------------------------+
| Alexander M. Rosenberg           <mailto:alexr@_spies.com> |
| Nobody cares what I say. Remove the underscore to mail me. |

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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 16:26               ` Zdenek Dvorak
  2004-03-18 16:34                 ` Geert Bosch
@ 2004-03-18 18:11                 ` Dale Johannesen
  2004-03-18 21:45                   ` Alex Rosenberg
  1 sibling, 1 reply; 25+ messages in thread
From: Dale Johannesen @ 2004-03-18 18:11 UTC (permalink / raw)
  To: Zdenek Dvorak
  Cc: gcc, Dale Johannesen, Joseph S. Myers, Steven Bosscher, Geert Bosch

On Mar 18, 2004, at 8:25 AM, Zdenek Dvorak wrote:
>
> OK, I may easily extend the loop optimizer to remove empty loops if
> there is a demand for it (once dce is fixed so that it is not done
> even in cases it is incorrect, as happens now).

I think it is a good idea.  In the past I've been on RMS's side in this
matter (don't remove them under the assumption that users put it
there for a reason), but enough people inside Apple have asked
for empty loops to be removed that I'm ready to change my mind.
If there is controversy, it might be conditionalized on 
-fremove-empty-loops
or something like that.

Of course this refers only to finite empty loops; infinite ones cannot
be removed, as several people have said.  (As a semi-practical
matter, you can use these to wait for an external signal from ^C
or the like.)

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

* RE: [tree-ssa] Dce & infinite loops
  2004-03-18 17:25                       ` Zdenek Dvorak
@ 2004-03-18 17:30                         ` Dave Korn
  0 siblings, 0 replies; 25+ messages in thread
From: Dave Korn @ 2004-03-18 17:30 UTC (permalink / raw)
  To: gcc


> -----Original Message-----
> From: gcc-owner On Behalf Of Zdenek Dvorak
> Sent: 18 March 2004 17:00

> > For me, the most important thing is consistency.  Right now 
> we do not 
> > remove infinite loops that are infinite because they have no loop 
> > exit, but we do kill infinite loops that are infinite 
> because the exit 
> > condition can never be true.  We should either remove all infinite 
> > loops, or none at all.
> 
> sorry, this is not up to us -- we must preserve *all* 
> infinite loops to be correct.  Only if we are able to prove 
> the loop must always terminate we may remove it.
> 
> Zdenek

  This discussion is becoming confused, owing to a lack of clarity in
people's posts: we must all take more care to be clear about the distinction
between finite and _in_finite loops.

  Removing an empty loop BODY (but keeping the actual loop) is always valid.

  Removing the body of a FINITE loop and just emitting code to perform the
side-effects is also always valid.

  Removing an INFINITE loop is NEVER valid, regardless of the content of its
body, because the program flow should never get past an INfinite loop.

    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....

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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 17:00                     ` Steven Bosscher
@ 2004-03-18 17:25                       ` Zdenek Dvorak
  2004-03-18 17:30                         ` Dave Korn
  0 siblings, 1 reply; 25+ messages in thread
From: Zdenek Dvorak @ 2004-03-18 17:25 UTC (permalink / raw)
  To: Steven Bosscher; +Cc: Geert Bosch, gcc, Joseph S. Myers

Hello,

> > > >OK, I may easily extend the loop optimizer to remove empty loops if
> > > >there is a demand for it (once dce is fixed so that it is not done
> > > >even in cases it is incorrect, as happens now).
> > >
> > > How is the loop in your example different from a call to
> > > a non-terminating function returning void? I don't see
> > > why the optimizers would handle that correctly and not
> > > the infinite loop. Could you explain?
> >
> > I had in one of previous mails, but anyway:  for the function we see it
> > has side effects (nontermination), so we mark it as neccesary.  For the
> > loop we do not.
> >
> > The solution is obvious -- mark the backedges of the loops for that we are
> > not able to prove that they have to terminate as well.
> 
> If we can eliminate empty loop bodies -- fine with me.  One of the
> reasons why cd-dce does better than regular dce is because we kill
> such loops.  Yes, they happen.  When I looked at this, there were
> about 2 dozen times or so in the test case for PR8361, so they're
> not even that uncommon.
> 
> Just always removing infinite loops is also not very hard to do.
> All we'd need to do is add fake edges for tree DCE.  I decided
> against that because I thought that removing infinite loops was
> not a valid transformation.  But if it is valid after all, I can
> put fake edges in, and all infinite loops will be removed.
> 
> For me, the most important thing is consistency.  Right now we
> do not remove infinite loops that are infinite because they have
> no loop exit, but we do kill infinite loops that are infinite
> because the exit condition can never be true.  We should either
> remove all infinite loops, or none at all.

sorry, this is not up to us -- we must preserve *all* infinite loops to
be correct.  Only if we are able to prove the loop must always terminate
we may remove it.

Zdenek

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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 16:38                   ` Zdenek Dvorak
@ 2004-03-18 17:00                     ` Steven Bosscher
  2004-03-18 17:25                       ` Zdenek Dvorak
  0 siblings, 1 reply; 25+ messages in thread
From: Steven Bosscher @ 2004-03-18 17:00 UTC (permalink / raw)
  To: Zdenek Dvorak, Geert Bosch; +Cc: gcc, Joseph S. Myers

On Thursday 18 March 2004 17:34, Zdenek Dvorak wrote:
> Hello,
>
> > >OK, I may easily extend the loop optimizer to remove empty loops if
> > >there is a demand for it (once dce is fixed so that it is not done
> > >even in cases it is incorrect, as happens now).
> >
> > How is the loop in your example different from a call to
> > a non-terminating function returning void? I don't see
> > why the optimizers would handle that correctly and not
> > the infinite loop. Could you explain?
>
> I had in one of previous mails, but anyway:  for the function we see it
> has side effects (nontermination), so we mark it as neccesary.  For the
> loop we do not.
>
> The solution is obvious -- mark the backedges of the loops for that we are
> not able to prove that they have to terminate as well.

If we can eliminate empty loop bodies -- fine with me.  One of the
reasons why cd-dce does better than regular dce is because we kill
such loops.  Yes, they happen.  When I looked at this, there were
about 2 dozen times or so in the test case for PR8361, so they're
not even that uncommon.

Just always removing infinite loops is also not very hard to do.
All we'd need to do is add fake edges for tree DCE.  I decided
against that because I thought that removing infinite loops was
not a valid transformation.  But if it is valid after all, I can
put fake edges in, and all infinite loops will be removed.

For me, the most important thing is consistency.  Right now we
do not remove infinite loops that are infinite because they have
no loop exit, but we do kill infinite loops that are infinite
because the exit condition can never be true.  We should either
remove all infinite loops, or none at all.

Gr.
Steven


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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 16:30     ` Richard Henderson
  2004-03-18 16:31       ` Diego Novillo
@ 2004-03-18 16:56       ` Geert Bosch
  1 sibling, 0 replies; 25+ messages in thread
From: Geert Bosch @ 2004-03-18 16:56 UTC (permalink / raw)
  To: Richard Henderson; +Cc: Zdenek Dvorak, gcc, Steven Bosscher, Diego Novillo


On Mar 18, 2004, at 11:26, Richard Henderson wrote:
> On Thu, Mar 18, 2004 at 09:31:39AM -0500, Diego Novillo wrote:
>> I've always hated this custom.  Is this a language mandate?  Or just
>> "we've always done it this way"?
>
> The later.  Lets stop this madness.

Richard, Diego was talking about removing infinite loops.
Of course this is an invalid transformation and I'm surprised
that anyone would think otherwise. Whether a program halts or
not  is the fundamental outcome of running it.

   -Geert

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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 16:34                 ` Geert Bosch
@ 2004-03-18 16:38                   ` Zdenek Dvorak
  2004-03-18 17:00                     ` Steven Bosscher
  0 siblings, 1 reply; 25+ messages in thread
From: Zdenek Dvorak @ 2004-03-18 16:38 UTC (permalink / raw)
  To: Geert Bosch; +Cc: gcc, Steven Bosscher, Joseph S. Myers

Hello,

> >OK, I may easily extend the loop optimizer to remove empty loops if
> >there is a demand for it (once dce is fixed so that it is not done
> >even in cases it is incorrect, as happens now).
> >
> 
> How is the loop in your example different from a call to
> a non-terminating function returning void? I don't see
> why the optimizers would handle that correctly and not
> the infinite loop. Could you explain?

I had in one of previous mails, but anyway:  for the function we see it
has side effects (nontermination), so we mark it as neccesary.  For the
loop we do not.

The solution is obvious -- mark the backedges of the loops for that we are
not able to prove that they have to terminate as well.

Zdenek

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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 16:26               ` Zdenek Dvorak
@ 2004-03-18 16:34                 ` Geert Bosch
  2004-03-18 16:38                   ` Zdenek Dvorak
  2004-03-18 18:11                 ` Dale Johannesen
  1 sibling, 1 reply; 25+ messages in thread
From: Geert Bosch @ 2004-03-18 16:34 UTC (permalink / raw)
  To: Zdenek Dvorak; +Cc: gcc, Steven Bosscher, Joseph S. Myers


On Mar 18, 2004, at 11:25, Zdenek Dvorak wrote:

> OK, I may easily extend the loop optimizer to remove empty loops if
> there is a demand for it (once dce is fixed so that it is not done
> even in cases it is incorrect, as happens now).
>

How is the loop in your example different from a call to
a non-terminating function returning void? I don't see
why the optimizers would handle that correctly and not
the infinite loop. Could you explain?

   -Geert

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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 16:30     ` Richard Henderson
@ 2004-03-18 16:31       ` Diego Novillo
  2004-03-18 16:56       ` Geert Bosch
  1 sibling, 0 replies; 25+ messages in thread
From: Diego Novillo @ 2004-03-18 16:31 UTC (permalink / raw)
  To: Richard Henderson; +Cc: Steven Bosscher, Zdenek Dvorak, gcc

On Thu, 2004-03-18 at 11:26, Richard Henderson wrote:
> On Thu, Mar 18, 2004 at 09:31:39AM -0500, Diego Novillo wrote:
> > I've always hated this custom.  Is this a language mandate?  Or just
> > "we've always done it this way"?
> 
> The later.  Lets stop this madness.
> 
*shrug*  I don't really care, but we had better have some empty loop
protection code then.  Apparently what we have now is not enough.


Diego.

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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 14:40   ` Diego Novillo
@ 2004-03-18 16:30     ` Richard Henderson
  2004-03-18 16:31       ` Diego Novillo
  2004-03-18 16:56       ` Geert Bosch
  0 siblings, 2 replies; 25+ messages in thread
From: Richard Henderson @ 2004-03-18 16:30 UTC (permalink / raw)
  To: Diego Novillo; +Cc: Steven Bosscher, Zdenek Dvorak, gcc

On Thu, Mar 18, 2004 at 09:31:39AM -0500, Diego Novillo wrote:
> I've always hated this custom.  Is this a language mandate?  Or just
> "we've always done it this way"?

The later.  Lets stop this madness.


r~

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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 16:23             ` Joseph S. Myers
@ 2004-03-18 16:26               ` Zdenek Dvorak
  2004-03-18 16:34                 ` Geert Bosch
  2004-03-18 18:11                 ` Dale Johannesen
  0 siblings, 2 replies; 25+ messages in thread
From: Zdenek Dvorak @ 2004-03-18 16:26 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: Geert Bosch, gcc, Steven Bosscher

Hello,

> > > It is important to remove loops that are empty, but can be shown
> > > to terminate. Even though programmers may not write such code,
> > > other optimizations may make all code invariant, resulting in an
> > > empty loop.
> > 
> > how often this happens? More precisely, could I see at least one
> > real-world example?
> 
> See the previous discussions that resulted in the change to the section of
> the manual explaining why we didn't remove empty loops, e.g.
> <http://gcc.gnu.org/ml/gcc/1998-05/msg00651.html> and thread,
> <http://gcc.gnu.org/ml/gcc/1998-06/msg00011.html> and (long) thread.  For
> example, the example in <http://gcc.gnu.org/ml/gcc/1998-06/msg00089.html>
> generates an empty loop just as it did in 1998, and the threads have other
> examples.

OK, I may easily extend the loop optimizer to remove empty loops if
there is a demand for it (once dce is fixed so that it is not done
even in cases it is incorrect, as happens now).

Zdenek

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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 16:18           ` Zdenek Dvorak
@ 2004-03-18 16:23             ` Joseph S. Myers
  2004-03-18 16:26               ` Zdenek Dvorak
  0 siblings, 1 reply; 25+ messages in thread
From: Joseph S. Myers @ 2004-03-18 16:23 UTC (permalink / raw)
  To: Zdenek Dvorak; +Cc: Geert Bosch, gcc, Steven Bosscher

On Thu, 18 Mar 2004, Zdenek Dvorak wrote:

> > It is important to remove loops that are empty, but can be shown
> > to terminate. Even though programmers may not write such code,
> > other optimizations may make all code invariant, resulting in an
> > empty loop.
> 
> how often this happens? More precisely, could I see at least one
> real-world example?

See the previous discussions that resulted in the change to the section of
the manual explaining why we didn't remove empty loops, e.g.
<http://gcc.gnu.org/ml/gcc/1998-05/msg00651.html> and thread,
<http://gcc.gnu.org/ml/gcc/1998-06/msg00011.html> and (long) thread.  For
example, the example in <http://gcc.gnu.org/ml/gcc/1998-06/msg00089.html>
generates an empty loop just as it did in 1998, and the threads have other
examples.

-- 
Joseph S. Myers
jsm@polyomino.org.uk

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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 15:38         ` Geert Bosch
@ 2004-03-18 16:18           ` Zdenek Dvorak
  2004-03-18 16:23             ` Joseph S. Myers
  0 siblings, 1 reply; 25+ messages in thread
From: Zdenek Dvorak @ 2004-03-18 16:18 UTC (permalink / raw)
  To: Geert Bosch; +Cc: gcc, Steven Bosscher

Hello,

> >the simple conservative solution is to mark all back edges as 
> >neccesary.
> >You can do a bit better and use the results of simple loop analysis to
> >avoid doing this for back edges of loops for that you are sure that 
> >they terminate.
> >But you won't gain much by this in practice, since people usually do 
> >not
> >write useless loops.  Also it is not clear whether people really want 
> >such
> >loop to be optimized out (they might write it in order to make the
> >program wait).
> 
> It is important to remove loops that are empty, but can be shown
> to terminate. Even though programmers may not write such code,
> other optimizations may make all code invariant, resulting in an
> empty loop.

how often this happens? More precisely, could I see at least one
real-world example?

> True, long ago GCC did keep such loops, but that policy has been
> explicitly reversed later on. If someone wants to keep a loop,
> just make sure it has some external effect such as writing to
> volatile memory.
> 
> I fail to see why you would need to have any special hacks to
> prevent infinite loops from being optimized away.

These are no special hacks. The problem that was missed here is
that nontermination is (an ugly kind of) side effect.  So there
is no fundamental difference between handling this and handling
any other statement that may cause something observable, except
for the value produced.

Zdenek

> What is the
> logic that causes this? There seems to be a more fundamental
> problem if the optimizers determine that the function would
> return 0. What if the loop was replaced with a call to a
> function that is marked non-terminating?

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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 13:17       ` Zdenek Dvorak
  2004-03-18 13:21         ` Paolo Carlini
@ 2004-03-18 15:38         ` Geert Bosch
  2004-03-18 16:18           ` Zdenek Dvorak
  1 sibling, 1 reply; 25+ messages in thread
From: Geert Bosch @ 2004-03-18 15:38 UTC (permalink / raw)
  To: Zdenek Dvorak; +Cc: gcc, Steven Bosscher


On Mar 18, 2004, at 08:12, Zdenek Dvorak wrote:
> the simple conservative solution is to mark all back edges as 
> neccesary.
> You can do a bit better and use the results of simple loop analysis to
> avoid doing this for back edges of loops for that you are sure that 
> they terminate.
> But you won't gain much by this in practice, since people usually do 
> not
> write useless loops.  Also it is not clear whether people really want 
> such
> loop to be optimized out (they might write it in order to make the
> program wait).

It is important to remove loops that are empty, but can be shown
to terminate. Even though programmers may not write such code,
other optimizations may make all code invariant, resulting in an
empty loop.

True, long ago GCC did keep such loops, but that policy has been
explicitly reversed later on. If someone wants to keep a loop,
just make sure it has some external effect such as writing to
volatile memory.

I fail to see why you would need to have any special hacks to
prevent infinite loops from being optimized away. What is the
logic that causes this? There seems to be a more fundamental
problem if the optimizers determine that the function would
return 0. What if the loop was replaced with a call to a
function that is marked non-terminating?

   -Geert

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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 12:34 ` Steven Bosscher
  2004-03-18 12:38   ` Zdenek Dvorak
@ 2004-03-18 14:40   ` Diego Novillo
  2004-03-18 16:30     ` Richard Henderson
  1 sibling, 1 reply; 25+ messages in thread
From: Diego Novillo @ 2004-03-18 14:40 UTC (permalink / raw)
  To: Steven Bosscher; +Cc: Zdenek Dvorak, gcc

On Thu, 2004-03-18 at 07:31, Steven Bosscher wrote:

> Removing an infinte loop is indeed wrong.  Hence this comment
> in tree-ssa-dce.c:
> 
>   /* Some blocks don't have an immediate post dominator.  This can happen
>      for example with infinite loops.  Removing an infinite loop is an
>      inappropriate transformation anyway...  */
> 
> If we remove that infinite loop, you found a bug.
> 
I've always hated this custom.  Is this a language mandate?  Or just
"we've always done it this way"?  Why not tell the user to use a
volatile index variable if they want the infinite loop?


Diego.

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

* RE: [tree-ssa] Dce & infinite loops
  2004-03-18 13:21         ` Paolo Carlini
@ 2004-03-18 14:03           ` Dave Korn
  0 siblings, 0 replies; 25+ messages in thread
From: Dave Korn @ 2004-03-18 14:03 UTC (permalink / raw)
  To: gcc


> -----Original Message-----
> From: gcc-owner On Behalf Of Paolo Carlini
> Sent: 18 March 2004 13:18

> Zdenek Dvorak wrote:
> 
> >But you won't gain much by this in practice, since people usually do 
> >not write useless loops.  Also it is not clear whether people really 
> >want such loop to be optimized out (they might write it in order to 
> >make the program wait).
> >  
> >
> Exactly: these two observations I remember perfectly from 
> that discussion.
> 
> Paolo.

  AFAIUI, anyone who writes a loop to make a delay is writing
non-standards-compliant code.  If you have a loop like

  for (i = 0; i < very_big_number; i++)
    /* do nothing but delay */ ;

then surely under the "as-if rule", the compiler is completely within its
rights to just replace it with

  i = very_big_number;

and so anyone expecting to get a delay loop is making a false assumption,
isn't it so?

  It's been bad engineering practice for many years now to assume a fixed
relationship between machine cycles and real time; it was OK on the CBM64 to
assume that each instruction was 1us, maybe, but in a world where CPUs range
from 486 to K8 to ppc and SH and beyond, and clocks vary from 50MHz to 3GHz,
and memory subsystems include 1, 2 or even 3 levels of caching..... it's
just borked.

[  I was going to butt into the PCH thread as well and mention that the last
time I coded for a system where you could actually *rely* on loading data
back into memory at the same address you wrote it out from, it was also the
C64.... ]

    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....

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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 13:17       ` Zdenek Dvorak
@ 2004-03-18 13:21         ` Paolo Carlini
  2004-03-18 14:03           ` Dave Korn
  2004-03-18 15:38         ` Geert Bosch
  1 sibling, 1 reply; 25+ messages in thread
From: Paolo Carlini @ 2004-03-18 13:21 UTC (permalink / raw)
  To: Zdenek Dvorak; +Cc: Steven Bosscher, gcc

Zdenek Dvorak wrote:

>But you won't gain much by this in practice, since people usually do not
>write useless loops.  Also it is not clear whether people really want such
>loop to be optimized out (they might write it in order to make the
>program wait).
>  
>
Exactly: these two observations I remember perfectly from that discussion.

Paolo.

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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 12:54     ` Steven Bosscher
@ 2004-03-18 13:17       ` Zdenek Dvorak
  2004-03-18 13:21         ` Paolo Carlini
  2004-03-18 15:38         ` Geert Bosch
  0 siblings, 2 replies; 25+ messages in thread
From: Zdenek Dvorak @ 2004-03-18 13:17 UTC (permalink / raw)
  To: Steven Bosscher; +Cc: gcc

Hello,

> > > > I may be wrong, but IIRC it is incorrect to remove infinite loops, as
> > > > happens currently for example for the following code:
> > > >
> > > > int main(void)
> > > > {
> > > >   unsigned i;
> > > >
> > > >   for (i = 1; i != 0; i+=2);
> > > >
> > > >   return 0;
> > > > }
> > >
> > > Removing an infinte loop is indeed wrong.  Hence this comment
> > > in tree-ssa-dce.c:
> > >
> > >   /* Some blocks don't have an immediate post dominator.  This can happen
> > >      for example with infinite loops.  Removing an infinite loop is an
> > >      inappropriate transformation anyway...  */
> > >
> > > If we remove that infinite loop, you found a bug.
> >
> > the problem is that the loop in the example above has an exit (that is
> > never taken); therefore the code in tree-ssa-dce.c you cite does not
> > handle it.
> 
> I know, and I'm not sure how to deal with this.  It seems kind of silly
> to need something like IV/loop analysis to decide whether or not some
> code is dead.

the simple conservative solution is to mark all back edges as neccesary.
You can do a bit better and use the results of simple loop analysis to
avoid doing this for back edges of loops for that you are sure that they terminate.
But you won't gain much by this in practice, since people usually do not
write useless loops.  Also it is not clear whether people really want such
loop to be optimized out (they might write it in order to make the
program wait).

Zdenek

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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 12:38   ` Zdenek Dvorak
@ 2004-03-18 12:54     ` Steven Bosscher
  2004-03-18 13:17       ` Zdenek Dvorak
  0 siblings, 1 reply; 25+ messages in thread
From: Steven Bosscher @ 2004-03-18 12:54 UTC (permalink / raw)
  To: Zdenek Dvorak; +Cc: gcc

On Thursday 18 March 2004 13:34, Zdenek Dvorak wrote:
> Hello,
>
> > > I may be wrong, but IIRC it is incorrect to remove infinite loops, as
> > > happens currently for example for the following code:
> > >
> > > int main(void)
> > > {
> > >   unsigned i;
> > >
> > >   for (i = 1; i != 0; i+=2);
> > >
> > >   return 0;
> > > }
> >
> > Removing an infinte loop is indeed wrong.  Hence this comment
> > in tree-ssa-dce.c:
> >
> >   /* Some blocks don't have an immediate post dominator.  This can happen
> >      for example with infinite loops.  Removing an infinite loop is an
> >      inappropriate transformation anyway...  */
> >
> > If we remove that infinite loop, you found a bug.
>
> the problem is that the loop in the example above has an exit (that is
> never taken); therefore the code in tree-ssa-dce.c you cite does not
> handle it.

I know, and I'm not sure how to deal with this.  It seems kind of silly
to need something like IV/loop analysis to decide whether or not some
code is dead.  What do other compilers do with your example?

Gr.
Steven



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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 12:34 ` Steven Bosscher
@ 2004-03-18 12:38   ` Zdenek Dvorak
  2004-03-18 12:54     ` Steven Bosscher
  2004-03-18 14:40   ` Diego Novillo
  1 sibling, 1 reply; 25+ messages in thread
From: Zdenek Dvorak @ 2004-03-18 12:38 UTC (permalink / raw)
  To: Steven Bosscher; +Cc: gcc

Hello,

> > I may be wrong, but IIRC it is incorrect to remove infinite loops, as
> > happens currently for example for the following code:
> >
> > int main(void)
> > {
> >   unsigned i;
> >
> >   for (i = 1; i != 0; i+=2);
> >
> >   return 0;
> > }
> 
> Removing an infinte loop is indeed wrong.  Hence this comment
> in tree-ssa-dce.c:
> 
>   /* Some blocks don't have an immediate post dominator.  This can happen
>      for example with infinite loops.  Removing an infinite loop is an
>      inappropriate transformation anyway...  */
> 
> If we remove that infinite loop, you found a bug.

the problem is that the loop in the example above has an exit (that is
never taken); therefore the code in tree-ssa-dce.c you cite does not
handle it.

Zdenek

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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 12:29 Zdenek Dvorak
  2004-03-18 12:29 ` Paolo Carlini
@ 2004-03-18 12:34 ` Steven Bosscher
  2004-03-18 12:38   ` Zdenek Dvorak
  2004-03-18 14:40   ` Diego Novillo
  1 sibling, 2 replies; 25+ messages in thread
From: Steven Bosscher @ 2004-03-18 12:34 UTC (permalink / raw)
  To: Zdenek Dvorak; +Cc: gcc

On Thursday 18 March 2004 13:21, Zdenek Dvorak wrote:
> Hello,
>
> I may be wrong, but IIRC it is incorrect to remove infinite loops, as
> happens currently for example for the following code:
>
> int main(void)
> {
>   unsigned i;
>
>   for (i = 1; i != 0; i+=2);
>
>   return 0;
> }

Removing an infinte loop is indeed wrong.  Hence this comment
in tree-ssa-dce.c:

  /* Some blocks don't have an immediate post dominator.  This can happen
     for example with infinite loops.  Removing an infinite loop is an
     inappropriate transformation anyway...  */

If we remove that infinite loop, you found a bug.

Gr.
Steven


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

* Re: [tree-ssa] Dce & infinite loops
  2004-03-18 12:29 Zdenek Dvorak
@ 2004-03-18 12:29 ` Paolo Carlini
  2004-03-18 12:34 ` Steven Bosscher
  1 sibling, 0 replies; 25+ messages in thread
From: Paolo Carlini @ 2004-03-18 12:29 UTC (permalink / raw)
  To: Zdenek Dvorak; +Cc: stevenb, gcc

Zdenek Dvorak wrote:

>Hello,
>
>I may be wrong, but IIRC it is incorrect to remove infinite loops, as
>happens currently for example for the following code:
>  
>
Hi Zdenek, a naive reply: I'm almost sure to remember messages pointing
out that in fact we don't want to remove infinite loop and even finite but
redundant ones (empty body).

I will try to dig out something from the archive.

Paolo.

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

* [tree-ssa] Dce & infinite loops
@ 2004-03-18 12:29 Zdenek Dvorak
  2004-03-18 12:29 ` Paolo Carlini
  2004-03-18 12:34 ` Steven Bosscher
  0 siblings, 2 replies; 25+ messages in thread
From: Zdenek Dvorak @ 2004-03-18 12:29 UTC (permalink / raw)
  To: stevenb; +Cc: gcc

Hello,

I may be wrong, but IIRC it is incorrect to remove infinite loops, as
happens currently for example for the following code:

int main(void)
{
  unsigned i;

  for (i = 1; i != 0; i+=2);

  return 0;
}

Zdenek

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

end of thread, other threads:[~2004-03-18 21:39 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-18 14:51 [tree-ssa] Dce & infinite loops Richard Guenther
2004-03-18 15:26 ` Paolo Carlini
  -- strict thread matches above, loose matches on Subject: below --
2004-03-18 12:29 Zdenek Dvorak
2004-03-18 12:29 ` Paolo Carlini
2004-03-18 12:34 ` Steven Bosscher
2004-03-18 12:38   ` Zdenek Dvorak
2004-03-18 12:54     ` Steven Bosscher
2004-03-18 13:17       ` Zdenek Dvorak
2004-03-18 13:21         ` Paolo Carlini
2004-03-18 14:03           ` Dave Korn
2004-03-18 15:38         ` Geert Bosch
2004-03-18 16:18           ` Zdenek Dvorak
2004-03-18 16:23             ` Joseph S. Myers
2004-03-18 16:26               ` Zdenek Dvorak
2004-03-18 16:34                 ` Geert Bosch
2004-03-18 16:38                   ` Zdenek Dvorak
2004-03-18 17:00                     ` Steven Bosscher
2004-03-18 17:25                       ` Zdenek Dvorak
2004-03-18 17:30                         ` Dave Korn
2004-03-18 18:11                 ` Dale Johannesen
2004-03-18 21:45                   ` Alex Rosenberg
2004-03-18 14:40   ` Diego Novillo
2004-03-18 16:30     ` Richard Henderson
2004-03-18 16:31       ` Diego Novillo
2004-03-18 16:56       ` Geert Bosch

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