aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPrathamesh Kulkarni <prathamesh.kulkarni@linaro.org>2017-09-27 00:03:07 +0000
committerPrathamesh Kulkarni <prathamesh3492@gcc.gnu.org>2017-09-27 00:03:07 +0000
commit1d6fadeeacdf6775396b2417d011520a8ab0d11e (patch)
tree1eef3982eb90504b87792d0c2a34fba32aa88dbf /gcc
parent1262c6cf3a0ca41bcb02959ab0842677e5517d28 (diff)
downloadgcc-1d6fadeeacdf6775396b2417d011520a8ab0d11e.zip
gcc-1d6fadeeacdf6775396b2417d011520a8ab0d11e.tar.gz
gcc-1d6fadeeacdf6775396b2417d011520a8ab0d11e.tar.bz2
match.pd ((X / Y) == 0 -> X < Y): New pattern.
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/match.pd12
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/cmpdiv.c18
4 files changed, 39 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 40e179b..ad090d2 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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,
diff --git a/gcc/match.pd b/gcc/match.pd
index 0863273..43ab226 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -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
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 64aea85..c064775 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..14161f5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/cmpdiv.c
@@ -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" } } */