https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118267

            Bug ID: 118267
           Summary: Suboptimal code for bool bitfield tests
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: law at gcc dot gnu.org
  Target Milestone: ---

This is extracted from bz99918 where someone added a testcase that likely is
unrelated to Martin's and where we don't know if that additional testcase is a
regression or not.



Another simple example:
#include <cstdint>

struct SomeClass {
    bool         cfg1 : 1;
    bool         cfg2 : 1;
    bool         cfg3 : 1;
    bool check() const noexcept { return cfg1 || cfg2 || cfg3; }
};

bool check(const SomeClass& rt) {
    return rt.check();
}

Emits:
check(SomeClass const&):
        movzx   edx, BYTE PTR [rdi]
        mov     eax, edx
        and     eax, 1
        jne     .L1
        mov     eax, edx
        shr     al
        and     eax, 1
        je      .L4
.L1:
        ret
.L4:
        mov     eax, edx
        shr     al, 2
        and     eax, 1
        ret

While it should:
check(SomeClass const&):
        test    byte ptr [rdi], 7
        setne   al
        ret

Reply via email to