]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR tree-optimization/54676 (ICE: in set_value_range, at tree-vrp.c:433)
authorJakub Jelinek <jakub@redhat.com>
Tue, 25 Sep 2012 12:46:54 +0000 (14:46 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 25 Sep 2012 12:46:54 +0000 (14:46 +0200)
PR tree-optimization/54676
* tree-vrp.c (set_and_canonicalize_value_range): Handle
one bit precision properly.

* gcc.dg/pr54676.c: New test.

From-SVN: r191703

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr54676.c [new file with mode: 0644]
gcc/tree-vrp.c

index 44c2ed1a80a62da890b9de2a759af8981165f682..df7ab16a2b3435c9cfaea4cef6a19febd7da4e5d 100644 (file)
@@ -1,5 +1,9 @@
 2012-09-25  Jakub Jelinek  <jakub@redhat.com>
 
+       PR tree-optimization/54676
+       * tree-vrp.c (set_and_canonicalize_value_range): Handle
+       one bit precision properly.
+
        PR other/54692
        * configure.ac (CFLAGS, CXXFLAGS): Remove -Ofast or -Og
        properly.
index d94545905e9c94a20be8016b6fa4323e4f14e5a1..078ebbf048003d5ed26783340bcec5a48117a181 100644 (file)
@@ -1,3 +1,8 @@
+2012-09-25  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/54676
+       * gcc.dg/pr54676.c: New test.
+
 2012-09-25  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/53663
diff --git a/gcc/testsuite/gcc.dg/pr54676.c b/gcc/testsuite/gcc.dg/pr54676.c
new file mode 100644 (file)
index 0000000..97032ed
--- /dev/null
@@ -0,0 +1,23 @@
+/* PR tree-optimization/54676 */
+/* { dg-do compile } */
+/* { dg-options "-O -fno-tree-ccp -fno-tree-copy-prop -fno-tree-fre -ftree-vrp" } */
+
+struct S
+{
+  int s:1;
+};
+
+struct S bar (void);
+
+int a;
+
+void
+foo (int x)
+{
+  struct S s = bar ();
+  while (!a)
+    {
+      int l = 94967295;
+      a = x || (s.s &= l);
+    }
+}
index a84c4b96feef6b345c534ec62edac3f0cd76b5af..b728dddb87113bafa5b93ffeb1ad60eed56c0dd5 100644 (file)
@@ -501,8 +501,19 @@ set_and_canonicalize_value_range (value_range_t *vr, enum value_range_type t,
      to adjust them.  */
   if (tree_int_cst_lt (max, min))
     {
-      tree one = build_int_cst (TREE_TYPE (min), 1);
-      tree tmp = int_const_binop (PLUS_EXPR, max, one);
+      tree one, tmp;
+
+      /* For one bit precision if max < min, then the swapped
+        range covers all values, so for VR_RANGE it is varying and
+        for VR_ANTI_RANGE empty range, so drop to varying as well.  */
+      if (TYPE_PRECISION (TREE_TYPE (min)) == 1)
+       {
+         set_value_range_to_varying (vr);
+         return;
+       }
+
+      one = build_int_cst (TREE_TYPE (min), 1);
+      tmp = int_const_binop (PLUS_EXPR, max, one);
       max = int_const_binop (MINUS_EXPR, min, one);
       min = tmp;
 
@@ -531,6 +542,24 @@ set_and_canonicalize_value_range (value_range_t *vr, enum value_range_type t,
          set_value_range_to_varying (vr);
          return;
        }
+      else if (TYPE_PRECISION (TREE_TYPE (min)) == 1
+              && !TYPE_UNSIGNED (TREE_TYPE (min))
+              && (is_min || is_max))
+       {
+         /* For signed 1-bit precision, one is not in-range and
+            thus adding/subtracting it would result in overflows.  */
+         if (operand_equal_p (min, max, 0))
+           {
+             min = max = is_min ? vrp_val_max (TREE_TYPE (min))
+                                : vrp_val_min (TREE_TYPE (min));
+             t = VR_RANGE;
+           }
+         else
+           {
+             set_value_range_to_varying (vr);
+             return;
+           }
+       }
       else if (is_min
               /* As a special exception preserve non-null ranges.  */
               && !(TYPE_UNSIGNED (TREE_TYPE (min))