https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104595
Bug ID: 104595 Summary: unvectorized loop due to bool condition loaded from memory Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: linkw at gcc dot gnu.org Target Milestone: --- For the case: #include "stdbool.h" #define N 256 typedef char T; extern T a[N]; extern T b[N]; extern T c[N]; extern bool pb[N]; extern char pc[N]; void predicate_by_bool() { for (int i = 0; i < N; i++) c[i] = pb[i] ? a[i] : b[i]; } void predicate_by_char() { for (int i = 0; i < N; i++) c[i] = pc[i] ? a[i] : b[i]; } Simply compiled with -Ofast -mcpu=power10, vectorizer can vectorize the 2nd function predicate_by_char but can't vectorize the first. It seems currently GCC just supports very limited case with bool types such as some patterns in vect_recog_bool_pattern. I guess here the size of bool seems to be a problem, for the size of bool, C says "An object declared as type _Bool is large enough to store the values 0 and 1.", C++ says "The value of sizeof(bool) is implementation defined and might differ from 1.". But the "implementation defined" looks to be compiler defined? then compiler should be aware of it when compiling. If so, we can use the equivalent size type for the load instead and make it compare with zero to get the predicate just like the char variant, I think the expectation to see both these loops vectorized is reasonable then?