This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH, middle-end]: Fix PR middle-end/32559


On 6/30/07, Uros Bizjak <ubizjak@gmail.com> wrote:
Hello!

The problem here is, that vectors can enter ~X + X = -1 folding, but we
can't create constant -1 for vector types using build_int_cst_type.

The solution is to move these folds under INTEGRAL_TYPE_P predicate a
couple of lines above instead of !FLOAT_TYPE_P.

Patch was bootstrapped and regression tested on x86_64-pc-linux-gnu for
all default languages.
OK for mainline?

This is ok.


Thanks,
Richard.


2007-06-30 Uros Bizjak <ubizjak@gmail.com>


        PR middle-end/32559
        * fold-const.c (fold-binary) [PLUS_EXPR]: Convert ~X + X to 1 or
        X + ~X to 1 only for INTEGRAL_TYPE_P type.

testsuite/ChangeLog:

2007-06-30  Uros Bizjak  <ubizjak@gmail.com>
            Volker Reichelt  <reichelt@netcologne.de>

        PR middle-end/32559
        * gcc.dg/pr32559.c: New test.

Uros.

Index: fold-const.c
===================================================================
--- fold-const.c        (revision 126153)
+++ fold-const.c        (working copy)
@@ -9270,27 +9270,13 @@ fold_binary (enum tree_code code, tree t
        return fold_build2 (MINUS_EXPR, type,
                            fold_convert (type, arg1),
                            fold_convert (type, TREE_OPERAND (arg0, 0)));
-      /* Convert ~A + 1 to -A.  */
-      if (INTEGRAL_TYPE_P (type)
-         && TREE_CODE (arg0) == BIT_NOT_EXPR
-         && integer_onep (arg1))
-       return fold_build1 (NEGATE_EXPR, type, TREE_OPERAND (arg0, 0));

-      /* Handle (A1 * C1) + (A2 * C2) with A1, A2 or C1, C2 being the
-        same or one.  */
-      if ((TREE_CODE (arg0) == MULT_EXPR
-          || TREE_CODE (arg1) == MULT_EXPR)
-         && (!FLOAT_TYPE_P (type) || flag_unsafe_math_optimizations))
-        {
-         tree tem = fold_plusminus_mult_expr (code, type, arg0, arg1);
-         if (tem)
-           return tem;
-       }
-
-      if (! FLOAT_TYPE_P (type))
+      if (INTEGRAL_TYPE_P (type))
        {
-         if (integer_zerop (arg1))
-           return non_lvalue (fold_convert (type, arg0));
+         /* Convert ~A + 1 to -A.  */
+         if (TREE_CODE (arg0) == BIT_NOT_EXPR
+             && integer_onep (arg1))
+           return fold_build1 (NEGATE_EXPR, type, TREE_OPERAND (arg0, 0));

          /* ~X + X is -1.  */
          if (TREE_CODE (arg0) == BIT_NOT_EXPR
@@ -9319,6 +9305,23 @@ fold_binary (enum tree_code code, tree t
                  return omit_one_operand (type, t1, arg0);
                }
            }
+       }
+
+      /* Handle (A1 * C1) + (A2 * C2) with A1, A2 or C1, C2 being the
+        same or one.  */
+      if ((TREE_CODE (arg0) == MULT_EXPR
+          || TREE_CODE (arg1) == MULT_EXPR)
+         && (!FLOAT_TYPE_P (type) || flag_unsafe_math_optimizations))
+        {
+         tree tem = fold_plusminus_mult_expr (code, type, arg0, arg1);
+         if (tem)
+           return tem;
+       }
+
+      if (! FLOAT_TYPE_P (type))
+       {
+         if (integer_zerop (arg1))
+           return non_lvalue (fold_convert (type, arg0));

          /* If we are adding two BIT_AND_EXPR's, both of which are and'ing
             with a constant, and the two constants have no bits in common,
Index: testsuite/gcc.dg/pr32559.c
===================================================================
--- testsuite/gcc.dg/pr32559.c  (revision 0)
+++ testsuite/gcc.dg/pr32559.c  (revision 0)
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+int __attribute__((vector_size (8))) v;
+
+void foo()
+{
+  v += ~v;
+}




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]