[LLVMbugs] [Bug 20971] New: performance: deduce least significant bits of a pointer from alignment

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Sep 16 17:39:36 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20971

            Bug ID: 20971
           Summary: performance: deduce least significant bits of a
                    pointer from alignment
           Product: new-bugs
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: kcc at google.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Here is a small performance opportunity:

struct S {
  long x;  // 8-aligned
  int a, b;
};

unsigned long a_bits(S *s) {
  return reinterpret_cast<unsigned long>(&s->a) & 7;
}
unsigned long b_bits(S *s) {
  return reinterpret_cast<unsigned long>(&s->b) & 7;
}

s->a is known to be 0 mod 8, and s->b to be 4 mod 8. 

Gcc uses it to optimize the code: 
a_bits:
        xorl    %eax, %eax
        ret
b_bits:
        movl    $4, %eax
        ret

Clang does not: 
a_bits:
        leal    8(%rdi), %eax
        andq    $7, %rax
        retq
b_bits:
        leal    12(%rdi), %eax
        andq    $7, %rax
        retq


Such optimization applied after ASAN instrumentation will reduce asan overhead,
see https://www.mail-archive.com/gcc-patches@gcc.gnu.org/msg88631.html
It's probably better to implement it as a separate thing than trying to 
make this optimization specifically in asan. 

Thoughts?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140917/a607ef2f/attachment.html>


More information about the llvm-bugs mailing list