re PR tree-optimization/64130 (vrp: handle non zero constant divided by range cannot...
authorKugan Vivekanandarajah <kuganv@linaro.org>
Mon, 29 Jun 2015 00:15:41 +0000 (00:15 +0000)
committerKugan Vivekanandarajah <kugan@gcc.gnu.org>
Mon, 29 Jun 2015 00:15:41 +0000 (00:15 +0000)
gcc/ChangeLog:

2015-06-29  Kugan Vivekanandarajah  <kuganv@linaro.org>

PR middle-end/64130
* tree-vrp.c (extract_range_from_binary_expr_1): For unsigned
division, compute max and min when value ranges for dividend and
divisor are available.

gcc/testsuite/ChangeLog:

2015-06-29  Kugan Vivekanandarajah  <kuganv@linaro.org>

PR middle-end/64130
* gcc.dg/tree-ssa/pr64130.c: New test.

From-SVN: r225108

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

index bc0614075459829b8a1fa175238c42c1fb0f3174..239ea9e66c723d782b384552c77c476a2eebd20f 100644 (file)
@@ -1,3 +1,10 @@
+2015-06-29  Kugan Vivekanandarajah  <kuganv@linaro.org>
+
+       PR middle-end/64130
+       * tree-vrp.c (extract_range_from_binary_expr_1): For unsigned
+       division, compute max and min when value ranges for dividend and
+       divisor are available.
+
 2015-06-28  Chung-Lin Tang <cltang@codesourcery.com>
            Sandra Loosemore <sandra@codesourcery.com>
 
index 610650edef7d6fff3ede7b5ca77c6b4188e152af..fda80ddedbc19c99f3412908cb963ec056d7e323 100644 (file)
@@ -1,3 +1,8 @@
+2015-06-29  Kugan Vivekanandarajah  <kuganv@linaro.org>
+
+       PR middle-end/64130
+       * gcc.dg/tree-ssa/pr64130.c: New test.
+
 2015-06-26  Jiong Wang  <jiong.wang@arm.com>
 
        * gcc.target/aarch64/pic-small.c: New testcase.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr64130.c b/gcc/testsuite/gcc.dg/tree-ssa/pr64130.c
new file mode 100644 (file)
index 0000000..0b25466
--- /dev/null
@@ -0,0 +1,18 @@
+
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-vrp1" } */
+
+int funsigned (unsigned a)
+{
+  return 0x1ffffffffL / a == 0;
+}
+
+int funsigned2 (unsigned a)
+{
+  if (a < 1) return 1;
+  return (-1 * 0x1ffffffffL) / a == 0;
+}
+
+/* { dg-final { scan-tree-dump ": \\\[2, 8589934591\\\]" "vrp1" } } */
+/* { dg-final { scan-tree-dump ": \\\[-8589934591, -2\\\]" "vrp1" } } */
+
index fdaebe4c2fc37a52251f05a6dd67c8c435c326f6..ec6d2c3e139ee9ddf2c0e3041a6be4a4fc4eb2d4 100644 (file)
@@ -3133,14 +3133,33 @@ extract_range_from_binary_expr_1 (value_range_t *vr,
                 and all numbers from min to 0 for negative min.  */
              cmp = compare_values (vr0.max, zero);
              if (cmp == -1)
-               max = zero;
+               {
+                 /* When vr0.max < 0, vr1.min != 0 and value
+                    ranges for dividend and divisor are available.  */
+                 if (vr1.type == VR_RANGE
+                     && !symbolic_range_p (&vr0)
+                     && !symbolic_range_p (&vr1)
+                     && !compare_values (vr1.min, zero))
+                   max = int_const_binop (code, vr0.max, vr1.min);
+                 else
+                   max = zero;
+               }
              else if (cmp == 0 || cmp == 1)
                max = vr0.max;
              else
                type = VR_VARYING;
              cmp = compare_values (vr0.min, zero);
              if (cmp == 1)
-               min = zero;
+               {
+                 /* For unsigned division when value ranges for dividend
+                    and divisor are available.  */
+                 if (vr1.type == VR_RANGE
+                     && !symbolic_range_p (&vr0)
+                     && !symbolic_range_p (&vr1))
+                   min = int_const_binop (code, vr0.min, vr1.max);
+                 else
+                   min = zero;
+               }
              else if (cmp == 0 || cmp == -1)
                min = vr0.min;
              else