https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78343
Bug ID: 78343 Summary: Loop is not eliminated Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: krister.walfridsson at gmail dot com Target Milestone: --- GCC 6 and trunk generates inefficient code for the loop unsigned int test(unsigned int quant) { unsigned int sum = 0; for (unsigned int i = 0; i < quant; ++i){ sum += quant; } return sum; } as noted in the tweet https://twitter.com/lefticus/status/797593368037642244?s=09. This is a regression introduced in r233207; GCC used to generate test: movl %edi, %eax imull %edi, %eax ret before r233207, and it generates a meaningless loop test: testl %edi, %edi je .L4 xorl %edx, %edx .L3: addl $1, %edx cmpl %edx, %edi jne .L3 movl %edi, %eax imull %edi, %eax ret .L4: xorl %eax, %eax ret after that change.