So, the arm memcpy code of aligned data isn’t as good as it can be.

void *memcpy(void *dest, const void *src, unsigned int n);

void foo(char *dst, int i) {
  memcpy (dst, &i, sizeof (i));
}

generates horrible code, but, it we are willing to notice the src or the 
destination are aligned, we can do much better:

$ ./cc1 -fschedule-fusion -fdump-tree-all-all -da -march=armv7ve 
-mcpu=cortex-m4 -fomit-frame-pointer -quiet -O2 /tmp/t.c -o t.s
$ cat t.s
[ … ]
foo:
        @ args = 0, pretend = 0, frame = 4
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        sub     sp, sp, #4
        str     r1, [r0]        @ unaligned
        add     sp, sp, #4

Index: gcc/config/arm/arm.c
===================================================================
--- gcc/config/arm/arm.c        (revision 223842)
+++ gcc/config/arm/arm.c        (working copy)
@@ -14376,7 +14376,10 @@ arm_block_move_unaligned_straight (rtx d
                                srcoffset + j * UNITS_PER_WORD - src_autoinc);
          mem = adjust_automodify_address (srcbase, SImode, addr,
                                           srcoffset + j * UNITS_PER_WORD);
-         emit_insn (gen_unaligned_loadsi (regs[j], mem));
+         if (src_aligned)
+           emit_move_insn (regs[j], mem);
+         else
+           emit_insn (gen_unaligned_loadsi (regs[j], mem));
        }
       srcoffset += words * UNITS_PER_WORD;
     }
@@ -14395,7 +14398,10 @@ arm_block_move_unaligned_straight (rtx d
                                dstoffset + j * UNITS_PER_WORD - dst_autoinc);
          mem = adjust_automodify_address (dstbase, SImode, addr,
                                           dstoffset + j * UNITS_PER_WORD);
-         emit_insn (gen_unaligned_storesi (mem, regs[j]));
+         if (dst_aligned)
+           emit_move_insn (mem, regs[j]);
+         else
+           emit_insn (gen_unaligned_storesi (mem, regs[j]));
        }
       dstoffset += words * UNITS_PER_WORD;
     }


Ok?

Can someone spin this through an arm test suite run for me, I was doing this by 
inspection and cross compile on a system with no arm bits.  Bonus points if you 
can check it in with the test case above marked up as appropriate.

Index: gcc/config/arm/arm.c
===================================================================
--- gcc/config/arm/arm.c        (revision 223842)
+++ gcc/config/arm/arm.c        (working copy)
@@ -14376,7 +14376,10 @@ arm_block_move_unaligned_straight (rtx d
                                srcoffset + j * UNITS_PER_WORD - src_autoinc);
          mem = adjust_automodify_address (srcbase, SImode, addr,
                                           srcoffset + j * UNITS_PER_WORD);
-         emit_insn (gen_unaligned_loadsi (regs[j], mem));
+         if (src_aligned)
+           emit_move_insn (regs[j], mem);
+         else
+           emit_insn (gen_unaligned_loadsi (regs[j], mem));
        }
       srcoffset += words * UNITS_PER_WORD;
     }
@@ -14395,7 +14398,10 @@ arm_block_move_unaligned_straight (rtx d
                                dstoffset + j * UNITS_PER_WORD - dst_autoinc);
          mem = adjust_automodify_address (dstbase, SImode, addr,
                                           dstoffset + j * UNITS_PER_WORD);
-         emit_insn (gen_unaligned_storesi (mem, regs[j]));
+         if (dst_aligned)
+           emit_move_insn (mem, regs[j]);
+         else
+           emit_insn (gen_unaligned_storesi (mem, regs[j]));
        }
       dstoffset += words * UNITS_PER_WORD;
     }

Reply via email to