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

--- Comment #9 from David Faust <dfaust at gcc dot gnu.org> ---
(In reply to mateuszb from comment #8)
> For the move "backwards" starting from SRC + SIZE we must start from the
> last byte of "remainder" bytes and finish with copy in chunks as large as
> alignment permits in "backwards" order.
> 
> 1) code:
>       /* Emit the "backwards" unrolled loop.  */
>       emit_move_loop (src, dst, mode, (size_bytes - inc), -inc, iters,
> remainder);
> should be replaced by:
>       /* Emit the "backwards" unrolled loop.  */
>       emit_move_loop (src, dst, mode, size_bytes, -inc, iters, remainder);
> 
> 2) in:
> static void
> emit_move_loop (rtx src, rtx dst, machine_mode mode, int offset, int inc,
>               unsigned iters, unsigned remainder)
> 
> for memmove "backwards" (inc < 0) we should start with:
>   if (remainder & 1)
>     {
>       offset -= 1;
>       remainder -= 1;
>       emit_insn (gen_rtx_SET (adjust_address (dst, QImode, offset),
>                             adjust_address (src, QImode, offset)));
>     }
> 
> and so on for 2 and 4 until:
> 
>   for (unsigned int i = 0; i < iters; i++)
>     {
>       offset += inc;
>       emit_insn (gen_rtx_SET (adjust_address (dst, mode, offset),
>                             adjust_address (src, mode, offset)));
>     }

Yeah, this is exactly what I have done locally:
https://forge.sourceware.org/dfaust/gcc/commit/c461cde36bbaae272ae5c1f3c1a9d2be72e5e72c

I was working on ways to integrate more runtime tests for BPF to catch silly
errors like this.  We are far too dependent on Linux kernel selftests at the
moment which don't happen to exercise this case.

But that is taking too long so I will make do with asm tests (more than in the
commit linked above) for now to get the fix in and backport it.

Reply via email to