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: unassig...@gcc.gnu.org

        ReportedBy: gli...@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.

Reply via email to