After executing gcc -m64 -O test.c -save-temps, I noticed that:
mov %edi, %edi
appears in the generated assembly. Does this instruction even do anything? It moves %edi into itself, effectively accomplishing nothing.
All optimization levels produce this assembly, though in some cases it is placed differently.
Please let me know if you need me to provide further context. As of posting this question, I don’t feel that further context is necessary, but I could be incorrect.
Code of procedure:
subl $400, %edi
cmpl $20, %edi
ja .L4
mov %edi, %edi
jmp *.L11(,%rdi,8)
This is referencing a jump table for a switch statement.
C Source:
int main()
{
}
int thing(int x)
{
switch(x)
{
case 400:
return 1;
break;
case 404:
return 2;
break;
case 408:
return 3;
break;
case 412:
return 4;
break;
case 416:
return 5;
break;
case 420:
return 6;
break;
}
}
In 64-bit mode, the
movinstruction when used on 32-bit registers will zero the upper 32-bits of the destination register.So:
clears the top 32-bits of
rdi.http://en.wikipedia.org/wiki/MOV_%28x86_instruction%29 (scroll all the way down)