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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-01-19
           Keywords|ra                          |
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Rs6000 has:
      /* On the RS/6000, if it is valid in the insn, it is free.  */
    case CONST_INT:
      if (((outer_code == SET
            || outer_code == PLUS
            || outer_code == MINUS)
           && (satisfies_constraint_I (x)
               || satisfies_constraint_L (x)))


While aarch64 has:
      /* If an instruction can incorporate a constant within the
         instruction, the instruction's expression avoids calling
         rtx_cost() on the constant.  If rtx_cost() is called on a
         constant, then it is usually because the constant must be
         moved into a register by one or more instructions.

         The exception is constant 0, which can be expressed
         as XZR/WZR and is therefore free.  The exception to this is
         if we have (set (reg) (const0_rtx)) in which case we must cost
         the move.  However, we can catch that when we cost the SET, so
         we don't need to consider that here.  */
      if (x == const0_rtx)
        *cost = 0;
      else
        {
          /* To an approximation, building any other constant is
             proportionally expensive to the number of instructions
             required to build that constant.  This is true whether we
             are compiling for SPEED or otherwise.  */
          if (!is_a <scalar_int_mode> (mode, &int_mode))
            int_mode = word_mode;
          *cost = COSTS_N_INSNS (aarch64_internal_mov_immediate
                                 (NULL_RTX, x, false, int_mode));
        }


I think rs6000 definition should be used instead otherwise we get the case
where (set (reg) (reg)) is the same cost as (set (reg) (const_int)) so GCC
decides it is better to do the (set (reg) (reg)) instead of staying with the
(set (reg) (const_int)).

Reply via email to