public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug optimization/12468] New: empty loop not eliminated as dead code
@ 2003-09-30 19:55 bh at techhouse dot brown dot edu
  2003-09-30 19:56 ` [Bug optimization/12468] " pinskia at gcc dot gnu dot org
  2003-09-30 22:28 ` bh at techhouse dot brown dot edu
  0 siblings, 2 replies; 3+ messages in thread
From: bh at techhouse dot brown dot edu @ 2003-09-30 19:55 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12468

           Summary: empty loop not eliminated as dead code
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bh at techhouse dot brown dot edu
                CC: gcc-bugs at gcc dot gnu dot org

The following two trivial loops are not eliminated as dead code in 3.3.1 using
-O2.  The former (foo) is eliminated using -O2 -funroll-loops, but I'd rather
hope that I could eliminate dead code like this without also unrolling all my
loops.  Also, -funroll-loops does horrible things to the latter loop (bar).

void foo() {
   int i;
   for(i=0;i<10;++i);
}
void bar(int n) {
    int i;
    for(i=0;i<n;++i);
}


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

* [Bug optimization/12468] empty loop not eliminated as dead code
  2003-09-30 19:55 [Bug optimization/12468] New: empty loop not eliminated as dead code bh at techhouse dot brown dot edu
@ 2003-09-30 19:56 ` pinskia at gcc dot gnu dot org
  2003-09-30 22:28 ` bh at techhouse dot brown dot edu
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-09-30 19:56 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12468


pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


------- Additional Comments From pinskia at gcc dot gnu dot org  2003-09-30 19:36 -------
Not a bug see: <http://gcc.gnu.org/onlinedocs/gcc/Non-bugs.html>:
Deleting "empty" loops.       

Historically, GCC has not deleted "empty" loops under the assumption that the most likely reason 
you would put one in a program is to have a delay, so deleting them will not make real programs 
run any faster.       

However, the rationale here is that optimization of a nonempty loop cannot produce an empty one, 
which holds for C but is not always the case for C++.       

Moreover, with -funroll-loops small "empty" loops are already removed, so the current behavior is 
both sub-optimal and inconsistent and will change in the future.


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

* [Bug optimization/12468] empty loop not eliminated as dead code
  2003-09-30 19:55 [Bug optimization/12468] New: empty loop not eliminated as dead code bh at techhouse dot brown dot edu
  2003-09-30 19:56 ` [Bug optimization/12468] " pinskia at gcc dot gnu dot org
@ 2003-09-30 22:28 ` bh at techhouse dot brown dot edu
  1 sibling, 0 replies; 3+ messages in thread
From: bh at techhouse dot brown dot edu @ 2003-09-30 22:28 UTC (permalink / raw)
  To: gcc-bugs

PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12468



------- Additional Comments From bh at techhouse dot brown dot edu  2003-09-30 20:14 -------
Subject: Re:  empty loop not eliminated as dead code

On Tue, Sep 30, 2003 at 07:36:55PM -0000, pinskia at gcc dot gnu dot org wrote:
> Deleting "empty" loops.
>
> Historically, GCC has not deleted "empty" loops under the assumption
> that the most likely reason you would put one in a program is to have
> a delay, so deleting them will not make real programs run any faster.
>
> However, the rationale here is that optimization of a nonempty loop
> cannot produce an empty one, which holds for C but is not always the
> case for C++.

This is false even for C: it's not too hard to create a case where all
the statements inside the loop can be hoisted out (everything is
loop-invariant or based on iteration variables) -- especially with
ifdefs, if(CONSTANT), or with the pure and const function attributes.  I
filed a bug report for an "empty" loop because gcc was only not killing
the loop; it hoisted all the code out of my loop just fine.

If the programmer is wanting to waste time, the programmer should
declare i to be volatile.  Perhaps gcc should also support
-fno-delete-empty-loops to support legacy code.


> Moreover, with -funroll-loops small "empty" loops are already removed,
> so the current behavior is both sub-optimal and inconsistent and will
> change in the future.

If the current behaviour is slated to be fixed, should it not be a bug
report / feature request entered into bugzilla?


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

end of thread, other threads:[~2003-09-30 20:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-30 19:55 [Bug optimization/12468] New: empty loop not eliminated as dead code bh at techhouse dot brown dot edu
2003-09-30 19:56 ` [Bug optimization/12468] " pinskia at gcc dot gnu dot org
2003-09-30 22:28 ` bh at techhouse dot brown dot edu

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