https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83272
Bug ID: 83272 Summary: Unnecessary mask instruction generated Product: gcc Version: 7.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: slash.tmp at free dot fr Target Milestone: --- Consider the following testcase: char foo(unsigned char n) { static const char map[16] = "wxyz"; return map[n / 16]; } gcc-7 -O2 -march=haswell -S testcase.c generates: foo: shrb $4, %dil andl $15, %edi movzbl map.2295(%rdi), %eax ret On this platform, CHAR_BIT = 8 and UCHAR_MAX = 255 Therefore n / 16 is guaranteed to be less than 16. Yet, GCC generates an unnecessary mask instruction (andl $15, %edi). https://gcc.gnu.org/ml/gcc-help/2017-11/msg00102.html