[Bug c++/108058] New: Missed optimization with O3 and m32 when unwinding a loop

pionere at freemail dot hu gcc-bugzilla@gcc.gnu.org
Sun Dec 11 12:11:45 GMT 2022


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

            Bug ID: 108058
           Summary: Missed optimization with O3 and m32 when unwinding a
                    loop
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pionere at freemail dot hu
  Target Milestone: ---

An unwinded loop produces a suboptimal code with O3 and m32 flags.
Example:

#include <stdint.h>
void copyFunc(uint8_t* dst, uint8_t* src, int n)
{
    while (n > 0) {
        *(uint32_t*)dst = *(uint32_t*)src;
        dst += 4;
        src += 4;
        n--;
    }
}

Since v 4.9.4 the loop is unwinded and produces two return points:
...
.L1:
        pop     ebx
        pop     esi
        pop     edi
        ret
...
        pop     ebx
        pop     esi
        pop     edi
        ret

Apparently this does not seem to happen if m32 is not set (probably there are
enough registers to use).


More information about the Gcc-bugs mailing list