[pypy-svn] r66418 - in pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp: . test

arigo at codespeak.net arigo at codespeak.net
Sun Jul 19 19:44:13 CEST 2009


Author: arigo
Date: Sun Jul 19 19:44:12 2009
New Revision: 66418

Modified:
   pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizeopt.py
   pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py
Log:
Optimize oononnull and ooisnull.


Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizeopt.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizeopt.py	(original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizeopt.py	Sun Jul 19 19:44:12 2009
@@ -103,5 +103,19 @@
             self.emit_operation(op)
             self.make_constant_class(instbox, clsbox)
 
+    def optimize_OONONNULL(self, op):
+        if self.has_constant_class(op.args[0]):
+            assert op.result.getint() == 1
+            self.make_constant(op.result)
+        else:
+            self.optimize_default(op)
+
+    def optimize_OOISNULL(self, op):
+        if self.has_constant_class(op.args[0]):
+            assert op.result.getint() == 0
+            self.make_constant(op.result)
+        else:
+            self.optimize_default(op)
+
 
 optimize_ops = _findall(Optimizer, 'optimize_')

Modified: pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py
==============================================================================
--- pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py	(original)
+++ pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py	Sun Jul 19 19:44:12 2009
@@ -70,7 +70,7 @@
           fail(i0)
         jump(i)
         """
-        self.optimize(ops, 'Not', ops)
+        self.optimize(ops, 'Not', ops, i0=0)
 
     def test_constant_propagate(self):
         ops = """
@@ -147,6 +147,48 @@
         """
         self.optimize(ops, 'Not', expected, i0=0, i1=1, i2=3)
 
+    def test_ooisnull_oononnull_1(self):
+        ops = """
+        [p0]
+        guard_class(p0, ConstClass(node_vtable))
+          fail()
+        i0 = oononnull(p0)
+        guard_true(i0)
+          fail()
+        i1 = ooisnull(p0)
+        guard_false(i1)
+          fail()
+        jump(p0)
+        """
+        expected = """
+        [p0]
+        guard_class(p0, ConstClass(node_vtable))
+          fail()
+        jump(p0)
+        """
+        self.optimize(ops, 'Not', expected, i0=1, i1=0)
+
+    def test_ooisnull_oononnull_2(self):
+        py.test.skip("less important")
+        ops = """
+        [p0]
+        i0 = oononnull(p0)         # p0 != NULL
+        guard_true(i0)
+          fail()
+        i1 = ooisnull(p0)
+        guard_false(i1)
+          fail()
+        jump(p0)
+        """
+        expected = """
+        [p0]
+        i0 = oononnull(p0)
+        guard_true(i0)
+          fail()
+        jump(p0)
+        """
+        self.optimize(ops, 'Not', expected, i0=1, i1=0)
+
 
 class TestLLtype(BaseTestOptimizeOpt, LLtypeMixin):
     pass



More information about the Pypy-commit mailing list