https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126580
Bug ID: 126580
Summary: missing cselim at phiopt1
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: pinskia at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Blocks: 125909
Target Milestone: ---
Take:
```
int *sink(int*);
void f(int a, int c, int d, int *e)
{
e = sink(&a);
a = d;
c = *e;
c += a;
if (c)
a = d|c;
sink(&a);
}
```
This can be optimized at `-O2 -fallow-store-data-races` to just:
```
a = d_6(D);
c_8 = *e_5;
c_9 = d_6(D) + c_8;
_1 = d_6(D) | c_9;
MEM <int> [(void *)&a] = _1;
```
In phiopt1.
But currently it takes until phiopt2 which is after cselim.
The reason is because cond_store_replacement_limited rejects `case 1` because
it wants to delete the store. But for allowing store data races you don't need
to delete the store, you can keep it around and let the rest of the compiler
take care of it.
The same is true of:
```
void f1(int *a, int c, int d, int *e)
{
*a = d;
c = *e;
c += *a;
int t = d|c;
if (c)
*a = t;
}
```
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125909
[Bug 125909] cselim should be removed