The following Fortran program program test complex :: z real :: r r = abs(z)**2 print *, r end program test
produces the following tree: D.1352 = __builtin_cabsf (z); D.1353 = D.1352 * D.1352; r = D.1353; The complex value is naively calculated as: sqrt( (_Real_ z)*(_Real_ z) + (_Imag_ z)*(_Imag_ z) ) However, since the value is squared afterwards, the square root can be simply removed. Calculating |...|^2 is not that uncommon in some codes. -- Summary: __builtin_cabsf(z) squared should be optimized Product: gcc Version: 4.3.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: middle-end AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: burnus at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31548