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/71636] New: Missed optimization in variable alignment test


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

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