[llvm-bugs] [Bug 47053] New: Missed opportunity to optimize pointer range checks

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Aug 8 04:19:44 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47053

            Bug ID: 47053
           Summary: Missed opportunity to optimize pointer range checks
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

bool f1 (char *a, char *b)
{
  return (a + 16 <= b) || (b + 16 <= a);
}



Clang:

f1(char*, char*):                              # @f1(char*, char*)
        lea     rax, [rdi + 16]
        cmp     rax, rsi
        setbe   cl
        add     rsi, 16
        cmp     rsi, rdi
        setbe   al
        or      al, cl
        ret

GCC:

f1(char*, char*):
        add     rdi, 15
        sub     rdi, rsi
        cmp     rdi, 30
        seta    al
        ret

GCC transforms 

A + size <= B || B + size <= A

to

(size_t) (A + (size - 1) - B) > (size - 1) * 2


Could be useful to optimize better RT checks from vectorizer.

Godbolt: https://godbolt.org/z/9jsKa4

-- 
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/20200808/de495f18/attachment.html>


More information about the llvm-bugs mailing list