Maciej Fijalkowski avatar Maciej Fijalkowski committed 543bfbe

work some on the tests, IN PROGRESS

Comments (0)

Files changed (5)

pypy/jit/metainterp/optimizeopt/deadops.py

+
+from pypy.jit.metainterp.history import rop
 
 def remove_dead_ops(loop):
     newops = []
     seen = {}
     for i in range(len(loop.operations) -1, -1, -1):
         op = loop.operations[i]
-        if op.has_no_side_effect() and op.result not in seen:
+        # XXX SAME_AS is required for crazy stuff that unroll does, which
+        #     makes dead ops sometime alive
+        if (op.opnum not in [rop.LABEL, rop.JUMP, rop.SAME_AS]
+            and op.has_no_side_effect()
+            and op.result not in seen):
             continue
         for arg in op.getarglist():
             seen[arg] = None

pypy/jit/metainterp/optimizeopt/rewrite.py

     def optimize_INT_FLOORDIV(self, op):
         v1 = self.getvalue(op.getarg(0))
         v2 = self.getvalue(op.getarg(1))
-
         if v2.is_constant() and v2.box.getint() == 1:
             self.make_equal_to(op.result, v1)
             return

pypy/jit/metainterp/optimizeopt/test/test_multilabel.py

 
     def test_two_intermediate_labels_basic_1(self):
         ops = """
-        [p1, i1]
+        [p1, i1, i10]
         i2 = getfield_gc(p1, descr=valuedescr)
+        guard_true(i10) [p1, i1, i2]
         label(p1, i1)
         i3 = getfield_gc(p1, descr=valuedescr)
         i4 = int_add(i1, i3)
         jump(p1, i5)
         """
         expected = """
-        [p1, i1]
+        [p1, i1, i10]
         i2 = getfield_gc(p1, descr=valuedescr)
+        guard_true(i10) [p1, i1, i2]
         label(p1, i1, i2)
         i4 = int_add(i1, i2)
         label(p1, i4)
         """
         expected = """
         [i0]
+        label(i0)
         i1 = int_add(i0, 1)
-        label(i0, i1)
         escape(i1)
         jump(i0, i1)
         """

pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py

         """
         preamble = """
         [p0]
-        p1 = getfield_gc(p0, descr=nextdescr)
         jump(p0)
         """
         expected = """
         """
         expected = """
         [p1]
-        i0 = force_token()
         jump(p1)
         """
         self.optimize_loop(ops, expected, expected)
 
     def test_bound_lt_noguard(self):
         ops = """
-        [i0]
+        [i0, i3]
         i1 = int_lt(i0, 4)
         i2 = int_lt(i0, 5)
-        jump(i2)
-        """
-        expected = """
-        [i0]
+        jump(i2, i1)
+        """
+        expected = """
+        [i0, i3]
         i1 = int_lt(i0, 4)
         i2 = int_lt(i0, 5)
-        jump(i2)
+        jump(i2, i1)
         """
         self.optimize_loop(ops, expected, expected)
 
         [i0]
         i1 = int_lt(i0, 4)
         guard_true(i1) []
-        i2 = int_add(i0, 10)
         jump(i0)
         """
         expected = """
         [i0]
         i1 = int_lt(i0, 4)
         guard_true(i1) []
-        i2 = int_add(i0, 10)
         jump(i0)
         """
         expected = """
         guard_true(i1) []
         i1p = int_gt(i0, -4)
         guard_true(i1p) []
-        i2 = int_sub(i0, 10)
         jump(i0)
         """
         expected = """
         expected = """
         [i0, p0]
         p1 = new_array(i0, descr=arraydescr)
-        i1 = arraylen_gc(p1)
         setarrayitem_gc(p0, 0, p1)
         jump(i0, p0)
         """
         """
         preamble = """
         [p0]
-        i0 = strlen(p0)
         jump(p0)
         """
         expected = """
         """
         expected = """
         [p0, i22]
-        i331 = force_token()
         jump(p0, i22)
         """
         self.optimize_loop(ops, expected)
         [p4, p7, i30]
         p16 = getfield_gc(p4, descr=valuedescr)
         p17 = getarrayitem_gc(p4, 1, descr=arraydescr)
-        guard_value(p16, ConstPtr(myptr), descr=<Guard3>) []
+        guard_value(p16, ConstPtr(myptr), descr=<Guard3>) [p17]
         i1 = getfield_raw(p7, descr=nextdescr)
         i2 = int_add(i1, i30)
         setfield_raw(p7, 7, descr=nextdescr)
         setarrayitem_raw(p7, 1, i2, descr=arraydescr)
         jump(p4, p7, i30)
         """
+        preamble = """
+        [p4, p7, i30]
+        p16 = getfield_gc(p4, descr=valuedescr)
+        guard_value(p16, ConstPtr(myptr), descr=<Guard3>) []
+        i1 = getarrayitem_raw(p7, 1, descr=arraydescr)
+        i2 = int_add(i1, i30)
+        setarrayitem_raw(p7, 1, 7, descr=arraydescr)
+        setarrayitem_raw(p7, 1, i2, descr=arraydescr)
+        jump(p4, p7, i30)
+        """
         expected = """
         [p4, p7, i30]
         i1 = getarrayitem_raw(p7, 1, descr=arraydescr)
         setarrayitem_raw(p7, 1, i2, descr=arraydescr)
         jump(p4, p7, i30)
         """
-        self.optimize_loop(ops, expected, ops)
+        self.optimize_loop(ops, expected, preamble)
 
     def test_pure(self):
         ops = """
         setfield_gc(p3, p1, descr=nextdescr)
         jump()
         """
-        self.optimize_loop(ops, ops)
+        expected = """
+        []
+        p1 = escape()
+        p3 = escape()
+        setfield_gc(p3, p1, descr=nextdescr)
+        jump()
+        """
+        self.optimize_loop(ops, expected)
 
     def test_getfield_guard_const(self):
         ops = """
         ix3 = int_xor(i1, i0)
         ix3t = int_ge(ix3, 0)
         guard_true(ix3t) []
-        ix4 = int_xor(i1, i2)
         jump(i0, i1, i2)
         """
         expected = """
         ix3 = int_floordiv(i1, i0)
         ix3t = int_ge(ix3, 0)
         guard_true(ix3t) []
-        ix4 = int_floordiv(i1, i2)
         jump(i0, i1, i2)
         """
         expected = """
         """
         preamble = """
         [i1, i2a, i2b, i2c]
-        i3 = int_is_zero(i1)
         i4 = int_gt(i2a, 7)
         guard_true(i4) []
         i6 = int_le(i2b, -7)
         guard_true(i6) []
         i8 = int_gt(i2c, -7)
         guard_true(i8) []
-        i9 = int_is_zero(i2c)
         jump(i1, i2a, i2b, i2c)
         """
         expected = """
         i17 = int_eq(i15, -1)
         guard_false(i17) []
         i18 = int_floordiv(i7, i6)
-        i19 = int_xor(i7, i6)
-        i22 = int_mod(i7, i6)
-        i23 = int_is_true(i22)
         jump(i7, i18, i8)
         """
         expected = """
         i17 = int_eq(i15, -1)
         guard_false(i17) []
         i18 = int_floordiv(i7, i6)
-        i19 = int_xor(i7, i6)
-        i22 = int_mod(i7, i6)
-        i23 = int_is_true(i22)
         jump(i7, i18, i8)
         """
         self.optimize_loop(ops, expected, preamble)
 
     def test_division_to_rshift(self):
         ops = """
-        [i1, i2]
+        [i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13]
         it = int_gt(i1, 0)
         guard_true(it)[]
-        i3 = int_floordiv(i1, i2)
-        i4 = int_floordiv(2, i2)
-        i5 = int_floordiv(i1, 2)
-        i6 = int_floordiv(3, i2)
-        i7 = int_floordiv(i1, 3)
-        i8 = int_floordiv(4, i2)
-        i9 = int_floordiv(i1, 4)
-        i10 = int_floordiv(i1, 0)
-        i11 = int_floordiv(i1, 1)
-        i12 = int_floordiv(i2, 2)
-        i13 = int_floordiv(i2, 3)
-        i14 = int_floordiv(i2, 4)
-        jump(i5, i14)
-        """
-        expected = """
-        [i1, i2]
+        i14 = int_floordiv(i1, i2)
+        i15 = int_floordiv(2, i3)
+        i16 = int_floordiv(i1, 2)
+        i17 = int_floordiv(3, i5)
+        i18 = int_floordiv(i6, 3)
+        i19 = int_floordiv(4, i7)
+        i20 = int_floordiv(i1, 4)
+        i21 = int_floordiv(i9, 0)
+        i22 = int_floordiv(i10, 1)
+        i23 = int_floordiv(i11, 2)
+        i24 = int_floordiv(i12, 3)
+        i25 = int_floordiv(i13, 4)
+        jump(i25, i14, i15, i16, i17, i18, i19, i20, i21, i22, i23, i24, i25)
+        """
+        expected = """
+        [i1, i2, i3, i4, i5, i6, i7, i8, i9, i11, i12, i13]
         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)
-        i10 = int_floordiv(i1, 0)
-        i12 = int_floordiv(i2, 2)
-        i13 = int_floordiv(i2, 3)
-        i14 = int_floordiv(i2, 4)
-        jump(i5, i14)
+        i14 = int_floordiv(i1, i2)
+        i15 = int_floordiv(2, i3)
+        i16 = int_rshift(i1, 1)
+        i17 = int_floordiv(3, i5)
+        i18 = int_floordiv(i6, 3)
+        i19 = int_floordiv(4, i7)
+        i20 = int_rshift(i1, 2)
+        i21 = int_floordiv(i9, 0)
+        i23 = int_floordiv(i11, 2)
+        i24 = int_floordiv(i12, 3)
+        i25 = int_floordiv(i13, 4)
+        jump(i25, i14, i15, i16, i17, i18, i19, i20, i21, i23, i24)
         """
         self.optimize_loop(ops, expected)
 

pypy/jit/metainterp/optimizeopt/test/test_util.py

         token = JitCellToken() 
         preamble.operations = [ResOperation(rop.LABEL, inputargs, None, descr=TargetToken(token))] + \
                               operations +  \
-                              [ResOperation(rop.LABEL, jump_args, None, descr=token)]
+                              [ResOperation(rop.LABEL, jump_args[:], None, descr=token)]
         self._do_optimize_loop(preamble, call_pure_results)
 
         assert preamble.operations[-1].getopnum() == rop.LABEL
 
-        inliner = Inliner(inputargs, jump_args)
+        inliner = Inliner(inputargs, jump_args[:])
         loop.resume_at_jump_descr = preamble.resume_at_jump_descr
         loop.operations = [preamble.operations[-1]] + \
                           [inliner.inline_op(op, clone=False) for op in cloned_operations] + \
         assert loop.operations[-1].getopnum() == rop.JUMP
         assert loop.operations[0].getopnum() == rop.LABEL
         loop.inputargs = loop.operations[0].getarglist()
+        self._do_optimize_loop(loop, call_pure_results)
 
-        self._do_optimize_loop(loop, call_pure_results)
         extra_same_as = []
         while loop.operations[0].getopnum() != rop.LABEL:
             extra_same_as.append(loop.operations[0])
             del loop.operations[0]
 
         # Hack to prevent random order of same_as ops
+            
         extra_same_as.sort(key=lambda op: str(preamble.operations).find(str(op.getarg(0))))
 
         for op in extra_same_as:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.