[pypy-svn] pypy fold_intadd: Reverted and fixed files I clobbered.

ademan commits-noreply at bitbucket.org
Wed Mar 16 08:37:21 CET 2011


Author: Daniel Roberts <Ademan555 at gmail.com>
Branch: fold_intadd
Changeset: r42693:ec125b51f088
Date: 2011-03-16 00:37 -0700
http://bitbucket.org/pypy/pypy/changeset/ec125b51f088/

Log:	Reverted and fixed files I clobbered.

diff --git a/pypy/jit/metainterp/test/test_optimizeopt.py b/pypy/jit/metainterp/test/test_optimizeopt.py
--- a/pypy/jit/metainterp/test/test_optimizeopt.py
+++ b/pypy/jit/metainterp/test/test_optimizeopt.py
@@ -5,7 +5,7 @@
                                                         BaseTest)
 import pypy.jit.metainterp.optimizeopt.optimizer as optimizeopt
 import pypy.jit.metainterp.optimizeopt.virtualize as virtualize
-from pypy.jit.metainterp.optimizeopt import optimize_loop_1
+from pypy.jit.metainterp.optimizeopt import optimize_loop_1, ALL_OPTS_DICT
 from pypy.jit.metainterp.optimizeutil import InvalidLoop
 from pypy.jit.metainterp.history import AbstractDescr, ConstInt, BoxInt
 from pypy.jit.metainterp.history import TreeLoop, LoopToken
@@ -163,7 +163,10 @@
 
     def optimize_loop(self, ops, optops, expected_preamble=None):
         loop = self.parse(ops)
-        expected = self.parse(optops)
+        if optops != "crash!":
+            expected = self.parse(optops)
+        else:
+            expected = "crash!"
         if expected_preamble:
             expected_preamble = self.parse(expected_preamble)
         #
@@ -185,17 +188,18 @@
             def clone_if_mutable(self):
                 return self
         loop.preamble.start_resumedescr = FakeDescr()
-        optimize_loop_1(metainterp_sd, loop)
+        optimize_loop_1(metainterp_sd, loop, ALL_OPTS_DICT)
         #
 
         print
         print loop.preamble.inputargs
         print '\n'.join([str(o) for o in loop.preamble.operations])
-        print 
+        print
         print loop.inputargs
         print '\n'.join([str(o) for o in loop.operations])
         print
-        
+
+        assert expected != "crash!", "should have raised an exception"
         self.assert_equal(loop, expected)
         if expected_preamble:
             self.assert_equal(loop.preamble, expected_preamble,
@@ -829,7 +833,7 @@
         i3 = getfield_gc(p2, descr=valuedescr)
         escape(i3)
         p3 = new_with_vtable(ConstClass(node_vtable))
-        setfield_gc(p3, i1, descr=valuedescr)        
+        setfield_gc(p3, i1, descr=valuedescr)
         jump(i1, p3)
         """
         # We cannot track virtuals that survive for more than two iterations.
@@ -889,7 +893,7 @@
         escape(i3)
         p2sub = new_with_vtable(ConstClass(node_vtable2))
         setfield_gc(p2sub, i1, descr=valuedescr)
-        setfield_gc(p2, p2sub, descr=nextdescr)        
+        setfield_gc(p2, p2sub, descr=nextdescr)
         jump(i1, p2, p2sub)
         """
         expected = """
@@ -1014,7 +1018,7 @@
         """
         preamble = """
         [i, p0]
-        i0 = getfield_gc(p0, descr=valuedescr)        
+        i0 = getfield_gc(p0, descr=valuedescr)
         i1 = int_add(i0, i)
         jump(i, i1)
         """
@@ -1346,6 +1350,26 @@
         self.node.value = 5
         self.optimize_loop(ops, expected)
 
+    def test_getfield_gc_pure_3(self):
+        ops = """
+        []
+        p1 = escape()
+        p2 = getfield_gc_pure(p1, descr=nextdescr)
+        escape(p2)
+        p3 = getfield_gc_pure(p1, descr=nextdescr)
+        escape(p3)
+        jump()
+        """
+        expected = """
+        []
+        p1 = escape()
+        p2 = getfield_gc_pure(p1, descr=nextdescr)
+        escape(p2)
+        escape(p2)
+        jump()
+        """
+        self.optimize_loop(ops, expected)
+
     def test_getfield_gc_nonpure_2(self):
         ops = """
         [i]
@@ -3440,7 +3464,7 @@
         guard_true(i1) []
         i2 = int_sub(i0, 10)
         i3 = int_lt(i2, -5)
-        guard_true(i3) []        
+        guard_true(i3) []
         jump(i0)
         """
         expected = """
@@ -3466,7 +3490,7 @@
         i1 = int_lt(i0, 4)
         guard_true(i1) []
         i1p = int_gt(i0, -4)
-        guard_true(i1p) []        
+        guard_true(i1p) []
         i2 = int_sub(i0, 10)
         jump(i0)
         """
@@ -3749,7 +3773,7 @@
         ops = """
         [p4, p7, i30]
         p16 = getfield_gc(p4, descr=valuedescr)
-        p17 = getarrayitem_gc(p4, 1, descr=arraydescr)        
+        p17 = getarrayitem_gc(p4, 1, descr=arraydescr)
         guard_value(p16, ConstPtr(myptr), descr=<Guard3>) []
         i1 = getfield_raw(p7, descr=nextdescr)
         i2 = int_add(i1, i30)
@@ -3806,6 +3830,47 @@
         self.node.value = 5
         self.optimize_loop(ops, expected)
 
+    def test_complains_getfieldpure_setfield(self):
+        from pypy.jit.metainterp.optimizeopt.heap import BogusPureField
+        ops = """
+        [p3]
+        p1 = escape()
+        p2 = getfield_gc_pure(p1, descr=nextdescr)
+        setfield_gc(p1, p3, descr=nextdescr)
+        jump(p3)
+        """
+        py.test.raises(BogusPureField, self.optimize_loop, ops, "crash!")
+
+    def test_dont_complains_different_field(self):
+        ops = """
+        [p3]
+        p1 = escape()
+        p2 = getfield_gc_pure(p1, descr=nextdescr)
+        setfield_gc(p1, p3, descr=otherdescr)
+        escape(p2)
+        jump(p3)
+        """
+        expected = """
+        [p3]
+        p1 = escape()
+        p2 = getfield_gc_pure(p1, descr=nextdescr)
+        setfield_gc(p1, p3, descr=otherdescr)
+        escape(p2)
+        jump(p3)
+        """
+        self.optimize_loop(ops, expected)
+
+    def test_dont_complains_different_object(self):
+        ops = """
+        []
+        p1 = escape()
+        p2 = getfield_gc_pure(p1, descr=nextdescr)
+        p3 = escape()
+        setfield_gc(p3, p1, descr=nextdescr)
+        jump()
+        """
+        self.optimize_loop(ops, ops)
+
     def test_getfield_guard_const(self):
         ops = """
         [p0]
@@ -3875,7 +3940,7 @@
         jump(p0)
         """
         self.optimize_loop(ops, expected, expected)
-        
+
     def test_addsub_ovf(self):
         ops = """
         [i0]
@@ -3995,7 +4060,7 @@
         """
         expected = """
         [i0, i1, i2]
-        jump(i0, i1, i2)        
+        jump(i0, i1, i2)
         """
         self.optimize_loop(ops, expected, preamble)
 
@@ -4034,7 +4099,7 @@
         """
         expected = """
         [i0, i1, i2]
-        jump(i0, i1, i2)        
+        jump(i0, i1, i2)
         """
         self.optimize_loop(ops, expected, preamble)
 
@@ -4052,7 +4117,7 @@
         guard_false(i7) []
         i8 = int_gt(i2c, -7)
         guard_true(i8) []
-        i9 = int_is_zero(i2c)        
+        i9 = int_is_zero(i2c)
         jump(i1, i2a, i2b, i2c)
         """
         preamble = """
@@ -4064,12 +4129,12 @@
         guard_true(i6) []
         i8 = int_gt(i2c, -7)
         guard_true(i8) []
-        i9 = int_is_zero(i2c)        
+        i9 = int_is_zero(i2c)
         jump(i1, i2a, i2b, i2c)
         """
         expected = """
         [i0, i1, i2, i3]
-        jump(i0, i1, i2, i3)        
+        jump(i0, i1, i2, i3)
         """
         self.optimize_loop(ops, expected, preamble)
 
@@ -4127,7 +4192,7 @@
     def test_division_to_rshift(self):
         ops = """
         [i1, i2]
-        it = int_gt(i1, 0) 
+        it = int_gt(i1, 0)
         guard_true(it)[]
         i3 = int_floordiv(i1, i2)
         i4 = int_floordiv(2, i2)
@@ -4145,15 +4210,15 @@
         """
         expected = """
         [i1, i2]
-        it = int_gt(i1, 0) 
-        guard_true(it)[]        
+        it = int_gt(i1, 0)
+        guard_true(it)[]
         i3 = int_floordiv(i1, i2)
         i4 = int_floordiv(2, i2)
         i5 = int_rshift(i1, 1)
         i6 = int_floordiv(3, i2)
         i7 = int_floordiv(i1, 3)
         i8 = int_floordiv(4, i2)
-        i9 = int_rshift(i1, 2)        
+        i9 = int_rshift(i1, 2)
         i10 = int_floordiv(i1, 0)
         i11 = int_rshift(i1, 0)
         i12 = int_floordiv(i2, 2)
@@ -4194,7 +4259,7 @@
         i9 = int_lt(i1b, 100)
         guard_true(i9) []
         i10 = int_gt(i1b, -100)
-        guard_true(i10) []        
+        guard_true(i10) []
         i13 = int_lshift(i1b, i2)
         i14 = int_rshift(i13, i2)
         i15 = int_lshift(i1b, 2)
@@ -4218,16 +4283,19 @@
         i9 = int_lt(i1b, 100)
         guard_true(i9) []
         i10 = int_gt(i1b, -100)
-        guard_true(i10) []        
+        guard_true(i10) []
         i13 = int_lshift(i1b, i2)
         i14 = int_rshift(i13, i2)
         i15 = int_lshift(i1b, 2)
+        i16 = int_rshift(i15, 2)
         i17 = int_lshift(i1b, 100)
         i18 = int_rshift(i17, 100)
+        i19 = int_eq(i1b, i16)
+        guard_true(i19) []
         jump(i2, i3, i1b, i2b)
         """
         self.optimize_loop(ops, expected)
-        
+
     def test_subsub_ovf(self):
         ops = """
         [i0]
@@ -4411,7 +4479,7 @@
         jump(i0, i1, i1b, i2, i3)
         """
         preamble = """
-        [i0, i1, i1b, i2, i3]        
+        [i0, i1, i1b, i2, i3]
         i4 = int_lt(i1, 7)
         guard_true(i4) []
         i4b = int_lt(i1b, 7)
@@ -4439,9 +4507,9 @@
         """
         expected = """
         [i0, i1, i1b, i2, i3]
-        jump(i0, i1, i1b, i2, i3)        
-        """
-        self.optimize_loop(ops, expected, preamble)        
+        jump(i0, i1, i1b, i2, i3)
+        """
+        self.optimize_loop(ops, expected, preamble)
 
     def test_bound_rshift(self):
         ops = """
@@ -4476,7 +4544,7 @@
         jump(i0, i1, i1b, i2, i3)
         """
         preamble = """
-        [i0, i1, i1b, i2, i3]        
+        [i0, i1, i1b, i2, i3]
         i4 = int_lt(i1, 7)
         guard_true(i4) []
         i4b = int_lt(i1b, 7)
@@ -4504,9 +4572,9 @@
         """
         expected = """
         [i0, i1, i1b, i2, i3]
-        jump(i0, i1, i1b, i2, i3)        
-        """
-        self.optimize_loop(ops, expected, preamble)        
+        jump(i0, i1, i1b, i2, i3)
+        """
+        self.optimize_loop(ops, expected, preamble)
 
     def test_bound_dont_backpropagate_rshift(self):
         ops = """
@@ -4519,7 +4587,7 @@
         """
         self.optimize_loop(ops, ops, ops)
 
-        
+
     def test_mul_ovf(self):
         ops = """
         [i0, i1]
@@ -4658,7 +4726,7 @@
             def sort_key(self):
                 return id(self)
 
-                
+
         for n in ('inst_w_seq', 'inst_index', 'inst_w_list', 'inst_length',
                   'inst_start', 'inst_step'):
             self.namespace[n] = FakeDescr(n)
@@ -4700,7 +4768,7 @@
         i87 = int_add(i84, i86)
         i91 = int_add(i80, 1)
         setfield_gc(p75, i91, descr=inst_index)
-        
+
         p110 = same_as(ConstPtr(myptr))
         i112 = same_as(3)
         i114 = same_as(39)
@@ -4720,13 +4788,13 @@
         p1 = getfield_gc(p0, descr=valuedescr)
         setfield_gc(p0, p1, descr=valuedescr)
         setfield_gc(p0, p1, descr=valuedescr)
-        setfield_gc(p0, p0, descr=valuedescr)        
+        setfield_gc(p0, p0, descr=valuedescr)
         jump(p0)
         """
         preamble = """
         [p0]
         p1 = getfield_gc(p0, descr=valuedescr)
-        setfield_gc(p0, p0, descr=valuedescr)                
+        setfield_gc(p0, p0, descr=valuedescr)
         jump(p0)
         """
         expected = """
@@ -4739,7 +4807,7 @@
         ops = """
         [p0]
         p1 = getfield_gc(p0, descr=valuedescr)
-        setfield_gc(p0, p0, descr=valuedescr)        
+        setfield_gc(p0, p0, descr=valuedescr)
         setfield_gc(p0, p1, descr=valuedescr)
         setfield_gc(p0, p1, descr=valuedescr)
         jump(p0)
@@ -4763,7 +4831,7 @@
         p2 = new_with_vtable(ConstClass(node_vtable))
         setfield_gc(p2, i1, descr=nextdescr)
         """
-        
+
     # ----------
     def optimize_strunicode_loop(self, ops, optops, preamble=None):
         if not preamble:
@@ -5045,6 +5113,40 @@
         """
         self.optimize_strunicode_loop(ops, expected)
 
+    def test_strgetitem_small(self):
+        ops = """
+        [p0, i0]
+        i1 = strgetitem(p0, i0)
+        i2 = int_lt(i1, 256)
+        guard_true(i2) []
+        i3 = int_ge(i1, 0)
+        guard_true(i3) []
+        jump(p0, i0)
+        """
+        expected = """
+        [p0, i0]
+        i1 = strgetitem(p0, i0)
+        jump(p0, i0)
+        """
+        self.optimize_loop(ops, expected)
+
+    def test_strlen_positive(self):
+        ops = """
+        [p0]
+        i0 = strlen(p0)
+        i1 = int_ge(i0, 0)
+        guard_true(i1) []
+        i2 = int_gt(i0, -1)
+        guard_true(i2) []
+        jump(p0)
+        """
+        expected = """
+        [p0]
+        i0 = strlen(p0)
+        jump(p0)
+        """
+        self.optimize_loop(ops, expected)
+
     # ----------
     def optimize_strunicode_loop_extradescrs(self, ops, optops, preamble=None):
         from pypy.jit.metainterp.optimizeopt import string
@@ -5404,7 +5506,6 @@
         # more generally, supporting non-constant but virtual cases is
         # not obvious, because of the exception UnicodeDecodeError that
         # can be raised by ll_str2unicode()
-        
 
 class TestFoldIntAdds(OptimizeOptTest, LLtypeMixin):
     def test_fold(self):


More information about the Pypy-commit mailing list