re PR tree-optimization/53058 (Another ice in remove_range_assertions)
authorJakub Jelinek <jakub@redhat.com>
Wed, 25 Apr 2012 11:35:38 +0000 (13:35 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 25 Apr 2012 11:35:38 +0000 (13:35 +0200)
PR tree-optimization/53058
* double-int.h (double_int_max_value, double_int_min_value): New
prototypes.
* double-int.c (double_int_max_value, double_int_min_value): New
functions.
* tree-vrp.c (register_edge_assert_for_2): Compare mask
for LE_EXPR or GT_EXPR with double_int_max_value
instead of double_int_mask.

* gcc.c-torture/compile/pr53058.c: New test.

From-SVN: r186816

gcc/ChangeLog
gcc/double-int.c
gcc/double-int.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr53058.c [new file with mode: 0644]
gcc/tree-vrp.c

index 3770d39aa16f45b4f332cc04badb57e16d3e5662..9edaf939e4a8babe37fde0538fa8f48459a50202 100644 (file)
@@ -1,3 +1,14 @@
+2012-04-25  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/53058
+       * double-int.h (double_int_max_value, double_int_min_value): New
+       prototypes.
+       * double-int.c (double_int_max_value, double_int_min_value): New
+       functions.
+       * tree-vrp.c (register_edge_assert_for_2): Compare mask
+       for LE_EXPR or GT_EXPR with double_int_max_value
+       instead of double_int_mask.
+
 2012-04-25  Richard Guenther  <rguenther@suse.de>
 
        * tree-vectorizer.h (vect_loop_versioning): Adjust prototype.
index d0fde0ed89fa898e296ba2e83ada6496eb3e03da..3a51bd35d0066f17c6404b51f284530900f70c0b 100644 (file)
@@ -1,5 +1,5 @@
 /* Operations with long integers.
-   Copyright (C) 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2007, 2009, 2010, 2012 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -616,6 +616,26 @@ double_int_mask (unsigned prec)
   return mask;
 }
 
+/* Returns a maximum value for signed or unsigned integer
+   of precision PREC.  */
+
+double_int
+double_int_max_value (unsigned int prec, bool uns)
+{
+  return double_int_mask (prec - (uns ? 0 : 1));
+}
+
+/* Returns a minimum value for signed or unsigned integer
+   of precision PREC.  */
+
+double_int
+double_int_min_value (unsigned int prec, bool uns)
+{
+  if (uns)
+    return double_int_zero;
+  return double_int_lshift (double_int_one, prec - 1, prec, false);
+}
+
 /* Clears the bits of CST over the precision PREC.  If UNS is false, the bits
    outside of the precision are set to the sign bit (i.e., the PREC-th one),
    otherwise they are set to zero.
index 408ed92b8a119cca9c1ce834e98783c1eaab2729..78191cc80f7964313ccbd195f26803b312073c4b 100644 (file)
@@ -1,5 +1,5 @@
 /* Operations with long integers.
-   Copyright (C) 2006, 2007, 2008, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2007, 2008, 2010, 2012 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -242,6 +242,9 @@ double_int double_int_sext (double_int, unsigned);
 double_int double_int_zext (double_int, unsigned);
 double_int double_int_mask (unsigned);
 
+double_int double_int_max_value (unsigned int, bool);
+double_int double_int_min_value (unsigned int, bool);
+
 #define ALL_ONES (~((unsigned HOST_WIDE_INT) 0))
 
 /* The operands of the following comparison functions must be processed
index d72f93c69765c3c7185f538c7b8ef8039330b27e..313015f9ede8fdf44150f9dd4df2856e472dea0a 100644 (file)
@@ -1,3 +1,8 @@
+2012-04-25  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/53058
+       * gcc.c-torture/compile/pr53058.c: New test.
+
 2012-04-25  Jan Hubicka  <jh@suse.cz>
 
        PR middle-end/53088
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr53058.c b/gcc/testsuite/gcc.c-torture/compile/pr53058.c
new file mode 100644 (file)
index 0000000..90063c5
--- /dev/null
@@ -0,0 +1,12 @@
+/* PR tree-optimization/53058 */
+
+int a, b, c;
+
+void
+foo ()
+{
+  c = b >> 16;
+  if (c > 32767)
+    c = 0;
+  a = b;
+}
index 73b3bb4b926d66e01ff0a7ce532e070ffd90c6ed..90660967c27f4b1c3928261866e533476144ed9e 100644 (file)
@@ -4565,6 +4565,7 @@ register_edge_assert_for_2 (tree name, edge e, gimple_stmt_iterator bsi,
              && INTEGRAL_TYPE_P (TREE_TYPE (name2))
              && IN_RANGE (tree_low_cst (cst2, 1), 1, prec - 1)
              && prec <= 2 * HOST_BITS_PER_WIDE_INT
+             && prec == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (val)))
              && live_on_edge (e, name2)
              && !has_single_use (name2))
            {
@@ -4598,8 +4599,10 @@ register_edge_assert_for_2 (tree name, edge e, gimple_stmt_iterator bsi,
            new_val = val2;
          else
            {
+             double_int maxval
+               = double_int_max_value (prec, TYPE_UNSIGNED (TREE_TYPE (val)));
              mask = double_int_ior (tree_to_double_int (val2), mask);
-             if (double_int_minus_one_p (double_int_sext (mask, prec)))
+             if (double_int_equal_p (mask, maxval))
                new_val = NULL_TREE;
              else
                new_val = double_int_to_tree (TREE_TYPE (val2), mask);