XOR A, A treatment

Hi,

I am wondering about what suitable assembler level instruction substations are.
For example:
Result = XOR Reg1, Reg1;

Result is always zero, with the flags cleared.
Could I substitute this for:

Result = XOR Constant0, Constant0;

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.

Kind Regards

James

Architecturally there may be an effect on memory ordering: machines
like ARM guarantee address dependency so if Result was later used as
an offset in a load or store, the CPU would guarantee that saw data
newer than when (anything feeding into) Reg1 was loaded.

Some special case for sequences like that XOR would be needed to
support http://open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0750r1.html,
though I strongly suspect it would involve pseudo-instructions rather
than a conventional xor, and even that's probably not enough.

But that's all theoretical future work. I believe the transformation
is valid going by what you've described -- neither register outputs
nor memory are changed by the substitution.

Cheers.

Tim.

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