https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117033
Bug ID: 117033 Summary: GCC trunk emits larger code at -Oz compared to -O2 Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: dccitaliano at gmail dot com Target Milestone: --- long patatino() { long x = 0; for (int i = 0; i < 5; ++i) { while (x < 37) { if (x % 4 == 0) { x += 4; } } } return x; } -Oz: patatino(): pushq $5 xorl %eax, %eax popq %rdx .L5: cmpq $36, %rax jg .L7 addq $4, %rax jmp .L5 .L7: decl %edx jne .L5 ret -O2: patatino(): movl $40, %eax ret https://godbolt.org/z/969sf9cfb Believe this is a pass ordering problem -- might be that simplifying the loop isn't always beneficial.