What is the purpose of mov% rax,% rax?

I'm currently learning ASM, parsing some of the C codes. I'm interested in the fact that the gcc compiler generates code like this

movq %rax,%rax

which is obviously pointless. So what is the purpose of this?

I am wondering if it is used to remove multiple processor cycles in order to improve the pipeline?

Thanks for the tip!

+5
source share
1 answer

This is, in principle, non-op, yes.

The compiler does this because branching to an address aligned on a 4-byte boundary is faster than branching to an uneven address. Therefore, if you have a loop, the compiler will insert "padding" just before it starts to bring it into line.

+10

All Articles