https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105451
Bug ID: 105451 Summary: miss optimizations due to inconsistency in complex numbers associativity Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: tnfchris at gcc dot gnu.org Reporter: tnfchris at gcc dot gnu.org Target Milestone: --- The two functions #include <complex.h> void f (complex double * restrict a, complex double *restrict b, complex double *restrict c, complex double *res, int n) { for (int i = 0; i < n; i++) res[i] = a[i] * (b[i] * c[i]); } and void g (complex double * restrict a, complex double *restrict b, complex double *restrict c, complex double *res, int n) { for (int i = 0; i < n; i++) res[i] = (a[i] * b[i]) * c[i]; } At -Ofast produce the same code, but internally they get there using different SLP trees. The former creates a chain of VEC_PERM_EXPR nodes as is expected tinyurl.com/cmulslp1 however the latter avoids the need of the permutes by duplicating the elements of the complex number https://tinyurl.com/cmulslp2 The former we can detect as back to back complex multiplication but the latter we can't. Not sure what the best way to get consistency here is.