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: unassignedb...@nondot.org
          Reporter: david.bolvan...@gmail.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to