https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82361
Bug ID: 82361
Summary: Useless "mov eax, eax" in generated code
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: antoshkka at gmail dot com
Target Milestone: ---
Following function
struct ret_t {
unsigned quot, rem;
};
ret_t my_div(unsigned a, unsigned b) {
return {a / b, a % b};
}
Produces suboptimal assembly:
my_div(unsigned int, unsigned int):
mov eax, edi
xor edx, edx
div esi
sal rdx, 32
mov eax, eax # <======
or rax, rdx
ret
Clang produces an assembly without "mov eax, eax" instead:
my_div(unsigned int, unsigned int): # @my_div(unsigned int, unsigned int)
xor edx, edx
mov eax, edi
div esi
shl rdx, 32
or rax, rdx
ret