https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121881
Bug ID: 121881
Summary: cselim does not handle some stuff sometimes
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: pinskia at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
```
struct s1
{
int t;
};
struct s1 f(int a, int b)
{
struct s1 t;
struct s1 c;
int *c1 = &t.t;
if (a)
t.t = b;
else
*c1 = b;
return t;
}
```
Compile at `-O2 -fno-tree-sra` and GCC produces:
```
<bb 2> [local count: 1073741824]:
if (a_2(D) != 0)
goto <bb 3>; [50.00%]
else
goto <bb 4>; [50.00%]
<bb 3> [local count: 536870912]:
# .MEM_6 = VDEF <.MEM_3(D)>
t.t = b_4(D);
goto <bb 5>; [100.00%]
<bb 4> [local count: 536870912]:
# .MEM_5 = VDEF <.MEM_3(D)>
MEM[(int *)&t] = b_4(D);
<bb 5> [local count: 1073741824]:
# .MEM_1 = PHI <.MEM_6(3), .MEM_5(4)>
# .MEM_7 = VDEF <.MEM_1>
```
BUT `t.t` and `MEM[(int *)&t]` point to the same location just a different
representation of the stores.
I Noticed this in the IR from PR 119482 (ladybird, this is with SRA turned on
even):
```
<bb 13> [local count: 66534413]:
# SR.3993_106 = PHI <9222809086901354496(11), SR.3993_63(12)>
iftmp.1316.D.157125.m_value.encoded = SR.3993_106;
goto <bb 15>; [100.00%]
<bb 14> [local count: 66534413]:
MEM[(struct Value *)&iftmp.1316] = 9222809086901354496;
<bb 15> [local count: 133068825]:
```
Both of these are the same stores.