]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Allow conversions in X/[ex]4 < Y/[ex]4
authorMarc Glisse <marc.glisse@inria.fr>
Tue, 11 Jun 2019 15:22:43 +0000 (17:22 +0200)
committerMarc Glisse <glisse@gcc.gnu.org>
Tue, 11 Jun 2019 15:22:43 +0000 (15:22 +0000)
2019-06-11  Marc Glisse  <marc.glisse@inria.fr>

gcc/
* match.pd (X/[ex]4<Y/[ex]4): Handle conversions.

gcc/testsuite/
* gcc.dg/tree-ssa/cmpexactdiv-5.c: New file.

From-SVN: r272158

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

index 0c5cf700f58df731bbaeceb3bf9a6d7cd08fc8c5..e4776e08626e890c6839f9c08bfa238211480d67 100644 (file)
@@ -1,3 +1,7 @@
+2019-06-11  Marc Glisse  <marc.glisse@inria.fr>
+
+       * match.pd (X/[ex]4<Y/[ex]4): Handle conversions.
+
 2019-06-11  Matthew Beliveau  <mbelivea@redhat.com>
 
        PR c++/90449 - add -Winaccessible-base option.
index 88dae4231d8f0e2f50d6676df2f8d06b14d64d6b..f8e35e96d22036bb0b96fbdbe2c7a346f4695067 100644 (file)
@@ -1503,11 +1503,26 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 /* X / 4 < Y / 4 iff X < Y when the division is known to be exact.  */
 (for cmp (simple_comparison)
  (simplify
-  (cmp (exact_div @0 INTEGER_CST@2) (exact_div @1 @2))
-  (if (wi::gt_p (wi::to_wide (@2), 0, TYPE_SIGN (TREE_TYPE (@2))))
-   (cmp @0 @1)
+  (cmp (convert?@3 (exact_div @0 INTEGER_CST@2)) (convert? (exact_div @1 @2)))
+  (if (element_precision (@3) >= element_precision (@0)
+       && types_match (@0, @1))
    (if (wi::lt_p (wi::to_wide (@2), 0, TYPE_SIGN (TREE_TYPE (@2))))
-    (cmp @1 @0)))))
+    (if (!TYPE_UNSIGNED (TREE_TYPE (@3)))
+     (cmp @1 @0)
+     (if (tree_expr_nonzero_p (@0) && tree_expr_nonzero_p (@1))
+      (with
+       {
+       tree utype = unsigned_type_for (TREE_TYPE (@0));
+       }
+       (cmp (convert:utype @1) (convert:utype @0)))))
+    (if (wi::gt_p (wi::to_wide (@2), 1, TYPE_SIGN (TREE_TYPE (@2))))
+     (if (TYPE_UNSIGNED (TREE_TYPE (@0)) || !TYPE_UNSIGNED (TREE_TYPE (@3)))
+      (cmp @0 @1)
+      (with
+       {
+       tree utype = unsigned_type_for (TREE_TYPE (@0));
+       }
+       (cmp (convert:utype @0) (convert:utype @1)))))))))
 
 /* X / C1 op C2 into a simple range test.  */
 (for cmp (simple_comparison)
index 21b5d83336c389007e9bd8d7c45b0f21b7b2de19..1d543337d7abcc71b72da64488b1572b51a59f56 100644 (file)
@@ -1,3 +1,7 @@
+2019-06-11  Marc Glisse  <marc.glisse@inria.fr>
+
+       * gcc.dg/tree-ssa/cmpexactdiv-5.c: New file.
+
 2019-06-11  Matthew Beliveau  <mbelivea@redhat.com>
 
        PR c++/90449 - add -Winaccessible-base option.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/cmpexactdiv-5.c b/gcc/testsuite/gcc.dg/tree-ssa/cmpexactdiv-5.c
new file mode 100644 (file)
index 0000000..41ffce1
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-optimized-raw" } */
+
+int f(int *a, int *b, int *c){
+  if(sizeof(__SIZE_TYPE__) != sizeof(__PTRDIFF_TYPE__)) return 2;
+  __SIZE_TYPE__ s = b - a;
+  __SIZE_TYPE__ t = c - a;
+  return s < t;
+}
+
+/* { dg-final { scan-tree-dump-not "exact_div_expr" "optimized" } } */