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
          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:

    xorl    %eax, %eax
    xorl    %edx, %edx
    cmpl    $999, %eax
    setle   %dl
    addl    %edx, %eax
    cmpl    $999, %eax
    jle .L2
    xorl    %eax, %eax

I would expect the loop to be removed completely.

Reply via email to