[llvm-bugs] [Bug 50389] New: Missed optimization for A && !B

via llvm-bugs llvm-bugs at lists.llvm.org
Tue May 18 09:43:03 PDT 2021


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

            Bug ID: 50389
           Summary: Missed optimization for A && !B
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mvels at google.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

The ABI dictates that bool be strictly 0 or 1. A bool value outside of 0 or 1
is UB

The compiler can optimize `A && !B1 then as `A > B`, which say under x86
becomes the macro fused op:

AAndNotBAlt(bool, bool):
        cmp     dil, sil
        jbe     .LBB1_1

instead, the compiler generates:
https://gcc.godbolt.org/z/EWx63b4nz

AAndNotB(bool, bool):
        test    edi, edi
        je      .LBB0_2
        test    sil, sil
        jne     .LBB0_2
        jmp     True()

-- 
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/20210518/6570a4f0/attachment.html>


More information about the llvm-bugs mailing list