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

            Bug ID: 120724
           Summary: [missed optimization] bit test in a loop
           Product: gcc
           Version: 15.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: izaberina at gmail dot com
  Target Milestone: ---

```
bool isvalid(uint64_t state) {
    for (int i = 0; i < 16; i++) {
        if ((state & 0xf) > 11)
            return false;
        state >>= 4;
    }
    return true;
}
```

this code is checking if all nibbles in that number have the top 2 bits set

i was expecting it to be optimised into a test against a bit mask, but it is
not

instead gcc produces a massive blob of avx

i tried rewriting it as `if ((state & 0b1100) != 0b1100)` so all operations are
just bit tests and shifts, but that didn't help either

https://godbolt.org/z/GvhPh4bEv

clang fails too

Reply via email to