[pypy-svn] r65537 - in pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Tue Jun 2 13:36:36 CEST 2009
Author: cfbolz
Date: Tue Jun 2 13:36:36 2009
New Revision: 65537
Modified:
pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/optimize2.py
pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_optimize2.py
Log:
Tiny enhancement to optimize2: if an ooisnull/oononnull are performed after a
guard_class on a variable, we remove them. Such checks seem to be common.
Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/optimize2.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/optimize2.py (original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/optimize2.py Tue Jun 2 13:36:36 2009
@@ -255,6 +255,26 @@
instnode.cls = op.args[1]
return False
+ @staticmethod
+ def optimize_oononnull(op, spec):
+ # very simple optimization: if the class of something is known (via
+ # guard_class) the thing cannot be a NULL
+ instnode = spec.getnode(op.args[0])
+ if instnode.cls is None:
+ return False
+ spec.nodes[op.result] = InstanceNode(ConstInt(1), const=True)
+ return True
+
+ @staticmethod
+ def optimize_ooisnull(op, spec):
+ # very simple optimization: if the class of something is known (via
+ # guard_class) the thing cannot be a NULL
+ instnode = spec.getnode(op.args[0])
+ if instnode.cls is None:
+ return False
+ spec.nodes[op.result] = InstanceNode(ConstInt(0), const=True)
+ return True
+
class SimpleVirtualizableOpt(object):
@staticmethod
def find_nodes_setfield_gc(op, spec):
Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_optimize2.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_optimize2.py (original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_optimize2.py Tue Jun 2 13:36:36 2009
@@ -166,6 +166,29 @@
[ConsecutiveGuardClassRemoval()]),
expected)
+ def test_remove_ooisnull_after_guard(self):
+ pre_op = """
+ [p0]
+ guard_class(p0, ConstClass(node_vtable))
+ fail()
+ i0 = ooisnull(p0)
+ guard_false(i0)
+ fail()
+ i1 = oononnull(p0)
+ guard_true(i1)
+ fail()
+ guard_class(p0, ConstClass(node_vtable))
+ fail()
+ """
+ expected = """
+ [p0]
+ guard_class(p0, ConstClass(node_vtable))
+ fail()
+ """
+ self.assert_equal(self.optimize(pre_op,
+ [ConsecutiveGuardClassRemoval()]),
+ expected)
+
def test_basic_virtualizable(self):
pre_op = """
[p0]
More information about the Pypy-commit
mailing list