public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* [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
* 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

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 12:29 [tree-ssa] Dce & infinite loops 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
2004-03-18 14:51 Richard Guenther
2004-03-18 15:26 ` Paolo Carlini

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