[llvm-dev] XOR A, A treatment

Hans Wennborg via llvm-dev llvm-dev at lists.llvm.org
Thu Sep 27 04:07:06 PDT 2018


On Thu, Sep 27, 2018 at 12:50 PM, James Courtier-Dutton via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> Hi,
>
> I am wondering about what suitable assembler level instruction substations
> are.

I'm not sure exactly what you're asking.

> For example:
> Result = XOR Reg1, Reg1;

At the assembler level, there is no separate Result value. With "XOR
Reg1, Reg1", the result (zero) goes into Reg1, and EFLAGS are updated
as a side-effect.

> Result is always zero, with the flags cleared.
> Could I substitute this for:
> Result = XOR Constant0, Constant0;

There is no such XOR instruction.

>
> Thus freeing up Reg1 usage.
> I think this would be a valid substitution, but I wanted to check with the
> knowledgeable people on this list as to whether I am missing something
> important.
>
> Other possible substitutions might be:
> Result = XOR Reg2, Reg2;
> Because it does not actually matter which reg is used.

Sure, XOR can be used like this to clear any desired register.

Thanks,
Hans


More information about the llvm-dev mailing list