bebbo / gcc

Bebbo's gcc-6-branch for m68k-amigaos
GNU General Public License v2.0
33 stars 11 forks source link

m68k incorrect LEA/SUBA timing - misread from manual! - Negative optimization #219

Closed GunnarVB closed 8 months ago

GunnarVB commented 8 months ago

I misread of a print typo in the 040 manual caused a number of bad and totally wrong Peephole optimizations in GCC

Fact the best and fastest way to clear an Addres register on any 68K is always SUBA.L An,An.

Therefore the compiler shouöld never use "LEA $0,An" for clearing a register - always SUBA.L An,An

Yes in some 68040 manuals was misprint - saying SUBA would need 2 cycle - but this is a known misprint.

Affected Files: file : m68k/m68k.md

  if (operands[1] == CONST0_RTX (SFmode)
      /* clr insns on 68000 read before writing.  */
      && ((TARGET_68010 || TARGET_COLDFIRE)
          || !(GET_CODE (operands[0]) == MEM && MEM_VOLATILE_P (operands[0]))))
    {
      if (ADDRESS_REG_P (operands[0]))
        {
          **/* On the '040, 'subl an,an' takes 2 clocks while lea takes only 1 */
          if (TUNE_68040_80)
            return MOTOROLA ? "lea 0.w,%0" : "lea 0:w,%0";
          else**
            return "sub%.l %0,%0";
        }
      /* moveq is faster on the 68000.  */
      if (DATA_REG_P (operands[0]) && TUNE_68000_10)
        return "moveq #0,%0";
      return "clr%.l %0";
    }
  return "move%.l %1,%0";
})

another location

**** This instruction definition is wrong!!!

;; Special case of fullword move when source is zero for 68040_60.
;; On the '040, 'subl an,an' takes 2 clocks while lea takes only 1
(define_insn "*movsi_const0_68040_60"
  [(set (match_operand:SI 0 "movsi_const0_operand" "=a,g")
        (const_int 0))]
  "TUNE_68040_80"
{
  if (which_alternative == 0)
    return MOTOROLA ? "lea 0.w,%0" : "lea 0:w,%0";
  else if (which_alternative == 1)
    return "clr%.l %0";
  else
    {
      gcc_unreachable ();
      return "";
    }
}

*** Please be so kind are fix and delete all the false peephole pessimizations