Bug 17640 - empty loop not removed after optimization
empty loop not removed after optimization
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: tree-optimization
3.4.2
: P3 enhancement
: 4.1.0
Assigned To: Not yet assigned to anyone
: missed-optimization
: 18648 (view as bug list)
Depends on:
Blocks: 19639 22325
  Show dependency treegraph
 
Reported: 2004-09-23 21:13 UTC by Wouter Vermaelen
Modified: 2005-07-12 00:01 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-05-11 13:15:59


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wouter Vermaelen 2004-09-23 21:13:44 UTC
gcc can optimize this program quite well. However the remaining empty loop is a 
bit silly.  
  
 
int f() { return 1; }  
  
int main() {  
  int a = 0;  
  for (int i = 0; i < 100; ++i) {  
    a += f();  
  }  
  return a;  
}  
 
 
> gcc loop.c -O3 -S 
  
main:   pushl   %ebp  
        movl    %esp, %ebp  
        subl    $8, %esp  
        andl    $-16, %esp  
        subl    $16, %esp  
        movl    $99, %eax  
.L7:    decl    %eax  
        jns     .L7  
        movl    $100, %eax  
        leave  
        ret
Comment 1 Andrew Pinski 2004-09-23 23:01:45 UTC
Confirmed but not the documentation says we don't want this but that has changed.
Comment 2 Andrew Pinski 2004-12-24 02:26:41 UTC
*** Bug 18648 has been marked as a duplicate of this bug. ***
Comment 3 Richard Biener 2005-01-28 14:26:21 UTC
One patch for empty-loop removal was posted here by Zdenek
http://gcc.gnu.org/ml/gcc-patches/2004-07/msg01679.html
Comment 4 Steven Bosscher 2005-01-28 15:18:30 UTC
That patch is just gross.  Come on, builtin_maybe_infinite_loop?!

There are better and easier ways to kill dead loops.  Like, a loop
optimizer that simply removes dead loops ;-)
Comment 5 Giovanni Bajo 2005-05-11 12:58:23 UTC
This is a most-wanted feature. Are there hope to see a patch landing for 4.1? 
Can the patch that Zdenek posted be updated for 4.1? Even if it's gross is 
surely better than nothing...
Comment 6 Andrew Pinski 2005-05-11 13:00:04 UTC
I should note that loops with small constants bounds are now removed on the mainline.
Comment 7 Richard Biener 2005-05-11 13:02:48 UTC
Only because they are completely peeled.
Comment 8 Steven Bosscher 2005-05-11 13:14:08 UTC
Subject: Re:  empty loop not removed after optimization

On Wednesday 11 May 2005 14:58, giovannibajo at libero dot it wrote:
> ------- Additional Comments From giovannibajo at libero dot it  2005-05-11
> 12:58 ------- This is a most-wanted feature. Are there hope to see a patch
> landing for 4.1? Can the patch that Zdenek posted be updated for 4.1? Even
> if it's gross is surely better than nothing...

nothing is better than gross.
Comment 9 Steven Bosscher 2005-05-11 13:15:58 UTC
I'll hack up something. 
Comment 10 Steven Bosscher 2005-06-30 21:48:17 UTC
Zdenek has a patch: 
http://gcc.gnu.org/ml/gcc-patches/2005-06/msg02270.html 
Comment 11 Andrew Pinski 2005-07-12 00:01:20 UTC
Fixed in 4.1.0.