Issue 166666
Summary missed optimization: llvm fails to vectorize when dealing with bools
Labels new issue
Assignees
Reporter alex
    https://godbolt.org/z/zz8xGqbY7

```c
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>

// Count how many bools are true
size_t count_true(const bool *values, size_t len) {
 size_t count = 0;
    for (size_t i = 0; i < len; i++) {
        if (values[i]) {
            count++;
        }
    }
    return count;
}

// Count how many uint8_t values are non-zero
size_t count_nonzero_u8(const uint8_t *values, size_t len) {
    size_t count = 0;
    for (size_t i = 0; i < len; i++) {
        if (values[i] != 0) {
 count++;
        }
    }
    return count;
}
```

`count_true` should vectorize just as easily as `count_nonzero_u8`, except it doesn't :-)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to