This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug rtl-optimization/83272] New: Unnecessary mask instruction generated
- From: "slash.tmp at free dot fr" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 04 Dec 2017 16:10:43 +0000
- Subject: [Bug rtl-optimization/83272] New: Unnecessary mask instruction generated
- Auto-submitted: auto-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