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

            Bug ID: 128467
           Summary: Missed register allocation optimization around stack
                    allocated addresses
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: ra
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: avieira at gcc dot gnu.org
  Target Milestone: ---
            Target: aarch64

Using the following testcase:

test.c:
typedef unsigned int flags_t;

extern void use_buffers(char *, char *, long);
extern int predicate(long);

__attribute__((noinline, used)) flags_t *
stack_flags(long a0, long a1, long a2, long a3, long a4, long a5, long a6,
            long a7, flags_t *flags) {
  char min_key[4096];
  char max_key[4096];

  if (predicate(a6))
    *flags |= 0x10;
  use_buffers(min_key, max_key, a0);
}

Compiled with
$ gcc -O3 -march=armv8-a -fomit-frame-pointer -g0 test.c -S

you'll see:
        ldr     x0, [sp, 8208]
        ldr     x1, [sp, 8208]
        ldr     w0, [x0]
        orr     w0, w0, 16
        str     w0, [x1]

where the same address get's loaded off the stack twice, back-to-back, though
there is no need as the same code could've been written as:

        ldr     x0, [sp, 8288]
        ldr     w1, [x0]
        orr     w1, w1, 16
        str     w1, [x0]

Reply via email to