[pypy-svn] pypy default: port and improve test_boolrewrite_invers; please review
antocuni
commits-noreply at bitbucket.org
Wed Mar 16 18:06:35 CET 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch:
Changeset: r42720:cd6bf05d78cb
Date: 2011-03-16 17:26 +0100
http://bitbucket.org/pypy/pypy/changeset/cd6bf05d78cb/
Log: port and improve test_boolrewrite_invers; please review
diff --git a/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py b/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
--- a/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
@@ -719,3 +719,43 @@
--TICK--
jump(p0, p1, p2, p3, p4, i9, i6, descr=<Loop0>)
""")
+
+ def test_boolrewrite_invers(self):
+ for a, b, res, opt_applied in (('2000', '2000', 20001000, True),
+ ( '500', '500', 15001500, True),
+ ( '300', '600', 16001700, False),
+ ( 'a', 'b', 16001700, False),
+ ( 'a', 'a', 13001700, True)):
+ src = """
+ def main():
+ sa = 0
+ a = 300
+ b = 600
+ for i in range(1000):
+ if i < %s: # ID: lt
+ sa += 1
+ else:
+ sa += 2
+ #
+ if i >= %s: # ID: ge
+ sa += 10000
+ else:
+ sa += 20000
+ return sa
+ """ % (a, b)
+ #
+ log = self.run(src, [], threshold=400)
+ assert log.result == res
+ loop, = log.loops_by_filename(self.filepath)
+ le_ops = log.opnames(loop.ops_by_id('lt'))
+ ge_ops = log.opnames(loop.ops_by_id('ge'))
+ assert le_ops.count('int_lt') == 1
+ #
+ if opt_applied:
+ assert ge_ops.count('int_ge') == 0
+ else:
+ # if this assert fails it means that the optimization was
+ # applied even if we don't expect to. Check whether the
+ # optimization is valid, and either fix the code or fix the
+ # test :-)
+ assert ge_ops.count('int_ge') == 1
More information about the Pypy-commit
mailing list