]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR bootstrap/26998 (bootstrap failure building libdecnumber, ICE in...
authorRichard Guenther <rguenther@suse.de>
Wed, 16 May 2007 11:57:09 +0000 (11:57 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 16 May 2007 11:57:09 +0000 (11:57 +0000)
2007-05-16  Richard Guenther  <rguenther@suse.de>

        Backport from mainline:
        2006-06-09  Richard Guenther  <rguenther@suse.de>

        PR tree-optimization/26998
        * tree-vrp.c (extract_range_from_unary_expr): For NEGATE_EXPR
        of signed types, only TYPE_MIN_VALUE is special, but for both,
        minimum and maximum value.  Likewise VR_ANTI_RANGE is special
        in this case, as is -fwrapv.

        * gcc.dg/torture/pr26998.c: New testcase.
        * gcc.dg/tree-ssa/vrp29.c: New testcase.

From-SVN: r124767

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr26998.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/vrp29.c [new file with mode: 0644]
gcc/tree-vrp.c

index bc4ffaaaebbc9e385e8da68193961ffdea6af937..9ca4d69e6ccf407bf83a8155a454cd294588b839 100644 (file)
@@ -1,3 +1,14 @@
+2007-05-16  Richard Guenther  <rguenther@suse.de>
+
+       Backport from mainline:
+       2006-06-09  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/26998
+       * tree-vrp.c (extract_range_from_unary_expr): For NEGATE_EXPR
+       of signed types, only TYPE_MIN_VALUE is special, but for both,
+       minimum and maximum value.  Likewise VR_ANTI_RANGE is special
+       in this case, as is -fwrapv.
+
 2007-05-11  Kaz Kojima  <kkojima@gcc.gnu.org>
 
        PR target/31876
index 29abbd142bd4a35eb1693a746fa60b2531372c83..a5c3530c56a851882497075629798ee6c1ec7041 100644 (file)
@@ -1,3 +1,12 @@
+2007-05-16  Richard Guenther  <rguenther@suse.de>
+
+       Backport from mainline:
+       2006-06-09  Richard Guenther  <rguenther@suse.de>
+
+       PR tree-optimization/26998
+       * gcc.dg/torture/pr26998.c: New testcase.
+       * gcc.dg/tree-ssa/vrp29.c: New testcase.
+
 2007-05-10  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libfortran/31880
diff --git a/gcc/testsuite/gcc.dg/torture/pr26998.c b/gcc/testsuite/gcc.dg/torture/pr26998.c
new file mode 100644 (file)
index 0000000..d50c344
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+
+int decCompareOp (int result)
+{
+    if (result != (int)0x80000000)
+    {
+        result = -result;
+        return (result > 0);
+    }
+    return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp29.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp29.c
new file mode 100644 (file)
index 0000000..bace4ff
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+extern void abort(void);
+
+void decCompareOp (int result)
+{
+  if (result != (int)0x80000000)
+    {
+      result = -result;
+      if (result != (int)0x80000001)
+        abort ();
+    }
+}
+
+int main()
+{
+  decCompareOp (0x7fffffff);
+  return 0;
+}
index 37fd274cf0d35c2a247972b234f19cb5f2dbf978..f5b22eac0b7a45eb18d5e06ff83489cf74d7ca1c 100644 (file)
@@ -1517,14 +1517,21 @@ extract_range_from_unary_expr (value_range_t *vr, tree expr)
   if (code == NEGATE_EXPR
       && !TYPE_UNSIGNED (TREE_TYPE (expr)))
     {
-      /* NEGATE_EXPR flips the range around.  */
-      min = (vr0.max == TYPE_MAX_VALUE (TREE_TYPE (expr)) && !flag_wrapv)
-            ? TYPE_MIN_VALUE (TREE_TYPE (expr))
-            : fold_unary_to_constant (code, TREE_TYPE (expr), vr0.max);
-
-      max = (vr0.min == TYPE_MIN_VALUE (TREE_TYPE (expr)) && !flag_wrapv)
-            ? TYPE_MAX_VALUE (TREE_TYPE (expr))
-            : fold_unary_to_constant (code, TREE_TYPE (expr), vr0.min);
+      /* NEGATE_EXPR flips the range around.  We need to treat
+        TYPE_MIN_VALUE specially dependent on wrapping, range type
+        and if it was used as minimum or maximum value:  
+         -~[MIN, MIN] == ~[MIN, MIN]
+         -[MIN, 0] == [0, MAX]  for -fno-wrapv
+         -[MIN, 0] == [0, MIN]  for -fwrapv (will be set to varying later)  */
+      min = vr0.max == TYPE_MIN_VALUE (TREE_TYPE (expr))
+           ? TYPE_MIN_VALUE (TREE_TYPE (expr))
+           : fold_unary_to_constant (code, TREE_TYPE (expr), vr0.max);
+
+      max = vr0.min == TYPE_MIN_VALUE (TREE_TYPE (expr))
+           ? (vr0.type == VR_ANTI_RANGE || flag_wrapv
+              ? TYPE_MIN_VALUE (TREE_TYPE (expr))
+              : TYPE_MAX_VALUE (TREE_TYPE (expr)))
+           : fold_unary_to_constant (code, TREE_TYPE (expr), vr0.min);
     }
   else if (code == ABS_EXPR
            && !TYPE_UNSIGNED (TREE_TYPE (expr)))