https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110457
Bug ID: 110457
Summary: Unnecessary movsx eax, dil
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: antoshkka at gmail dot com
Target Milestone: ---
For the following code
int sample1(char c) {
return (c << 4) + (c << 8) + (c << 16) + c;
}
GCC-14 with -O2 generates the assembly:
sample1(char):
movsx eax,dil
imul eax,eax,0x10111
ret
However, it could be shortened to just:
sample1(char):
imul eax,edi,0x10111
Godbolt playground: https://godbolt.org/z/7GGdedEY8