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



             Bug #: 55796

           Summary: Comparison with a negated number vs sum

    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





Hello,



gcc doesn't seem to notice that for double variables a and b, comparing a==-b

or a+b==0 is the same thing for finite math.



void g();

void f(double a,double b){

  if(a==-b)  g();

  if(-a==b)  g();

  if(a+b==0) g();

}



compiled with -Ofast on x86_64-linux still has three comparisons and jumps.

Merging the first two shouldn't even require any unsafe flag.

Reply via email to