For types with just two values max - 1 is equal to min and thus
we fail to optimize some cases of comparisons.  With fold-const.c
bool < 0 needed the abs(x) < 0 simplification to trigger it
(same issue with mis-ordered if / else-ifs).

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2015-07-28  Richard Biener  <rguent...@suse.de>

        * match.pd: Re-order two cases in comparison with max/min
        value simplification to make it apply for bools.

Index: gcc/match.pd
===================================================================
--- gcc/match.pd        (revision 226306)
+++ gcc/match.pd        (working copy)
@@ -1856,12 +1856,6 @@ (define_operator_list CBRT BUILT_IN_CBRT
        { constant_boolean_node (true, type); })
        (if (cmp == LT_EXPR)
        (ne @2 @1))))
-     (if (wi::eq_p (@1, max - 1))
-      (switch
-       (if (cmp == GT_EXPR)
-        (eq @2 { wide_int_to_tree (TREE_TYPE (@1), wi::add (@1, 1)); }))
-       (if (cmp == LE_EXPR)
-        (ne @2 { wide_int_to_tree (TREE_TYPE (@1), wi::add (@1, 1)); }))))
      (if (wi::eq_p (@1, min))
       (switch
        (if (cmp == LT_EXPR)
@@ -1872,6 +1866,12 @@ (define_operator_list CBRT BUILT_IN_CBRT
         { constant_boolean_node (true, type); })
        (if (cmp == GT_EXPR)
         (ne @2 @1))))
+     (if (wi::eq_p (@1, max - 1))
+      (switch
+       (if (cmp == GT_EXPR)
+        (eq @2 { wide_int_to_tree (TREE_TYPE (@1), wi::add (@1, 1)); }))
+       (if (cmp == LE_EXPR)
+        (ne @2 { wide_int_to_tree (TREE_TYPE (@1), wi::add (@1, 1)); }))))
      (if (wi::eq_p (@1, min + 1))
       (switch
        (if (cmp == GE_EXPR)

Reply via email to