[pypy-commit] pypy intbound-improvements: refactor the .make_??( methods to include versions that take constants as
cfbolz
pypy.commits at gmail.com
Sun Dec 3 12:49:52 EST 2017
Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: intbound-improvements
Changeset: r93253:3dd506aecf8a
Date: 2017-12-03 18:33 +0100
http://bitbucket.org/pypy/pypy/changeset/3dd506aecf8a/
Log: refactor the .make_??( methods to include versions that take
constants as arguments (as opposed to bounds), make those versions
the primitives
diff --git a/rpython/jit/metainterp/optimizeopt/intutils.py b/rpython/jit/metainterp/optimizeopt/intutils.py
--- a/rpython/jit/metainterp/optimizeopt/intutils.py
+++ b/rpython/jit/metainterp/optimizeopt/intutils.py
@@ -49,28 +49,51 @@
# Returns True if the bound was updated
def make_le(self, other):
if other.has_upper:
- if not self.has_upper or other.upper < self.upper:
- self.has_upper = True
- self.upper = other.upper
- return True
+ self.make_le_const(other.upper)
return False
def make_lt(self, other):
- return self.make_le(other.add(-1))
+ if other.has_upper:
+ return self.make_lt_const(other.upper)
+ return False
def make_ge(self, other):
if other.has_lower:
- if not self.has_lower or other.lower > self.lower:
- self.has_lower = True
- self.lower = other.lower
- return True
+ return self.make_ge_const(other.lower)
return False
+ def make_gt(self, other):
+ if other.has_lower:
+ return self.make_gt_const(other.lower)
+ return False
+
+ def make_le_const(self, other):
+ if not self.has_upper or other < self.upper:
+ self.has_upper = True
+ self.upper = other
+ return True
+ return False
+
+ def make_lt_const(self, other):
+ try:
+ other = ovfcheck(other - 1)
+ except OverflowError:
+ return False
+ return self.make_le_const(other)
+
def make_ge_const(self, other):
- return self.make_ge(ConstIntBound(other))
+ if not self.has_lower or other > self.lower:
+ self.has_lower = True
+ self.lower = other
+ return True
+ return False
def make_gt_const(self, other):
- return self.make_gt(ConstIntBound(other))
+ try:
+ other = ovfcheck(other + 1)
+ except OverflowError:
+ return False
+ return self.make_ge_const(other)
def make_eq_const(self, intval):
self.has_upper = True
@@ -78,9 +101,6 @@
self.upper = intval
self.lower = intval
- def make_gt(self, other):
- return self.make_ge(other.add(1))
-
def is_constant(self):
return self.has_upper and self.has_lower and self.lower == self.upper
@@ -221,21 +241,21 @@
return r # nothing known about other
if other.known_nonnegative():
# with Python's modulo: 0 <= (x % pos) < pos
- r.make_ge(IntBound(0, 0))
+ r.make_ge_const(0)
if other.has_upper:
- r.make_lt(IntBound(other.upper, other.upper))
+ r.make_lt_const(other.upper)
elif other.has_upper and other.upper <= 0:
# with Python's modulo: neg < (x % neg) <= 0
- r.make_le(IntBound(0, 0))
+ r.make_le_const(0)
if other.has_lower:
- r.make_gt(IntBound(other.lower, other.lower))
+ r.make_gt_const(other.lower)
else:
# the interval straddles 0, so we know this:
# other.lower < x % other < other.upper
if other.has_upper:
- r.make_lt(IntBound(other.upper, other.upper))
+ r.make_lt_const(other.upper)
if other.has_lower:
- r.make_gt(IntBound(other.lower, other.lower))
+ r.make_gt_const(other.lower)
pass
return r
@@ -273,7 +293,7 @@
pos2 = other.known_nonnegative()
r = IntUnbounded()
if pos1 or pos2:
- r.make_ge(IntBound(0, 0))
+ r.make_ge_const(0)
if pos1:
r.make_le(self)
if pos2:
@@ -284,14 +304,14 @@
r = IntUnbounded()
if self.known_nonnegative() and \
other.known_nonnegative():
- r.make_ge(IntBound(0, 0))
+ r.make_ge_const(0)
if self.has_upper and other.has_upper:
r.intersect(IntBound(0, upper_bound_or_xor(self.upper, other.upper)))
if self.has_lower and other.has_lower:
# max of the two lower bounds gives an ok (but not tight) lower
# bound of or
lower = max(self.lower, other.lower)
- r.make_ge(IntBound(lower, lower))
+ r.make_ge_const(lower)
return r
def xor_bound(self, other):
@@ -301,7 +321,7 @@
if self.has_upper and other.has_upper:
r.intersect(IntBound(0, upper_bound_or_xor(self.upper, other.upper)))
else:
- r.make_ge(IntBound(0, 0))
+ r.make_ge_const(0)
return r
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_intbound.py b/rpython/jit/metainterp/optimizeopt/test/test_intbound.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_intbound.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_intbound.py
@@ -130,7 +130,7 @@
assert b.known_lt(c)
-def test_make():
+def test_make():
for _, _, b1 in some_bounds():
for _, _, b2 in some_bounds():
lt = IntUnbounded()
@@ -169,7 +169,7 @@
assert not le.known_gt(c)
assert not le.known_ge(c)
-
+
ge = IntUnbounded()
ge.make_ge(b1)
ge.make_ge(b2)
@@ -192,13 +192,13 @@
else:
assert not gl.known_ge(c)
assert not gl.known_gt(c)
- if b2.known_le(c):
+ if b2.known_le(c):
assert gl.known_le(c)
else:
assert not gl.known_le(c)
assert not gl.known_lt(c)
-def test_intersect():
+def test_intersect():
for _, _, b1 in some_bounds():
for _, _, b2 in some_bounds():
b = copy(b1)
@@ -208,7 +208,7 @@
assert b.contains(n)
else:
assert not b.contains(n)
-
+
def test_add():
for _, _, b1 in some_bounds():
for n1 in nbr:
More information about the pypy-commit
mailing list