[pypy-svn] r76687 - in pypy/branch/jit-bounds/pypy: jit/metainterp jit/metainterp/test module/pypyjit/test
hakanardo at codespeak.net
hakanardo at codespeak.net
Fri Aug 20 18:50:29 CEST 2010
Author: hakanardo
Date: Fri Aug 20 18:50:28 2010
New Revision: 76687
Modified:
pypy/branch/jit-bounds/pypy/jit/metainterp/optimizeopt.py
pypy/branch/jit-bounds/pypy/jit/metainterp/test/test_optimizeopt.py
pypy/branch/jit-bounds/pypy/module/pypyjit/test/test_pypy_c.py
Log:
int_eq support
Modified: pypy/branch/jit-bounds/pypy/jit/metainterp/optimizeopt.py
==============================================================================
--- pypy/branch/jit-bounds/pypy/jit/metainterp/optimizeopt.py (original)
+++ pypy/branch/jit-bounds/pypy/jit/metainterp/optimizeopt.py Fri Aug 20 18:50:28 2010
@@ -711,6 +711,11 @@
self.resumedata_memo.update_counters(self.metainterp_sd.profiler)
def propagate_bounds_backward(self, box):
+ v = self.getvalue(box)
+ b = v.intbound
+ if b.has_lower and b.has_upper and b.lower == b.upper:
+ v.make_constant(ConstInt(b.lower))
+
try:
op = self.producer[box]
except KeyError:
@@ -812,13 +817,15 @@
oldop = self.pure_operations.get(targs, None)
if oldop is not None and oldop.descr is op.descr:
value = self.getvalue(oldop.result)
+ print value
if value.is_constant():
- if value.box is CONST_1:
+ if value.box.same_constant(CONST_1):
self.make_constant(op.result, CONST_0)
return True
- elif value.box is CONST_0:
+ elif value.box.same_constant(CONST_0):
self.make_constant(op.result, CONST_1)
return True
+
return False
@@ -1343,6 +1350,16 @@
else:
self.optimize_default(op)
+ def optimize_INT_EQ(self, op):
+ v1 = self.getvalue(op.args[0])
+ v2 = self.getvalue(op.args[1])
+ if v1.intbound.known_gt(v2.intbound):
+ self.make_constant_int(op.result, 0)
+ elif v1.intbound.known_lt(v2.intbound):
+ self.make_constant_int(op.result, 0)
+ else:
+ self.optimize_default(op)
+
def make_int_lt(self, args):
v1 = self.getvalue(args[0])
v2 = self.getvalue(args[1])
@@ -1398,6 +1415,17 @@
else:
self.make_int_lt(op.args)
+ def propagate_bounds_INT_EQ(self, op):
+ r = self.getvalue(op.result)
+ if r.is_constant():
+ if r.box.same_constant(CONST_1):
+ v1 = self.getvalue(op.args[0])
+ v2 = self.getvalue(op.args[1])
+ if v1.intbound.intersect(v2.intbound):
+ self.propagate_bounds_backward(op.args[0])
+ if v2.intbound.intersect(v1.intbound):
+ self.propagate_bounds_backward(op.args[1])
+
def propagate_bounds_INT_ADD(self, op):
v1 = self.getvalue(op.args[0])
v2 = self.getvalue(op.args[1])
Modified: pypy/branch/jit-bounds/pypy/jit/metainterp/test/test_optimizeopt.py
==============================================================================
--- pypy/branch/jit-bounds/pypy/jit/metainterp/test/test_optimizeopt.py (original)
+++ pypy/branch/jit-bounds/pypy/jit/metainterp/test/test_optimizeopt.py Fri Aug 20 18:50:28 2010
@@ -266,7 +266,13 @@
guard_value(i0, 0) [i0]
jump(i)
"""
- self.optimize_loop(ops, 'Not', ops)
+ expected = """
+ [i]
+ i0 = int_sub(i, 1)
+ guard_value(i0, 0) [i0]
+ jump(1)
+ """
+ self.optimize_loop(ops, 'Not', expected)
def test_constant_propagate(self):
ops = """
@@ -662,7 +668,13 @@
guard_value(i1, 0) [i]
jump(i)
"""
- self.optimize_loop(ops, 'Not', ops)
+ expected = """
+ [i]
+ i1 = int_add(i, 3)
+ guard_value(i1, 0) [i]
+ jump(-3)
+ """
+ self.optimize_loop(ops, 'Not', expected)
def test_int_is_true_of_bool(self):
ops = """
@@ -3091,7 +3103,7 @@
guard_false(i1) []
i2 = int_lt(i0, 5)
guard_true(i2) []
- jump(i0)
+ jump(4)
"""
self.optimize_loop(ops, 'Not', expected)
@@ -3544,6 +3556,65 @@
"""
self.optimize_loop(ops, 'Not', expected)
+ def test_bound_eq(self):
+ ops = """
+ [i0, i1]
+ i2 = int_le(i0, 4)
+ guard_true(i2) []
+ i3 = int_eq(i0, i1)
+ guard_true(i3) []
+ i4 = int_lt(i1, 5)
+ guard_true(i4) []
+ jump(i0, i1)
+ """
+ expected = """
+ [i0, i1]
+ i2 = int_le(i0, 4)
+ guard_true(i2) []
+ i3 = int_eq(i0, i1)
+ guard_true(i3) []
+ jump(i0, i1)
+ """
+ self.optimize_loop(ops, 'Not, Not', expected)
+
+ def test_bound_eq_const(self):
+ ops = """
+ [i0]
+ i1 = int_eq(i0, 7)
+ guard_true(i1) []
+ i2 = int_add(i0, 3)
+ jump(i2)
+ """
+ expected = """
+ [i0]
+ i1 = int_eq(i0, 7)
+ guard_true(i1) []
+ jump(10)
+
+ """
+ self.optimize_loop(ops, 'Not', expected)
+
+ def test_bound_lege_const(self):
+ ops = """
+ [i0]
+ i1 = int_ge(i0, 7)
+ guard_true(i1) []
+ i2 = int_le(i0, 7)
+ guard_true(i2) []
+ i3 = int_add(i0, 3)
+ jump(i3)
+ """
+ expected = """
+ [i0]
+ i1 = int_ge(i0, 7)
+ guard_true(i1) []
+ i2 = int_le(i0, 7)
+ guard_true(i2) []
+ jump(10)
+
+ """
+ self.optimize_loop(ops, 'Not', expected)
+
Modified: pypy/branch/jit-bounds/pypy/module/pypyjit/test/test_pypy_c.py
==============================================================================
--- pypy/branch/jit-bounds/pypy/module/pypyjit/test/test_pypy_c.py (original)
+++ pypy/branch/jit-bounds/pypy/module/pypyjit/test/test_pypy_c.py Fri Aug 20 18:50:28 2010
@@ -884,7 +884,8 @@
def test_intbound_addsub_mix(self):
tests = ('i > 4', 'i > 2', 'i + 1 > 2', '1 + i > 4',
- 'i - 1 > 1', '1 - i > 1', '1 - i < -3')
+ 'i - 1 > 1', '1 - i > 1', '1 - i < -3',
+ 'i == 1', 'i == 5')
for t1 in tests:
for t2 in tests:
print t1, t2
@@ -952,6 +953,32 @@
return (a, b)
''', 56, ([], (2000, 2000)))
+ def test_intbound_eq(self):
+ self.run_source('''
+ def main(a):
+ i, s = 0, 0
+ while i < 1500:
+ if a == 7:
+ s += a + 1
+ elif i == 10:
+ s += i
+ else:
+ s += 1
+ i += 1
+ return s
+ ''', 69, ([7], 12000), ([42], 1509), ([10], 1509))
+
+ def test_assert(self):
+ self.run_source('''
+ def main(a):
+ i, s = 0, 0
+ while i < 1500:
+ assert a == 7
+ s += a + 1
+ i += 1
+ return s
+ ''', 38, ([7], 8*1500))
+
def test_zeropadded(self):
self.run_source('''
from array import array
@@ -977,6 +1004,29 @@
''', 232, ([], 9895050.0))
+ def test_circular(self):
+ self.run_source('''
+ from array import array
+ class Circular(array):
+ def __new__(cls):
+ self = array.__new__(cls, 'd', range(256))
+ return self
+ def __getitem__(self, i):
+ return array.__getitem__(self, i & 255)
+
+ def main():
+ buf = Circular()
+ i = 10
+ sa = 0
+ while i < 2000 - 10:
+ sa += buf[i-2] + buf[i-1] + buf[i] + buf[i+1] + buf[i+2]
+ i += 1
+ return sa
+
+ ''', 170, ([], 1239690.0))
+
+
+
# test_circular
class AppTestJIT(PyPyCJITTests):
More information about the Pypy-commit
mailing list