This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix for GCC Bugzilla Bug 36134


Hi,

Andreas Schwab, asked me do email here again,
the test case and the patch that are included to the GCC bugtracker of
Bug 36134.


Problem desciption:
---------------------------
The 68K/Coldfire backend uses 6 byte long ADDA.L instructions where
the shorter LEA instruction could be used .
The reason for this is that the 68K-backend does not keep track of
instruction size costs but only of the clocks per instructions.
This means if several possible instruction are equally fast (both need
just 1 clock in above case) the GCC-68k-backend
is not able to pick the shorter instruction but will just use the
first instruction matching the criteria.


Fix:
----
But shorter LEA before ADDA in the list of available instructions.


How to reproduce:
-------------------------
Code:
Compile this example function with:
m68k-linux-gnu-gcc -mcpu=54455 -msoft-float -o example -Os
-fomit-frame-pointer example.c
void * copy_32x4a(void *destparam, const void *srcparam, size_t size)
{
        int *dest = destparam;
        const int *src = srcparam;
        int size32;
        size32 = size / 16;
        for (; size32; size32--) {
                *dest++ = *src++;
                *dest++ = *src++;
                *dest++ = *src++;
                *dest++ = *src++;
        }
}

The resulting code will include two x 6 byte long ADDA instructions
 d3fc 0000 0010  addal #16,%a1
 d1fc 0000 0010  addal #16,%a0

Apply patch and compile again
The code will now include two x 4 byte long LEA instrustions
This is better as LEA is optimized for pipelining (with destination
forwarding) and is shorter than ADDA.L


Please be so kind and apply this patch.


A future improvement could be to include instruction LENGTH information into
the 68K/Coldfire backend to allow the Compiler to choose instructions
on code size decisions.


Many thanks in advance

Kind regards

Gunnar von Boehn
*** ../../../../gcc-4.4-20080523.ori/gcc/config/m68k/m68k.md	2008-05-14 14:24:43.000000000 +0200
--- m68k.md	2008-05-29 14:33:03.000000000 +0200
***************
*** 2323,2333 ****
    "! TARGET_COLDFIRE"
    "* return output_addsi3 (operands);")
  
  (define_insn_and_split "*addsi3_5200"
!   [(set (match_operand:SI 0 "nonimmediate_operand"         "=mr,mr,m,r,  ?a,?a,?a,?a")
! 	(plus:SI (match_operand:SI 1 "general_operand"     "%0, 0, 0,0,   a, a, r, a")
! 		 (match_operand:SI 2 "general_src_operand" " I, L, d,mrKi,Cj,r, a, J")))]
    "TARGET_COLDFIRE"
  {
    switch (which_alternative)
      {
--- 2323,2333 ----
    "! TARGET_COLDFIRE"
    "* return output_addsi3 (operands);")
  
  (define_insn_and_split "*addsi3_5200"
!   [(set (match_operand:SI 0 "nonimmediate_operand"         "=mr,mr,?a, m,r,  ?a,?a,?a")
! 	(plus:SI (match_operand:SI 1 "general_operand"     "%0, 0, a,0,0,   a, a, r")
! 		 (match_operand:SI 2 "general_src_operand" " I, L, J,d,mrKi,Cj,r, a")))]
    "TARGET_COLDFIRE"
  {
    switch (which_alternative)
      {
***************
*** 2338,2360 ****
        operands[2] = GEN_INT (- INTVAL (operands[2]));
        return "subq%.l %2,%0";
  
      case 2:
      case 3:
        return "add%.l %2,%0";
  
!     case 4:
        /* move%.l %2,%0\n\tadd%.l %1,%0 */
        return "#";
  
!     case 5:
        return MOTOROLA ? "lea (%1,%2.l),%0" : "lea %1@(0,%2:l),%0";
  
!     case 6:
        return MOTOROLA ? "lea (%2,%1.l),%0" : "lea %2@(0,%1:l),%0";
  
-     case 7:
-       return MOTOROLA ? "lea (%c2,%1),%0" : "lea %1@(%c2),%0";
  
      default:
        gcc_unreachable ();
        return "";
--- 2338,2361 ----
        operands[2] = GEN_INT (- INTVAL (operands[2]));
        return "subq%.l %2,%0";
  
      case 2:
+       return MOTOROLA ? "lea (%c2,%1),%0" : "lea %1@(%c2),%0";
+ 
      case 3:
+     case 4:
        return "add%.l %2,%0";
  
!     case 5:
        /* move%.l %2,%0\n\tadd%.l %1,%0 */
        return "#";
  
!     case 6:
        return MOTOROLA ? "lea (%1,%2.l),%0" : "lea %1@(0,%2:l),%0";
  
!     case 7:
        return MOTOROLA ? "lea (%2,%1.l),%0" : "lea %2@(0,%1:l),%0";
  
  
      default:
        gcc_unreachable ();
        return "";

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]