[Bug optimization/10620] for(i=25000;i;i--) {} generates wrong assembly source in avr-gcc with -O2

eric@ecentral.com gcc-bugzilla@gcc.gnu.org
Thu May 22 18:48:00 GMT 2003


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

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


eric@ecentral.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eric@ecentral.com


------- Additional Comments From eric@ecentral.com  2003-05-22 18:43 -------
I can confirm that this is what this version / target of GCC produces. But I 
wouldn't describe it as a bug. 

This is a do-nothing loop and really should be optimized away. If the i and j 
variables are set to volatile it seems to generate correct code. If the 
optimization is set to -O1, then this is probably the code that the submitter 
was looking for. At -O2, it aggressively optimizes the decrement step in the 
inner loop, as the loop does nothing. If the code is changed to do something, 
such as:

int main(void)
{
    unsigned int i;
    unsigned int j;
    volatile unsigned int a;
    for(j=500;j;j--) 
    {
        for(i=25000;i;i--) 
        {
            a = i;
        }
    }
    
    return(0);
}

Then GCC generates correct decrement steps in the inner loop at -O2.

I would suggest:
Status = Resolved
Resolution = Invalid

Eric Weddington
Admin for WinAVR (GCC AVR target / Windows Host)



------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.



More information about the Gcc-bugs mailing list