re PR tree-optimization/80426 (wrong manipulation of range based on INT_MIN)
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 19 Apr 2017 19:27:09 +0000 (19:27 +0000)
committerJeff Law <law@gcc.gnu.org>
Wed, 19 Apr 2017 19:27:09 +0000 (13:27 -0600)
PR tree-optimization/80426
* tree-vrp.c (extract_range_from_binary_expr_1): For an additive
operation on symbolic operands, also compute the overflow for the
invariant part when the operation degenerates into a negation.

PR tree-optimization/80426
* gcc.c-torture/execute/20170419-1.c: New test.

Co-Authored-By: Jakub Jelinek <jakub@redhat.com>
From-SVN: r247007

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/20170429-1.c [new file with mode: 0644]
gcc/tree-vrp.c

index 6b17e9a8b877501e66d651c45c6c8e7ded058915..de76f8a83f467e31eeb3ea81cd6bbbcea0f2dfbd 100644 (file)
@@ -1,3 +1,11 @@
+2017-04-19  Eric Botcazou  <ebotcazou@adacore.com>
+            Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/80426
+       * tree-vrp.c (extract_range_from_binary_expr_1): For an additive
+       operation on symbolic operands, also compute the overflow for the
+       invariant part when the operation degenerates into a negation.
+
 2017-04-19  Jakub Jelinek  <jakub@redhat.com>
 
        PR debug/80461
index 048541d310740c359a4ee001372202037a828fdc..7c306a683e9c74326a64e7bb7fe9a35b994be7a2 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-19  Eric Botcazou  <ebotcazou@adacore.com>
+
+       PR tree-optimization/80426
+       * gcc.c-torture/execute/20170419-1.c: New test.
+
 2017-04-19  Jakub Jelinek  <jakub@redhat.com>
 
        PR debug/80461
diff --git a/gcc/testsuite/gcc.c-torture/execute/20170429-1.c b/gcc/testsuite/gcc.c-torture/execute/20170429-1.c
new file mode 100644 (file)
index 0000000..f59dbc7
--- /dev/null
@@ -0,0 +1,24 @@
+/* PR tree-optimization/80426 */
+/* Testcase by <ishiura-compiler@ml.kwansei.ac.jp> */
+
+#define INT_MAX 0x7fffffff
+#define INT_MIN (-INT_MAX-1)
+
+int x;
+
+int main (void)
+{
+  volatile int a = 0;
+  volatile int b = -INT_MAX;
+  int j;
+
+  for(j = 0; j < 18; j += 1) {
+    x = ( (a == 0) != (b - (int)(INT_MIN) ) );
+  }
+
+  if (x != 0)
+    __builtin_abort ();
+
+  return 0;
+}
+
index 6d802de29a802376efd5e164091bdb1a740edbb8..697cd88502ebdf0c02b6ee0961668e743ba0ca96 100644 (file)
@@ -2461,7 +2461,20 @@ extract_range_from_binary_expr_1 (value_range *vr,
          else if (min_op0)
            wmin = min_op0;
          else if (min_op1)
-           wmin = minus_p ? wi::neg (min_op1) : min_op1;
+           {
+             if (minus_p)
+               {
+                 wmin = wi::neg (min_op1);
+
+                 /* Check for overflow.  */
+                 if (sgn == SIGNED && wi::neg_p (min_op1) && wi::neg_p (wmin))
+                   min_ovf = 1;
+                 else if (sgn == UNSIGNED && wi::ne_p (min_op1, 0))
+                   min_ovf = -1;
+               }
+             else
+               wmin = min_op1;
+           }
          else
            wmin = wi::shwi (0, prec);
 
@@ -2489,7 +2502,20 @@ extract_range_from_binary_expr_1 (value_range *vr,
          else if (max_op0)
            wmax = max_op0;
          else if (max_op1)
-           wmax = minus_p ? wi::neg (max_op1) : max_op1;
+           {
+             if (minus_p)
+               {
+                 wmax = wi::neg (max_op1);
+
+                 /* Check for overflow.  */
+                 if (sgn == SIGNED && wi::neg_p (max_op1) && wi::neg_p (wmax))
+                   max_ovf = 1;
+                 else if (sgn == UNSIGNED && wi::ne_p (max_op1, 0))
+                   max_ovf = -1;
+               }
+             else
+               wmax = max_op1;
+           }
          else
            wmax = wi::shwi (0, prec);