[Bug tree-optimization/56355] New: abs and multiplication

glisse at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sat Feb 16 12:00:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56355

             Bug #: 56355
           Summary: abs and multiplication
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: glisse@gcc.gnu.org


#include <cmath>
#include <cstdlib>
typedef double T;
// typedef int T;
T f(T a, T b){
  return std::abs(a)*std::abs(b);
}
T g(T a){
  return std::abs(a)*std::abs(a);
}
T h(T a){
  return std::abs(a*a);
}

Compiled with g++ -O3 (-ffast-math doesn't help), g is properly optimized to
a*a but only at the RTL level, and the other 2 are not optimized at all. If I
make T a typedef for int, nothing is optimized.

For the first one, I would expect abs(a*b), and for the others just a*a.

Related to PR 31548.



More information about the Gcc-bugs mailing list