The PLUS handling in aarch64_rtx_costs only checked for nonnegative
constants, meaning that simple immediate subtractions like:

  (set (reg R1) (plus (reg R2) (const_int -8)))

had a cost of two instructions.

Tested on aarch64-linux-gnu (with and without SVE).  OK to install?

Richard


2019-09-23  Richard Sandiford  <richard.sandif...@arm.com>

gcc/
        * config/aarch64/aarch64.c (aarch64_rtx_costs): Use
        aarch64_plus_immediate rather than aarch64_uimm12_shift
        to test for valid PLUS immediates.

Index: gcc/config/aarch64/aarch64.c
===================================================================
--- gcc/config/aarch64/aarch64.c        2019-09-23 10:22:47.000000000 +0100
+++ gcc/config/aarch64/aarch64.c        2019-09-23 10:43:41.652295538 +0100
@@ -10753,7 +10753,7 @@ aarch64_rtx_costs (rtx x, machine_mode m
          }
 
        if (GET_MODE_CLASS (mode) == MODE_INT
-           && ((CONST_INT_P (op1) && aarch64_uimm12_shift (INTVAL (op1)))
+           && (aarch64_plus_immediate (op1, mode)
                || aarch64_sve_addvl_addpl_immediate (op1, mode)))
          {
            *cost += rtx_cost (op0, mode, PLUS, 0, speed);

Reply via email to