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

            Bug ID: 118732
           Summary: [15 regression] caller-saves optimization can inhibit
                    shrink wrapping
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rearnsha at gcc dot gnu.org
                CC: jskumari at gcc dot gnu.org, vmakarov at redhat dot com
  Target Milestone: ---
            Target: arm aarch64

The patch to fix PR111673 introduced a regression on Arm and AArch64 (and maybe
elsewhere) in that we now more aggressively generate caller-save registers, but
can place them before an early branch.  This means that the shrink wrap code
cannot operate properly as it cannot save the register before the initial
branch unless the stack frame has been set up.

Consider for example:

void f(int *i)
{
        if (!i)
                return;
        else
        {
                __builtin_printf("Hi");
                *i=0;
        }
}

In gcc-14 this would be shrink-wrapped to give

cbz x0, done
...
body
...
done: ret

With gcc-15 there is a store of the parameter i onto the stack, but this is
placed before the conditional branch and this is enough to block
shrink-wrapping

str  x0, [sp, offset]
cbz  x0, done
...
body
...

It's not clear to me why the store has to be placed before the branch: the
stack slot is dead if we do not enter body, so this is worse code anyway even
if we don't shrink wrap.

Reply via email to