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.