Bug 964 - missed warning and optimization
Summary: missed warning and optimization
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 2.95.2
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2000-12-02 16:56 UTC by benoit.hudson
Modified: 2003-11-16 01:47 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description benoit.hudson 2000-12-02 16:56:00 UTC
In the code in how-to-repeat, gcc -O2 -Wall doesn't warn 
about the unused variable x.  It does optimize it
away.

However, it does not optimize away the entire loop, which
would be slightly nice.

Release:
2.95.2

How-To-Repeat:
void foo(int n) {
    int i, x;
    for(i=0; i<n; i++) {
        x = 1;
    }
}
Comment 1 Richard Henderson 2001-01-16 02:51:49 UTC
State-Changed-From-To: open->suspended
State-Changed-Why: (1) The variable X is not unused -- you assigned to it.
    
    (2) The loop is removed in current snapshots with 
        -fssa -fdce, which is not the default at -ON
        because of various problems remaining in that
        code wrt unfriendly constructs generated by some
        ports.  Some day that will get fixed.
Comment 2 Richard Henderson 2001-01-16 10:51:49 UTC
From: rth@gcc.gnu.org
To: bh@techhouse.brown.edu, gcc-gnats@gcc.gnu.org, nobody@gcc.gnu.org
Cc:  
Subject: Re: optimization/964
Date: 16 Jan 2001 10:51:49 -0000

 Synopsis: missed warning and optimization
 
 State-Changed-From-To: open->suspended
 State-Changed-By: rth
 State-Changed-When: Tue Jan 16 02:51:49 2001
 State-Changed-Why:
     (1) The variable X is not unused -- you assigned to it.
     
     (2) The loop is removed in current snapshots with 
         -fssa -fdce, which is not the default at -ON
         because of various problems remaining in that
         code wrt unfriendly constructs generated by some
         ports.  Some day that will get fixed.
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=964&database=gcc

Comment 3 benoit.hudson 2001-01-16 17:03:02 UTC
From: Benoit Hudson <bh@techhouse.brown.edu>
To: rth@gcc.gnu.org
Cc: gcc-gnats@gcc.gnu.org, nobody@gcc.gnu.org
Subject: Re: optimization/964
Date: Tue, 16 Jan 2001 17:03:02 -0500

 On Tue, Jan 16, 2001 at 10:51:49AM -0000, rth@gcc.gnu.org wrote:
 >     (1) The variable X is not unused -- you assigned to it.
 
 But I never read it.  By comparison:
         void foo() {
             int x = 1;
         }
 x is unused.
 
 Although it's true that:
         void foo() {
             int x;
             x = 1;
         }
 doesn't warn.
 
         -- Benoît

Comment 4 Richard Henderson 2001-01-16 18:50:23 UTC
From: Richard Henderson <rth@redhat.com>
To: Benoit Hudson <bh@techhouse.brown.edu>
Cc: rth@gcc.gnu.org, gcc-gnats@gcc.gnu.org, nobody@gcc.gnu.org
Subject: Re: optimization/964
Date: Tue, 16 Jan 2001 18:50:23 -0800

 On Tue, Jan 16, 2001 at 05:03:02PM -0500, Benoit Hudson wrote:
 > >     (1) The variable X is not unused -- you assigned to it.
 > 
 > But I never read it.
 
 Doesn't matter.  All the flag does is see if the variable is
 used in any context after its declaration.  A write counts.
 And, in particular, uses inside dead code counts.
 
 
 r~
Comment 5 Andrew Pinski 2003-11-16 01:47:10 UTC
From <http://gcc.gnu.org/onlinedocs/gcc/Non-bugs.html#Non-bugs> "Certain Changes We Don't 
Want to Make":
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.