https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77644

            Bug ID: 77644
           Summary: missed optimization with sqrt in comparison
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Joost.VandeVondele at mat dot ethz.ch
  Target Milestone: ---

> cat t.f90
LOGICAL FUNCTION F1(A,B)
  REAL :: A,B
  F1=(abs(A)<sqrt(B))
END FUNCTION
LOGICAL FUNCTION F2(A,B)
  REAL :: A,B
  F2=(A*A<B)
END FUNCTION

LOGICAL FUNCTION F3(A,B)
  REAL :: A,B
  F3=sqrt(A*A)<sqrt(B*B)
END FUNCTION
LOGICAL FUNCTION F4(A,B)
  REAL :: A,B
  F4=(A*A)<(B*B)
END FUNCTION

In the testcase above F1 could be optimized as F2, F3 as F4, at least with
-ffast-math, getting rid of a sqrt. a<b -> a*a < b*b if a>0 and b>0.

Reply via email to