https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126396
Bug ID: 126396
Summary: (~a)>>a to -1 for vector types
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: kaelfandrew at gmail dot com
Target Milestone: ---
https://godbolt.org/z/6KjE8Wh7e
With -O2, src () does not optimize to tgt ():
```
typedef int v4si __attribute__ ((vector_size (16)));
v4si
src (v4si a)
{
return (~a >> a);
}
v4si
tgt (void)
{
v4si a = {-1, -1, -1, -1};
return a;
}
```
Testcases should be vector versions of PR125707 and PR125790.
gcc/match.pd:
```
/* (~X) >> (type1)X -> -1 for signed X.
The cast needs not to be truncating cast. */
(simplify
(rshift (bit_not @0) (convert?@1 @0))
(if (INTEGRAL_TYPE_P (type)
&& !TYPE_UNSIGNED (type)
&& TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (@1)))
{ build_minus_one_cst (type); }))
```