This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/81834] New: Simple loop with single variable is not optimized out


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81834

            Bug ID: 81834
           Summary: Simple loop with single variable is not optimized out
           Product: gcc
           Version: 7.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: geoffrey at allott dot email
  Target Milestone: ---

The following code:

int main() {
    for(int i=0; i += i < 1000, i < 1000;);
}

optimizes on x86_64 to the following code:

main:
.LFB0:
    xorl    %eax, %eax
.L2:
    xorl    %edx, %edx
    cmpl    $999, %eax
    setle   %dl
    addl    %edx, %eax
    cmpl    $999, %eax
    jle .L2
    xorl    %eax, %eax
    ret

I would expect the loop to be removed completely.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]