AArch64 currently does not have a legitimize address hook to find better
solutions for loading from addresses that are not valid.  The current
approach 'gets away with it' much of the time because we currently split
constants during expand.  We might change that soon, since it is
inhibits other optimizations.  Even so, there are some cases where we
don't get code that is as good as it can be.  Consider:
typedef double t;

t f(char *a)
{
  return *(t*)(a+4093) + *(t*)(a+4266);
}

This currently expands to

        add     x1, x0, 4093
        add     x0, x0, 4096
        ldr     d1, [x1]
        ldr     d0, [x0,170]
        fadd    d0, d1, d0
        ret

With the patch, we now get

        add     x0, x0, 4096
        ldr     d1, [x0,-3]
        ldr     d0, [x0,170]
        fadd    d0, d1, d0
        ret

Saving us an instruction.

        * aarch64.c (aarch64_legitimize_address): New function
        (TARGET_LEGITIMIZE_ADDRESS): Redefine.

Bootstrapped and tested; committed to trunk.

R.

Reply via email to