Committed.

Also makes visible a desirable change I plan for if-exprs.  They
should behave like outer ifs and allow us to write that series
of pattern as

(for op in eq ne
  /* Simplify X * C1 CMP 0 to X CMP 0 if C1 is not zero.  */
  (simplify
    (op (mult @0 INTEGER_CST@1) integer_zerop@2)
    /* In fold-const.c we have this and the following patterns
       combined because there we can "compute" the operator
       to use by using swap_tree_comparison.  */
    (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))
      (if (tree_int_cst_sgn (@1) > 0)
          (op @0 @2))
      (if (tree_int_cst_sgn (@1) < 0 && op == EQ_EXPR)
          (ne @0 @2))
      (if (tree_int_cst_sgn (@1) < 0 && op == NE_EXPR)
          (eq @0 @2)))))

that is, inner ifs have two operands, one condition and one
"result" (which can be another if).  And the simplify
now has one mandatory match operand and at least one
result operand (if which all but the last have to be an
'if').

Richard.

2014-08-20  Richard Biener  <rguent...@suse.de>

        * match-comparison.pd (X * CST == 0 -> X == 0): Properly guard
        with TYPE_OVERFLOW_UNDEFINED.

Index: gcc/match-comparison.pd
===================================================================
--- gcc/match-comparison.pd     (revision 214146)
+++ gcc/match-comparison.pd     (working copy)
@@ -5,13 +5,16 @@
     /* In fold-const.c we have this and the following patterns
        combined because there we can "compute" the operator
        to use by using swap_tree_comparison.  */
-    (if (tree_int_cst_sgn (@1) > 0))
+    (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))
+        && tree_int_cst_sgn (@1) > 0))
     (op @0 @2))
   (simplify
     (op (mult @0 INTEGER_CST@1) integer_zerop@2)
-    (if (tree_int_cst_sgn (@1) < 0 && op == EQ_EXPR))
+    (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))
+         && tree_int_cst_sgn (@1) < 0 && op == EQ_EXPR))
     (ne @0 @2))
   (simplify
     (op (mult @0 INTEGER_CST@1) integer_zerop@2)
-    (if (tree_int_cst_sgn (@1) < 0 && op == NE_EXPR))
+    (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))
+         && tree_int_cst_sgn (@1) < 0 && op == NE_EXPR))
     (eq @0 @2)))

Reply via email to