[PATCH] memcpy lowering: use "rep movs" even when esi is used as base pointer

Rafael Espíndola rafael.espindola at gmail.com
Tue Mar 18 09:51:35 PDT 2014


On 17 March 2014 14:46, Jim Grosbach <grosbach at apple.com> wrote:
> In general, physical register references like this are very dangerous and won’t play nicely with the rest of the code. It’s possible the glue here will work around that, but it still seems pretty dodgy. Sometimes when we need an enforced instruction ordering, we use a pseudo-instruction that gets expanded very late (sometimes as late as the MC lowering).
>
> I’m not expert on the assumptions the x86 backend makes about ESI, so I don’t have a very good feel for how safe/unsafe this change really is, unfortunately.

Using physical register should be safe. I now understand what is going
on. We start with

%vreg1<def> = MOV32rm <fi#-1>, 1, %noreg, 0, %noreg;
mem:LD4[FixedStack-1](align=16) GR32:%vreg1
ADJCALLSTACKDOWN32 92, %ESP<imp-def>, %EFLAGS<imp-def,dead>, %ESP<imp-use>
%vreg3<def> = LEA32r %ESP, 1, %noreg, 4, %noreg; GR32:%vreg3
%ECX<def> = MOV32ri 22
%EDI<def> = COPY %vreg3<kill>; GR32:%vreg3
%ESI<def> = COPY %vreg1<kill>; GR32:%vreg1

And the register allocator selects EDI for vreg3 and ESI for vreg,
which is safe. We then rewrite it to

%ESI<def> = MOV32rm <fi#-1>, 1, %noreg, 0, %noreg;
mem:LD4[FixedStack-1](align=16)
ADJCALLSTACKDOWN32 92, %ESP<imp-def>, %EFLAGS<imp-def,dead>, %ESP<imp-use>
%EDI<def> = LEA32r %ESP, 1, %noreg, 4, %noreg
%ECX<def> = MOV32ri 22
%EDI<def> = COPY %vreg3<kill>; GR32:%vreg3
%ESI<def> = COPY %vreg1<kill>; GR32:%vreg1

And delete the nop copies. Having understood that, I will take another
look at the patch :-)

Cheers,
Rafael




More information about the llvm-commits mailing list