https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117852
Bug ID: 117852 Summary: Missed optimization/vectorization opportunity (bitwise-OR-ing into a bool accumulator) Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: nicula.iccc at gmail dot com Target Milestone: --- Consider the following functions which check if there's at least one element greater than 0 in an u32 array: #include <cstdint> #include <cstddef> using u32 = uint32_t; bool find_v1(u32 *data, size_t len) { bool ret = false; for (size_t i = 0; i < len; i++) ret |= (data[i] > 0); // Not vectorized return ret; } bool find_v2(u32 *data, size_t len) { u32 ret = 0; for (size_t i = 0; i < len; i++) ret |= (data[i] > 0); // Vectorized return ret; } See the assembly code here: https://godbolt.org/z/b8xPzM3Ee Clang vectorizes both find_v1() and find_v2(). GCC only manages to vectorize find_v2(). It would be great if it could manage to vectorize find_v1() too, because I think folks are way more likely to reach for a `bool` accumulator when they're checking if at least one element satisfies a property. Using an integer as the accumulator seems less intuitive.