This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug rtl-optimization/83272] New: Unnecessary mask instruction generated


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]