https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121362
Bug ID: 121362 Summary: Fre sometimes does not read through aggregate copies Product: gcc Version: 14.2.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: ``` struct s1 { int t, t1; }; struct s3 { struct s1 t; }; struct s2 { struct s3 t; }; void f(int, int); void l(); void g(int a, int b, int *p) { struct s2 c; { struct s1 tmp = {a,b}; #if WORKS c.t.t = tmp; #else struct s3 *t = &c.t; t->t = tmp; #endif } f(c.t.t.t, c.t.t.t1); } ``` At `-O2 -fno-tree-sra` FRE1 is not able to optimize the loads of c.t.t.t/c.t.t.t1 . But if we add -DWORKS=1 then FRE1 can look through the aggregate copy. Note I disable SRA just to make easier to see in .optimized that the missed optimization has happened. This shows up in C++ code and in highway (with turning off SRA).