[llvm-bugs] [Bug 50008] New: Missing comparison folding optimization

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Apr 16 23:14:04 PDT 2021


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

            Bug ID: 50008
           Summary: Missing comparison folding optimization
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: juneyoung.lee at sf.snu.ac.kr
                CC: llvm-bugs at lists.llvm.org

Optimization

(cond ? ptr + 1 : ptr == ptr) --> !cond

is missing in clang.

https://godbolt.org/z/e7W5WrK5M

bool not_cond(char *x, bool cond) {
    char *y = x;
    if (cond)
        y = x + 1;
    return x == y;
}

g++ -O3 (x86-64):
        mov     eax, esi
        xor     eax, 1
        ret

clang -O3 (x86-64):
        lea     rax, [rdi + 1]
        test    esi, esi
        cmove   rax, rdi
        cmp     rax, rdi
        sete    al
        ret

Similarly for AArch64.

It seems the middle-end optimization cannot fold this:
```
  %add.ptr = getelementptr inbounds i8, i8* %x, i64 1
  %spec.select = select i1 %cond, i8* %add.ptr, i8* %x
  %cmp = icmp eq i8* %spec.select, %x
```

-- 
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/20210417/13adb281/attachment.html>


More information about the llvm-bugs mailing list