This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug rtl-optimization/71636] New: Missed optimization in variable alignment test
- From: "rth at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 23 Jun 2016 17:27:15 +0000
- Subject: [Bug rtl-optimization/71636] New: Missed optimization in variable alignment test
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71636
Bug ID: 71636
Summary: Missed optimization in variable alignment test
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: rth at gcc dot gnu.org
Target Milestone: ---
The following functions are equivalent,
unsigned f(unsigned x, unsigned b)
{
return x & ((1U << b) - 1);
}
unsigned g(unsigned x, unsigned b)
{
return x & ~(~0U << b);
}
If the target has an andnot insn, G is shorter:
aarch64:
f: mov w2, 1
lsl w1, w2, w1
sub w2, w1, #1
and w0, w2, w0
g: mov w2, -1
lsl w1, w2, w1
bic w0, w0, w1
x86_64 (-march=haswell):
f: movl $1, %edx
shlx %esi, %edx, %eax
subl $1, %eax
andl %edi, %eax
g: movl $-1, %edx
shlx %esi, %edx, %esi
andn %edi, %esi, %eax