[AArch64] Improve TARGET_LEGITIMIZE_ADDRESS_P hook
authorJiong Wang <jiong.wang@arm.com>
Fri, 1 Aug 2014 15:17:03 +0000 (15:17 +0000)
committerJiong Wang <jiwang@gcc.gnu.org>
Fri, 1 Aug 2014 15:17:03 +0000 (15:17 +0000)
currently, aarch64 LEGITIMIZE_ADDRESS_P hook will reject all "reg + offset"
address given "offset" is beyond supported range.

while this may be too strict. we should honor the "strict_p" parameter in the
hook. before reload, we accept all offset if it's a frame access, because the
offset may change during later register elimination.

the early reject of "reg + offset" may cause extra registers created, and if
that register live range is across function invoking then callee saved reg
needed, thus introduce extra reg save/restore also.

give a simple example as:

int
test15 (void)
{
   unsigned char a[480];
   initialize_array (a, 480);

   if (a[0] == 0x10)
     return 1;

   return 0;
}

.S before the patch
(-O2 -fPIC)
===
test15:
         sub     sp, sp, #480
         mov     w1, 480
         stp     x29, x30, [sp, -32]!
         add     x29, sp, 0
         str     x19, [sp, 16]
         add     x19, x29, 32
         mov     x0, x19
         bl      initialize_array
         ldrb    w0, [x19]
         ldr     x19, [sp, 16]
         ldp     x29, x30, [sp], 32
         cmp     w0, 16
         cset    w0, eq
         add     sp, sp, 480
         ret

.S after the patch
===
test15:
         stp     x29, x30, [sp, -496]!
         mov     w1, 480
         add     x29, sp, 0
         add     x0, x29, 16
         bl      initialize_array
         ldrb    w0, [x29, 16]
         ldp     x29, x30, [sp], 496
         cmp     w0, 16
         cset    w0, eq
         ret

gcc/
  * config/aarch64/aarch64.c (aarch64_classify_address): Accept all offset for
  frame access when strict_p is false.

gcc/testsuite
   * gcc.target/aarch64/legitimize_stack_var_before_reload_1.c: New testcase.

From-SVN: r213488

gcc/ChangeLog
gcc/config/aarch64/aarch64.c
gcc/testsuite/ChangeLog

index 3782894ce8509e1d823593cbc6e410aea01186d5..f9671110d089a464052a7ae18bd4f9a6bc624c2e 100644 (file)
@@ -1,3 +1,8 @@
+2014-08-01  Jiong Wang <jiong.wang@arm.com>
+
+       * config/aarch64/aarch64.c (aarch64_classify_address): Accept all offset
+       for frame access when strict_p is false.
+
 2014-08-01  Renlin Li <renlin.li@arm.com>
 2014-08-01  Jiong Wang <jiong.wang@arm.com>
 
index d3f2adbc7011a511efd52199e1da60d84d39bec2..7e135a19ada5d3590f814c4e92074555c3727852 100644 (file)
@@ -3248,6 +3248,21 @@ aarch64_classify_address (struct aarch64_address_info *info,
     case PLUS:
       op0 = XEXP (x, 0);
       op1 = XEXP (x, 1);
+
+      if (! strict_p
+         && GET_CODE (op0) == REG
+         && (op0 == virtual_stack_vars_rtx
+             || op0 == frame_pointer_rtx
+             || op0 == arg_pointer_rtx)
+         && GET_CODE (op1) == CONST_INT)
+       {
+         info->type = ADDRESS_REG_IMM;
+         info->base = op0;
+         info->offset = op1;
+
+         return true;
+       }
+
       if (GET_MODE_SIZE (mode) != 0
          && CONST_INT_P (op1)
          && aarch64_base_register_rtx_p (op0, strict_p))
index e29098f52ab49f76d74657efaed86196225e4340..cc4e3d1e367cfc059d46faba567486776d5e8454 100644 (file)
@@ -1,3 +1,8 @@
+2014-08-01  Jiong Wang  <jiong.wang@arm.com>
+
+       * gcc.target/aarch64/legitimize_stack_var_before_reload_1.c: New
+       testcase.
+
 2014-08-01  Richard Biener  <rguenther@suse.de>
 
        PR middle-end/61762