match.pd ((X / Y) == 0 -> X < Y): New pattern.
authorPrathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
Wed, 27 Sep 2017 00:03:07 +0000 (00:03 +0000)
committerPrathamesh Kulkarni <prathamesh3492@gcc.gnu.org>
Wed, 27 Sep 2017 00:03:07 +0000 (00:03 +0000)
2017-09-26  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

* match.pd ((X / Y) == 0 -> X < Y): New pattern.
((X / Y) != 0 -> X >= Y): Likewise.

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

From-SVN: r253218

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

index 40e179bf79e7c4cdcca895c89968052fbb8c9347..ad090d2161c9c92987665a3853617f7cc01c11ee 100644 (file)
@@ -1,3 +1,8 @@
+2017-09-26  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
+
+       * match.pd ((X / Y) == 0 -> X < Y): New pattern.
+       ((X / Y) != 0 -> X >= Y): Likewise.
+
 2017-09-26  Carl Love  <cel@us.ibm.com>
 
        * config/rs6000/rs6000-c.c (P9V_BUILTIN_VEC_XL_LEN_R,
index 0863273b244fa1d50c340b9bb722b6e9a95b6516..43ab226a705ad17bf04c37cc9c9ee5578b2341a1 100644 (file)
@@ -1275,6 +1275,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
           || TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0))))
    (op @1 @0))))
 
+/* Transform:
+ * (X / Y) == 0 -> X < Y if X, Y are unsigned.
+ * (X / Y) != 0 -> X >= Y, if X, Y are unsigned.
+ */
+(for cmp (eq ne)
+     ocmp (lt ge)
+ (simplify
+  (cmp (trunc_div @0 @1) integer_zerop)
+  (if (TYPE_UNSIGNED (TREE_TYPE (@0))
+       && (VECTOR_TYPE_P (type) || !VECTOR_TYPE_P (TREE_TYPE (@0))))
+   (ocmp @0 @1))))
+
 /* X == C - X can never be true if C is odd.  */
 (for cmp (eq ne)
  (simplify
index 64aea85c664eeedc46d5e31de01cabdd677e07a2..c064775317be9f29a8df2b57c9b244a429d3b8e5 100644 (file)
@@ -1,3 +1,7 @@
+2017-09-26  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
+
+       * gcc.dg/tree-ssa/cmpdiv.c: New test.
+
 2017-09-26  Carl Love  <cel@us.ibm.com>
 
        * gcc.target/powerpc/builtins-5-p9-runnable.c: Add new runable test
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cmpdiv.c b/gcc/testsuite/gcc.dg/tree-ssa/cmpdiv.c
new file mode 100644 (file)
index 0000000..14161f5
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized-raw" } */
+
+_Bool f1(unsigned x, unsigned y)
+{
+  unsigned t1 = x / y;
+  _Bool t2 = (t1 != 0);
+  return t2;
+}
+
+_Bool f2(unsigned x, unsigned y)
+{
+  unsigned t1 = x / y;
+  _Bool t2 = (t1 == 0);
+  return t2;
+}
+
+/* { dg-final { scan-tree-dump-not "trunc_div_expr" "optimized" } } */