[llvm-bugs] [Bug 48559] New: Optimizer does not take advantage of `-value == !(value -1)`

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Dec 19 09:38:01 PST 2020


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

            Bug ID: 48559
           Summary: Optimizer does not take advantage of `-value ==
                    !(value -1)`
           Product: libraries
           Version: 11.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: ju.orth at gmail.com
                CC: llvm-bugs at lists.llvm.org

Test case:

long f(long align) {
        return (align - 1) & -align;
}

long g(long align) {
        return (align - 1) & ~(align - 1);
}

int h(long align) {
        return -align == ~(align - 1);
}

Generated assembly:

f:
        leaq    -1(%rdi), %rax
        negq    %rdi
        andq    %rdi, %rax
        retq
g:
        xorl    %eax, %eax
        retq
h:
        movl    $1, %eax
        retq

-- 
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/20201219/5e414252/attachment.html>


More information about the llvm-bugs mailing list