This is the mail archive of the
mailing list for the GCC project.
Empty loop elimination in 4.0 ?
- From: Michael Veksler <VEKSLER at il dot ibm dot com>
- To: gcc at gcc dot gnu dot org
- Date: Sun, 9 Jan 2005 22:33:05 +0200
- Subject: Empty loop elimination in 4.0 ?
In the days of gcc-2.6.x the documentation of gcc said that empty loops
were not eliminated. The docs used to say that this was on purpose -
because empty loops were being used as delay loops.
Does this ancient and not portable delay-loop hack still work with
gcc version 4.0.0 20050102 (experimental) ?
int f(int i)
int a = 0;
for (j=0 ; j < 100 ; ++j)
For this code, gcc finds out that 'a' is dead, and it almost eliminates
the inner loop. Yet, the inner loop is not eliminated, and it is not
moved out of the outer loop.
I think that the above code should have been transformed to something
int f(int i)
This is not a regression, because this is the way gcc-3.4.2 does it. Still
"fixing" this may result in performance improvements that may offset
one or two performance regressions.
Here is the relevant part of the asm (gcc -O2 t.c -s):
movl $100, %eax
movl %ecx, %eax
subl %edx, %eax
testl %eax, %eax
On the bright side, at least it does not try to unroll the outer loop
like it did with gcc-3.4.2 (gcc-3.4 copies the inner loop over and over).
I came to this example by examining some tail recursion code - that
was badly optimized (bad on itself, without comparing it to any other
compiler or version).