https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82260
Bug ID: 82260
Summary: [x86] Unnecessary use of 8-bit registers with -Os.
slightly slower and larger code
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: peter at cordes dot ca
Target Milestone: ---
Target: x86_64-*-*, i?86-*-*
int shift(int x, int c) {
return x >> c;
}
// https://godbolt.org/g/waovLu
gcc8 20170915 -Os -mtune=haswell:
movl %edi, %eax
movb %sil, %cl # bad
sarl %cl, %eax
ret
-O3:
movl %edi, %eax
movl %esi, %ecx # good
sarl %cl, %eax
ret
The 8-bit MOV needs a REX prefix to access %sil, and has a false dependency on
the old value of RCX. Haswell/Skylake don't rename low8 partial registers,
only high8. https://stackoverflow.com/q/45660139/224132. P6 and Sandybridge
do, but an 8-bit mov is definitely *not* better when a 32-bit mov is also an
option.
So -Os makes code that's larger and also potentially slower.