https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112104
Bug ID: 112104
Summary: loop of ^1 should just be reduced to ^(n&1)
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
```
int
foo(long n3) {
int j = 0;
for(int i=0; i<n3; i++)
j=j^1;
return j;
}
int
foo1(long n3) {
int j = 0;
if (n3>=0)
j = j ^ (n3&1);
return j;
}
```
We should figure out that j as the result is just alternating between 0 and 1
(VRP figures that that is the range) in SCCP pattern matching.
I Noticed this while looking into PR 111972