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

            Bug ID: 124339
           Summary: ARM64 -O3 (ftree-vectorize) giant assembly with inc
                    inside the loop condition
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: szuplak at gmail dot com
  Target Milestone: ---

If we use the incrementation operator inside the loop condition,
for the ARM64 gcc 15 compiled with O3  (ftree-vectorize) generates 178 lines of
assembly (the example below.)
Compiled with -O2 or -O3 -f-no-tree-vectorize generates only 16 lines.

Looks normal on gcc 15 with x86-64 and MIPS64. 
GCC 14 with ARM64 also creates normal assembly for ARM64 so looks like only v15
is affected.

Example - 178 lines of assembly
int foo(const char* s, int size)
{
  while((*s++) && (--size > 0)) {
  }
  return size;
}

However If I move one of the operation to the loop body like that:
int foo(const char* s, int size)
{
  while((*s) && (--size > 0)) {
    s++;
  }
  return size;
}

The assembly is normal size

Reply via email to