https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83350
Bug ID: 83350 Summary: Missed optimization in math expression: missing cube of the sum formula Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: zamazan4ik at tut dot by Target Milestone: --- gcc(trunk) with '--std=c++17 -O3 -march=native -ffast-math' flags for this code: double test(double a, double b) { return a*a*a + 3.0*a*a*b + 3.0*a*b*b + b*b*b; } generates this assembly: test(double, double): vmovsd xmm2, QWORD PTR .LC0[rip] vmulsd xmm3, xmm0, xmm0 vmovapd xmm4, xmm0 vfmadd132sd xmm4, xmm1, xmm2 vmulsd xmm4, xmm4, xmm1 vfmadd132sd xmm2, xmm4, xmm3 vmulsd xmm1, xmm2, xmm1 vfmadd132sd xmm0, xmm1, xmm3 ret .LC0: .long 0 .long 1074266112 But there is formula: a*a*a + 3.0*a*a*b + 3.0*a*b*b + b*b*b == (a + b)^3. And it can be compiled in faster way.