summaryrefslogtreecommitdiff
path: root/gcc/match.pd
diff options
context:
space:
mode:
authorMarc Glisse <marc.glisse@inria.fr>2019-06-11 17:22:43 +0200
committerMarc Glisse <glisse@gcc.gnu.org>2019-06-11 15:22:43 +0000
commit9adfa8e25f4750e27e73aca3ea8df2f34c4b8272 (patch)
tree2c6480f50fc5e2c52a8f0e8ee25538f8871d18a6 /gcc/match.pd
parentd3786ebbb06f501be93cceaf087339986e4829c7 (diff)
Allow conversions in X/[ex]4 < Y/[ex]4
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
Diffstat (limited to 'gcc/match.pd')
-rw-r--r--gcc/match.pd23
1 files changed, 19 insertions, 4 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index 88dae4231d8..f8e35e96d22 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -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)