https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68282
Bug ID: 68282 Summary: Optimization fails to remove unnecessary sign extension instruction Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: other Assignee: unassigned at gcc dot gnu.org Reporter: stanshebs at earthlink dot net Target Milestone: --- For the code int table[256]; int func(unsigned char c) { return table[(c >> 2) + 1]; } x86-64 gcc -m64 -O2 generates movzbl %dil, %eax sarl $2, %eax addl $1, %eax cltq movl table(,%rax,4), %eax ret where the cltq is not really needed. Current Clang produces shrl $2, %edi incl %edi movl table(,%rdi,4), %eax retq which is more like what we would want.