xis
xis

Reputation: 24840

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

I am currently learning ASM by disassembling some of C codes. One thing interested me is that the gcc compiler generates code like this

movq %rax,%rax

which is obviously meaningless. So what is the purpose of doing that?

I am wondering if it is used for waste a few cycles of CPU in order to improve the pipeline?

Thank you for your hint!

Upvotes: 6

Views: 4294

Answers (1)

Anon.
Anon.

Reputation: 60008

It is basically a no-op, yes.

The compiler does this because branching to an address aligned on a 4-byte boundary is faster than branching to an unaligned address. So if you have a loop, the compiler will insert "padding" just before the start of it in order to get it into alignment.

Upvotes: 11

Related Questions