[llvm-bugs] [Bug 47797] New: Missing optimization with (var&const)==const

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Oct 11 15:58:52 PDT 2020


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

            Bug ID: 47797
           Summary: Missing optimization with (var&const)==const
           Product: new-bugs
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: blubban at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

$ clang -Oz

void t();
void x(int a) { if ((a&1234) == 1234) t(); }
void y(int a) { if (!(1234&~a)) t(); }


Output (x86_64):

x(int):                                  # @x(int)
        mov     eax, 1234
        and     edi, eax
        cmp     edi, eax
        je      t()                   # TAILCALL
        ret
y(int):                                  # @y(int)
        mov     eax, 1234
        and     edi, eax
        cmp     edi, eax
        je      t()                   # TAILCALL
        ret


Expected output: `not edi; test edi,1234; je t(); ret` for both, it's one byte
smaller.

It intuitively seems faster too, since and+cmp calculates a less-than flag that
not+test doesn't, but modern x86 performance is quite unintuitive, so who
knows.

Compiler Explorer: https://godbolt.org/z/Yeofdo

-- 
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/20201011/2c51bea5/attachment.html>


More information about the llvm-bugs mailing list