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; } }
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.
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
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
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~
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.