Issue 91754
Summary Failure to spot bitmask building loop idiom
Labels missed-optimization
Assignees
Reporter Kmeakin
    These two functions (which calculate the mask necessary to extract the n lowest bits from a 64-bit int) are equivalent, but LLVM fails to optimize the first into the second:

[godbolt](https://godbolt.org/z/zdrbaxonT), [alive](https://alive2.llvm.org/ce/z/LuaWSV)

```c
#include <stdint.h>

uint64_t src(uint8_t n) {
    uint64_t mask = 0;
 for (uint8_t i = 0; i < n; i++) {
        mask |= UINT64_C(1) << i;
 }
    return mask;
}

uint64_t tgt(uint8_t n) {
    return (n == 64) ? UINT64_MAX : (UINT64_C(1) << n) - 1;
}
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to