[pypy-svn] r65417 - in pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp: . test

fijal at codespeak.net fijal at codespeak.net
Tue May 26 04:13:59 CEST 2009


Author: fijal
Date: Tue May 26 04:13:56 2009
New Revision: 65417

Modified:
   pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/optimize2.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/resoperation.py
   pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/test/test_optimize2.py
Log:
a test and a fix that not all guards can be constant folded away only
based on their args


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 May 26 04:13:56 2009
@@ -90,11 +90,12 @@
         return newboxes
 
     def optimize_guard(self, op):
-        for arg in op.args:
-            if not self.getnode(arg).const:
-                break
-        else:
-            return None
+        if op.is_foldable_guard():
+            for arg in op.args:
+                if not self.getnode(arg).const:
+                    break
+            else:
+                return None
         assert len(op.suboperations) == 1
         op_fail = op.suboperations[0]
         op_fail.args = self.new_arguments(op_fail)

Modified: pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/resoperation.py
==============================================================================
--- pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/resoperation.py	(original)
+++ pypy/branch/pyjitpl5-experiments/pypy/jit/metainterp/resoperation.py	Tue May 26 04:13:56 2009
@@ -64,6 +64,9 @@
     def is_guard(self):
         return rop._GUARD_FIRST <= self.opnum <= rop._GUARD_LAST
 
+    def is_foldable_guard(self):
+        return rop._GUARD_FOLDABLE_FIRST <= self.opnum <= rop._GUARD_FOLDABLE_LAST
+
     def is_guard_exception(self):
         return (self.opnum == rop.GUARD_EXCEPTION or
                 self.opnum == rop.GUARD_NO_EXCEPTION)
@@ -98,10 +101,12 @@
     _FINAL_LAST = 3
 
     _GUARD_FIRST = 8 # ----- start of guard operations -----
+    _GUARD_FOLDABLE_FIRST = 8
     GUARD_TRUE             = 8
     GUARD_FALSE            = 9
     GUARD_VALUE            = 10
     GUARD_CLASS            = 11
+    _GUARD_FOLDABLE_LAST   = 11
     GUARD_NONVIRTUALIZED   = 12
     GUARD_NO_EXCEPTION     = 13
     GUARD_EXCEPTION        = 14

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 May 26 04:13:56 2009
@@ -199,6 +199,14 @@
         expected = "[]"
         self.assert_equal(self.optimize(pre_op, []), expected)
 
+    def test_don_t_fold_guard_no_exception(self):
+        pre_op = """
+        []
+        guard_no_exception()
+            fail()
+        """
+        self.assert_equal(self.optimize(pre_op, []), pre_op)
+
     def test_virtualized_list_on_virtualizable(self):
         pre_op = """
         [p0]



More information about the Pypy-commit mailing list