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

arigo at codespeak.net arigo at codespeak.net
Mon Jul 20 18:33:04 CEST 2009


Author: arigo
Date: Mon Jul 20 18:33:03 2009
New Revision: 66450

Modified:
   pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/optimizeopt.py
   pypy/branch/pyjitpl5-optimize4/pypy/jit/metainterp/test/test_optimizeopt.py
Log:
Actually use known_nonnull().
Simplify deref().


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	Mon Jul 20 18:33:03 2009
@@ -64,15 +64,8 @@
         """Maps a Box/Const to the corresponding Box/Const/VirtualBox
         by following the dict _equals.
         """
-        while box in self._equals:
-            # follow the chain: box -> box2 -> box3 -> ...
-            box2 = self._equals[box]
-            if box2 not in self._equals:
-                return box2
-            # compress the mapping one step (rare case)
-            box3 = self._equals[box2]
-            self._equals[box] = box3
-            box = box3
+        box = self._equals.get(box, box)
+        assert box not in self._equals
         return box
 
     def _make_equal(self, box, box2):
@@ -202,14 +195,14 @@
             self.make_constant_class(instbox, clsbox)
 
     def optimize_OONONNULL(self, op):
-        if self.has_constant_class(op.args[0]):
+        if self.known_nonnull(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]):
+        if self.known_nonnull(op.args[0]):
             assert op.result.getint() == 0
             self.make_constant(op.result)
         else:
@@ -250,6 +243,7 @@
         if isinstance(instbox, VirtualBox):
             self._make_equal(op.result, instbox.fields[op.descr])
         else:
+            self.make_nonnull(instbox)
             self.optimize_default(op)
 
     optimize_GETFIELD_PURE_GC = optimize_GETFIELD_GC
@@ -259,6 +253,7 @@
         if isinstance(instbox, VirtualBox):
             instbox.fields[op.descr] = op.args[1]
         else:
+            self.make_nonnull(instbox)
             self.optimize_default(op)
 
 

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	Mon Jul 20 18:33:03 2009
@@ -253,6 +253,38 @@
         """
         self.optimize_loop(ops, 'Not', expected, i0=1, i1=0, i2=1, i3=0)
 
+    def test_nonnull_1(self):
+        ops = """
+        [p0]
+        setfield_gc(p0, 5, descr=valuedescr)     # forces p0 != NULL
+        i0 = ooisnot(p0, NULL)
+        guard_true(i0)
+          fail()
+        i1 = oois(p0, NULL)
+        guard_false(i1)
+          fail()
+        i2 = ooisnot(NULL, p0)
+        guard_true(i0)
+          fail()
+        i3 = oois(NULL, p0)
+        guard_false(i1)
+          fail()
+        i4 = oononnull(p0)
+        guard_true(i4)
+          fail()
+        i5 = ooisnull(p0)
+        guard_false(i5)
+          fail()
+        jump(p0)
+        """
+        expected = """
+        [p0]
+        setfield_gc(p0, 5, descr=valuedescr)
+        jump(p0)
+        """
+        self.optimize_loop(ops, 'Not', expected,
+                           i0=1, i1=0, i2=1, i3=0, i4=1, i5=0)
+
     # ----------
 
     def test_virtual_1(self):



More information about the Pypy-commit mailing list