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: unassignedb...@nondot.org
          Reporter: juneyoung....@sf.snu.ac.kr
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to