diff mbox

[VRP] Improve value ranges for unsigned division

Message ID 55851248.3010408@linaro.org
State New
Headers show

Commit Message

Kugan Vivekanandarajah June 20, 2015, 7:12 a.m. UTC
As discussed in PR64130, this patch improves the VRP value ranges for
unsigned division.

Bootstrapped and regression tested on x86_64-linux-gnu and regression
tested on arm-none-linux-gnu with no new regression.

Is this OK for trunk?

Thanks,
Kugan

gcc/ChangeLog:

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

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


gcc/testsuite/ChangeLog:

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

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

Patch

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr64130.c b/gcc/testsuite/gcc.dg/tree-ssa/pr64130.c
index e69de29..9e96abb 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr64130.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr64130.c
@@ -0,0 +1,11 @@ 
+
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-vrp1" } */
+
+int funsigned(unsigned a)
+{
+  return 0x1ffffffffL / a == 0;
+}
+
+/* { dg-final { scan-tree-dump ": \\\[2, 8589934591\\\]" "vrp1" } } */
+
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index b517363..2e1c84b 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -3158,7 +3158,16 @@  extract_range_from_binary_expr_1 (value_range_t *vr,
 		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