[llvm-bugs] [Bug 42697] New: Optimize ((a >> c1) & c2) eq/ne 0

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Jul 20 05:16:48 PDT 2019


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

            Bug ID: 42697
           Summary: Optimize ((a >> c1) & c2) eq/ne 0
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

int f(int a) {
    return ((a >> 7) & 8) == 0;
}

int f2(int a) {
    return (a & (8 << 7)) == 0;
}

Clang:
f(int):                                  # @f(int)
        mov     eax, edi
        shr     eax, 10
        not     eax
        and     eax, 1
        ret
f2(int):                                 # @f2(int)
        mov     eax, edi
        shr     eax, 10
        not     eax
        and     eax, 1
        ret

I expected atleast 'f2' give us what we want:
        xor     eax, eax
        and     edi, 1024
        sete    al
        ret

GCC:
f(int):
        xor     eax, eax
        and     edi, 1024
        sete    al
        ret
f2(int):
        xor     eax, eax
        and     edi, 1024
        sete    al
        ret

Codegen: https://godbolt.org/z/HE-ZPA

-- 
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/20190720/5e880e53/attachment.html>


More information about the llvm-bugs mailing list