https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122577
Bug ID: 122577
Summary: (int)bool is not handled by the vectorizer
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
```
int count_true(const bool *values, int len) {
int count = 0;
for (int i = 0; i < len; i++) {
if (values[i]) {
count++;
}
}
return count;
}
int count_true1(const bool *values, int len) {
int count = 0;
for (int i = 0; i < len; i++) {
if (values[i]) {
count+=2;
}
}
return count;
}
```
count_true1 is vectorized but count_true is not.
In count_true case we have:
```
# count_15 = PHI <_13(6), 0(5)>
...
_3 = *_2;
_12 = (int) _3;
_13 = _12 + count_15;
```
While in count_true1 we have:
```
# count_16 = PHI <_14(6), 0(5)>
...
_3 = *_2;
_12 = (int) _3;
_13 = _12 * 2;
_14 = _13 + count_16;
```
count_true dump:
```
/app/example.cpp:3:23: missed: type conversion to/from bit-precision
unsupported.
/app/example.cpp:3:23: note: vect_is_simple_use: operand *_2, type of def:
internal
/app/example.cpp:3:23: note: vect_is_simple_use: operand *_2, type of def:
internal
/app/example.cpp:4:12: missed: not vectorized: relevant stmt not supported:
_12 = (int) _3;
/app/example.cpp:3:23: note: unsupported SLP instance starting from: _13 =
_12 + count_15;
/app/example.cpp:3:23: missed: unsupported SLP instances
```
count_true1 dump:
```
/app/example.cpp:12:23: note: op template: patt_23 = patt_27 w* 2;
/app/example.cpp:12:23: note: stmt 0 patt_23 = patt_27 w* 2;
```
We recognize it as a widening multiply by 2.