re PR rtl-optimization/68217 (Wrong constant folding)
authorKugan Vivekanandarajah <kuganv@linaro.org>
Fri, 29 Jul 2016 00:35:23 +0000 (00:35 +0000)
committerKugan Vivekanandarajah <kugan@gcc.gnu.org>
Fri, 29 Jul 2016 00:35:23 +0000 (00:35 +0000)
gcc/ChangeLog:

2016-07-29  Kugan Vivekanandarajah  <kuganv@linaro.org>

PR middle-end/68217
* tree-vrp.c (extract_range_from_binary_expr_1): In case of signed
& sign-bit-CST, generate [-INF, 0] instead of [-INF, INF].

gcc/testsuite/ChangeLog:

2016-07-29  Kugan Vivekanandarajah  <kuganv@linaro.org>

PR middle-end/68217
* gcc.dg/pr68217.c: New test.

From-SVN: r238846

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

index e51cc011e53e4d395d5ba34774f00872593b5dde..b0da5b313d89a037251f0bb08d9ad0395badd46b 100644 (file)
@@ -1,3 +1,9 @@
+2016-07-29  Kugan Vivekanandarajah  <kuganv@linaro.org>
+
+       PR middle-end/68217
+       * tree-vrp.c (extract_range_from_binary_expr_1): In case of signed
+       & sign-bit-CST, generate [-INF, 0] instead of [-INF, INF].
+
 2016-07-28  Michael Meissner  <meissner@linux.vnet.ibm.com>
 
        * config/rs6000/rs6000-protos.h (rs6000_split_vec_extract_var):
index a588afecbef7790aedb2f7a345c7475d96bfe0fd..ebb2c2fb7bdfd9cad473f2002316f6b64a2e3945 100644 (file)
@@ -1,3 +1,8 @@
+2016-07-29  Kugan Vivekanandarajah  <kuganv@linaro.org>
+
+       PR middle-end/68217
+       * gcc.dg/pr68217.c: New test.
+
 2016-07-28  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/71067
diff --git a/gcc/testsuite/gcc.dg/pr68217.c b/gcc/testsuite/gcc.dg/pr68217.c
new file mode 100644 (file)
index 0000000..426a99a
--- /dev/null
@@ -0,0 +1,14 @@
+
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-vrp1" } */
+
+int foo (void)
+{
+    volatile int a = -1;
+    long long b = (1LL << (sizeof (b) * 8 - 1)); // LLONG_MIN
+    long long x = (a & b); // x == 0x8000000000000000
+    if (x < 1LL) { ; } else { __builtin_abort(); }
+    return 0;
+}
+
+/* { dg-final { scan-tree-dump "\\\[-INF, 0\\\]" "vrp1" } } */
index 77c30144858b85f1d79a39a8046522613665cae3..41c870f111c4f7fbe0fb6631e3c8e239cbd833ce 100644 (file)
@@ -3067,6 +3067,24 @@ extract_range_from_binary_expr_1 (value_range *vr,
          if (int_cst_range1 && tree_int_cst_sgn (vr1.min) >= 0)
            wmax = wi::min (wmax, vr1.max, TYPE_SIGN (expr_type));
          max = wide_int_to_tree (expr_type, wmax);
+         cmp = compare_values (min, max);
+         /* PR68217: In case of signed & sign-bit-CST should
+            result in [-INF, 0] instead of [-INF, INF].  */
+         if (cmp == -2 || cmp == 1)
+           {
+             wide_int sign_bit
+               = wi::set_bit_in_zero (TYPE_PRECISION (expr_type) - 1,
+                                      TYPE_PRECISION (expr_type));
+             if (!TYPE_UNSIGNED (expr_type)
+                 && ((value_range_constant_singleton (&vr0)
+                      && !wi::cmps (vr0.min, sign_bit))
+                     || (value_range_constant_singleton (&vr1)
+                         && !wi::cmps (vr1.min, sign_bit))))
+               {
+                 min = TYPE_MIN_VALUE (expr_type);
+                 max = build_int_cst (expr_type, 0);
+               }
+           }
        }
       else if (code == BIT_IOR_EXPR)
        {