re PR tree-optimization/77644 (missed optimization with sqrt in comparison)
authorPrathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
Wed, 10 May 2017 13:26:09 +0000 (13:26 +0000)
committerPrathamesh Kulkarni <prathamesh3492@gcc.gnu.org>
Wed, 10 May 2017 13:26:09 +0000 (13:26 +0000)
2017-05-10  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

PR tree-optimization/77644
* match.pd (sqrt(x) cmp sqrt(y) -> x cmp y): New pattern.

testsuite/
* gcc.dg/tree-ssa/pr77644.c: New test-case.

From-SVN: r247835

gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr77644.c [new file with mode: 0644]

index 72dd1bc196848b1ec50eed8d77b196b4ce2454de..428efbab44c58ffda78fe13c16597ce0a560f94e 100644 (file)
@@ -1,3 +1,8 @@
+2017-05-10  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
+
+       PR tree-optimization/77644
+       * match.pd (sqrt(x) cmp sqrt(y) -> x cmp y): New pattern.
+
 2017-05-10  Nathan Sidwell  <nathan@acm.org>
 
        * dumpfile.h (TDI_lang_all): New.
index e3d98baa12fa62ca103624d4b387dfd21e580252..80a17ba3d23ac9c4a679085640a52b287e6f1a3a 100644 (file)
@@ -2633,7 +2633,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
         (if (GENERIC)
          (truth_andif
           (ge @0 { build_real (TREE_TYPE (@0), dconst0); })
-          (cmp @0 { build_real (TREE_TYPE (@0), c2); }))))))))))))
+          (cmp @0 { build_real (TREE_TYPE (@0), c2); })))))))))
+   /* Transform sqrt(x) cmp sqrt(y) -> x cmp y.  */
+   (simplify
+    (cmp (sq @0) (sq @1))
+      (if (! HONOR_NANS (@0))
+       (cmp @0 @1))))))
 
 /* Fold A /[ex] B CMP C to A CMP B * C.  */
 (for cmp (eq ne)
index 0fc75a3c1a215ff14a4325ccdac5f28cd29525af..e300900952b6c4d523c38a700e0acb84774efc5d 100644 (file)
@@ -1,3 +1,8 @@
+2017-05-10  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
+
+       PR tree-optimization/77644
+       * gcc.dg/tree-ssa/pr77644.c: New test-case.
+
 2017-05-10  Alexandre Oliva <aoliva@redhat.com>
 
        * gcc.dg/guality/inline-params-2.c: New.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr77644.c b/gcc/testsuite/gcc.dg/tree-ssa/pr77644.c
new file mode 100644 (file)
index 0000000..c73bb73
--- /dev/null
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target c99_runtime } */
+/* { dg-options "-O2 -fdump-tree-optimized -funsafe-math-optimizations -fno-math-errno -ffinite-math-only" } */
+
+#define FOO(type, cmp, suffix, no)  \
+int f_##no(type x, type y) \
+{ \
+  type gen_##no(); \
+  type xs = __builtin_sqrt##suffix((gen_##no())); \
+  type xy = __builtin_sqrt##suffix((gen_##no())); \
+  return (xs cmp xy); \
+}
+
+#define GEN_FOO(type, suffix) \
+FOO(type, <, suffix, suffix##1) \
+FOO(type, <=, suffix, suffix##2) \
+FOO(type, >, suffix, suffix##3) \
+FOO(type, >=, suffix, suffix##4) \
+FOO(type, ==, suffix, suffix##5) \
+FOO(type, !=, suffix, suffix##6)
+
+GEN_FOO(float, f)
+GEN_FOO(double, )
+GEN_FOO(long double, l)
+
+/* { dg-final { scan-tree-dump-not "__builtin_sqrtf" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "__builtin_sqrt" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "__builtin_sqrtl" "optimized" } } */