Author: Spenser Bauman <saba...@gmail.com>
Branch: remove-getarrayitem-pure
Changeset: r83511:e2e277a65e93
Date: 2016-04-02 16:06 -0400
http://bitbucket.org/pypy/pypy/changeset/e2e277a65e93/

Log:    Make some of the tests work

diff --git a/rpython/jit/metainterp/optimizeopt/heap.py 
b/rpython/jit/metainterp/optimizeopt/heap.py
--- a/rpython/jit/metainterp/optimizeopt/heap.py
+++ b/rpython/jit/metainterp/optimizeopt/heap.py
@@ -554,13 +554,22 @@
     def optimize_GETARRAYITEM_GC_I(self, op):
         arrayinfo = self.ensure_ptr_info_arg0(op)
         indexb = self.getintbound(op.getarg(1))
+        arraydescr = op.getdescr()
+
+        if (arraydescr.is_always_pure() and
+            self.get_constant_box(op.getarg(0)) is not None and
+            self.get_constant_box(op.getarg(1)) is not None):
+            resbox = self.optimizer.constant_fold(op)
+            self.optimizer.make_constant(op, resbox)
+            return
+
         cf = None
         if indexb.is_constant():
             index = indexb.getint()
             arrayinfo.getlenbound(None).make_gt_const(index)
             # use the cache on (arraydescr, index), which is a constant
-            cf = self.arrayitem_cache(op.getdescr(), index)
-            field = cf.getfield_from_cache(self, arrayinfo, op.getdescr())
+            cf = self.arrayitem_cache(arraydescr, index)
+            field = cf.getfield_from_cache(self, arrayinfo, arraydescr)
             if field is not None:
                 self.make_equal_to(op, field)
                 return
@@ -573,36 +582,13 @@
         self.emit_operation(op)
         # then remember the result of reading the array item
         if cf is not None:
-            arrayinfo.setitem(op.getdescr(), indexb.getint(),
+            arrayinfo.setitem(arraydescr, indexb.getint(),
                               self.get_box_replacement(op.getarg(0)),
                               self.get_box_replacement(op), optheap=self,
                               cf=cf)
     optimize_GETARRAYITEM_GC_R = optimize_GETARRAYITEM_GC_I
     optimize_GETARRAYITEM_GC_F = optimize_GETARRAYITEM_GC_I
 
-    def optimize_GETARRAYITEM_GC_PURE_I(self, op):
-        arrayinfo = self.ensure_ptr_info_arg0(op)
-        indexb = self.getintbound(op.getarg(1))
-        cf = None
-        if indexb.is_constant():
-            index = indexb.getint()
-            arrayinfo.getlenbound(None).make_gt_const(index)
-            # use the cache on (arraydescr, index), which is a constant
-            cf = self.arrayitem_cache(op.getdescr(), index)
-            fieldvalue = cf.getfield_from_cache(self, arrayinfo, op.getdescr())
-            if fieldvalue is not None:
-                self.make_equal_to(op, fieldvalue)
-                return
-        else:
-            # variable index, so make sure the lazy setarrayitems are done
-            self.force_lazy_setarrayitem(op.getdescr(), 
self.getintbound(op.getarg(1)))
-        # default case: produce the operation
-        self.make_nonnull(op.getarg(0))
-        self.emit_operation(op)
-
-    optimize_GETARRAYITEM_GC_PURE_R = optimize_GETARRAYITEM_GC_PURE_I
-    optimize_GETARRAYITEM_GC_PURE_F = optimize_GETARRAYITEM_GC_PURE_I
-
     def optimize_SETARRAYITEM_GC(self, op):
         #opnum = OpHelpers.getarrayitem_pure_for_descr(op.getdescr())
         #if self.has_pure_result(opnum, [op.getarg(0), op.getarg(1)],
diff --git a/rpython/jit/metainterp/optimizeopt/optimizer.py 
b/rpython/jit/metainterp/optimizeopt/optimizer.py
--- a/rpython/jit/metainterp/optimizeopt/optimizer.py
+++ b/rpython/jit/metainterp/optimizeopt/optimizer.py
@@ -757,24 +757,20 @@
         check at all, but then we don't unroll in that case.
         """
         opnum = op.getopnum()
+        descr = op.getdescr()
         cpu = self.cpu
 
-        if OpHelpers.is_pure_getfield(opnum, op.getdescr()):
-            fielddescr = op.getdescr()
+        if OpHelpers.is_pure_getfield(opnum, descr):
             ref = self.get_constant_box(op.getarg(0)).getref_base()
-            cpu.protect_speculative_field(ref, fielddescr)
+            cpu.protect_speculative_field(ref, descr)
             return
 
-        elif (opnum == rop.GETARRAYITEM_GC_PURE_I or
-              opnum == rop.GETARRAYITEM_GC_PURE_R or
-              opnum == rop.GETARRAYITEM_GC_PURE_F or
-              opnum == rop.ARRAYLEN_GC):
-            arraydescr = op.getdescr()
+        elif OpHelpers.is_pure_getarrayitem(opnum, descr):
             array = self.get_constant_box(op.getarg(0)).getref_base()
-            cpu.protect_speculative_array(array, arraydescr)
+            cpu.protect_speculative_array(array, descr)
             if opnum == rop.ARRAYLEN_GC:
                 return
-            arraylength = cpu.bh_arraylen_gc(array, arraydescr)
+            arraylength = cpu.bh_arraylen_gc(array, descr)
 
         elif (opnum == rop.STRGETITEM or
               opnum == rop.STRLEN):
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py 
b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -5403,15 +5403,15 @@
     def test_getarrayitem_gc_pure_not_invalidated(self):
         ops = """
         [p0]
-        i1 = getarrayitem_gc_pure_i(p0, 1, descr=arrayimmutdescr)
+        i1 = getarrayitem_gc_i(p0, 1, descr=arrayimmutdescr)
         escape_n(p0)
-        i2 = getarrayitem_gc_pure_i(p0, 1, descr=arrayimmutdescr)
+        i2 = getarrayitem_gc_i(p0, 1, descr=arrayimmutdescr)
         escape_n(i2)
         jump(p0)
         """
         expected = """
         [p0]
-        i1 = getarrayitem_gc_pure_i(p0, 1, descr=arrayimmutdescr)
+        i1 = getarrayitem_gc_i(p0, 1, descr=arrayimmutdescr)
         escape_n(p0)
         escape_n(i1)
         jump(p0)
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py 
b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py
@@ -7869,7 +7869,7 @@
     def test_loopinvariant_getarrayitem_gc_pure(self):
         ops = """
         [p9, i1]
-        i843 = getarrayitem_gc_pure_i(p9, i1, descr=arrayimmutdescr)
+        i843 = getarrayitem_gc_i(p9, i1, descr=arrayimmutdescr)
         call_n(i843, descr=nonwritedescr)
         jump(p9, i1)
         """
@@ -8873,7 +8873,7 @@
         ptemp = new_with_vtable(descr=nodesize)
         setfield_gc(ptemp, p1, descr=nextdescr)
         p2 = getfield_gc_r(ptemp, descr=nextdescr)
-        ix = getarrayitem_gc_pure_i(p2, 0, descr=arrayimmutdescr)
+        ix = getarrayitem_gc_i(p2, 0, descr=arrayimmutdescr)
         pfoo = getfield_gc_r(ptemp, descr=nextdescr)
         guard_value(pfoo, ConstPtr(immutarray)) []
         ifoo = int_add(ix, 13)
@@ -8905,7 +8905,7 @@
     def test_constant_float_pure(self):
         ops = """
         [p0]
-        f0 = getarrayitem_gc_pure_f(p0, 3, descr=floatarrayimmutdescr)
+        f0 = getarrayitem_gc_f(p0, 3, descr=floatarrayimmutdescr)
         guard_value(f0, 1.03) []
         jump(p0)
         """
@@ -9141,7 +9141,7 @@
         [p0, i1]
         i2 = int_gt(i1, 0)
         guard_true(i2) []
-        getarrayitem_gc_pure_i(p0, 5, descr=arraydescr)
+        getarrayitem_gc_i(p0, 5, descr=arrayimmutdescr)
         i3 = int_sub(i1, 1)
         jump(NULL, i3)
         """
@@ -9152,7 +9152,7 @@
         [p0, i1]
         i2 = int_gt(i1, 0)
         guard_true(i2) []
-        getarrayitem_gc_pure_i(p0, 5, descr=arraydescr)
+        getarrayitem_gc_i(p0, 5, descr=arrayimmutdescr)
         i3 = int_sub(i1, 1)
         jump(ConstPtr(myptr3), i3)
         """
@@ -9163,7 +9163,7 @@
         [p0, i1]
         i2 = int_gt(i1, 0)
         guard_true(i2) []
-        getarrayitem_gc_pure_i(p0, 125, descr=arraydescr)
+        getarrayitem_gc_i(p0, 125, descr=arrayimmutdescr)
         i3 = int_sub(i1, 1)
         jump(ConstPtr(arrayref), i3)     # too short, length < 126!
         """
@@ -9174,7 +9174,7 @@
         [i0, i1]
         i2 = int_gt(i1, 0)
         guard_true(i2) []
-        getarrayitem_gc_pure_i(ConstPtr(arrayref), i0, descr=arraydescr)
+        getarrayitem_gc_i(ConstPtr(arrayref), i0, descr=arrayimmutdescr)
         i3 = int_sub(i1, 1)
         jump(125, i3)     # arrayref is too short, length < 126!
         """
@@ -9185,7 +9185,7 @@
         [i0, i1]
         i2 = int_gt(i1, 0)
         guard_true(i2) []
-        getarrayitem_gc_pure_i(ConstPtr(arrayref), i0, descr=arraydescr)
+        getarrayitem_gc_i(ConstPtr(arrayref), i0, descr=arrayimmutdescr)
         i3 = int_sub(i1, 1)
         jump(-1, i3)     # cannot access array item -1!
         """
diff --git a/rpython/jit/metainterp/optimizeopt/virtualize.py 
b/rpython/jit/metainterp/optimizeopt/virtualize.py
--- a/rpython/jit/metainterp/optimizeopt/virtualize.py
+++ b/rpython/jit/metainterp/optimizeopt/virtualize.py
@@ -286,12 +286,6 @@
     optimize_GETARRAYITEM_GC_R = optimize_GETARRAYITEM_GC_I
     optimize_GETARRAYITEM_GC_F = optimize_GETARRAYITEM_GC_I
 
-    # note: the following line does not mean that the two operations are
-    # completely equivalent, because GETARRAYITEM_GC_PURE is_always_pure().
-    optimize_GETARRAYITEM_GC_PURE_I = optimize_GETARRAYITEM_GC_I
-    optimize_GETARRAYITEM_GC_PURE_R = optimize_GETARRAYITEM_GC_I
-    optimize_GETARRAYITEM_GC_PURE_F = optimize_GETARRAYITEM_GC_I
-
     def optimize_SETARRAYITEM_GC(self, op):
         opinfo = self.getptrinfo(op.getarg(0))
         if opinfo and opinfo.is_virtual():
diff --git a/rpython/jit/metainterp/resoperation.py 
b/rpython/jit/metainterp/resoperation.py
--- a/rpython/jit/metainterp/resoperation.py
+++ b/rpython/jit/metainterp/resoperation.py
@@ -1281,14 +1281,6 @@
         return rop.GETFIELD_GC_I
 
     @staticmethod
-    def getarrayitem_pure_for_descr(descr):
-        if descr.is_array_of_pointers():
-            return rop.GETARRAYITEM_GC_PURE_R
-        elif descr.is_array_of_floats():
-            return rop.GETARRAYITEM_GC_PURE_F
-        return rop.GETARRAYITEM_GC_PURE_I
-
-    @staticmethod
     def getarrayitem_for_descr(descr):
         if descr.is_array_of_pointers():
             return rop.GETARRAYITEM_GC_R
@@ -1368,8 +1360,25 @@
     @staticmethod
     def is_pure_getfield(opnum, descr):
         if (opnum == rop.GETFIELD_GC_I or
-            opnum == rop.GETFIELD_GC_F or
-            opnum == rop.GETFIELD_GC_R):
+            opnum == rop.GETFIELD_GC_R or
+            opnum == rop.GETFIELD_GC_F):
+            return descr is not None and descr.is_always_pure()
+        return False
+
+    @staticmethod
+    def is_pure_getarrayitem(opnum, descr):
+        if (opnum == rop.GETARRAYITEM_GC_I or
+            opnum == rop.GETARRAYITEM_GC_R or
+            opnum == rop.GETARRAYITEM_GC_F):
+            return descr is not None and descr.is_always_pure()
+        return False
+
+    @staticmethod
+    def is_pure_arrayref(opnum, descr):
+        if (opnum == rop.GETARRAYITEM_GC_I or
+            opnum == rop.GETARRAYITEM_GC_R or
+            opnum == rop.GETARRAYITEM_GC_F or
+            opnum == rop.ARRAYLEN_GC):
             return descr is not None and descr.is_always_pure()
         return False
 
@@ -1401,10 +1410,7 @@
 
     @staticmethod
     def is_getarrayitem(opnum):
-        return opnum in (rop.GETARRAYITEM_GC_I, rop.GETARRAYITEM_GC_F,
-                         rop.GETARRAYITEM_GC_R, rop.GETARRAYITEM_GC_PURE_I,
-                         rop.GETARRAYITEM_GC_PURE_F,
-                         rop.GETARRAYITEM_GC_PURE_R)
+        return opnum in (rop.GETARRAYITEM_GC_I, rop.GETARRAYITEM_GC_F, 
rop.GETARRAYITEM_GC_R)
 
     @staticmethod
     def is_real_call(opnum):
@@ -1721,10 +1727,6 @@
     rop.GETARRAYITEM_RAW_F: rop.VEC_GETARRAYITEM_RAW_F,
     rop.GETARRAYITEM_GC_I: rop.VEC_GETARRAYITEM_GC_I,
     rop.GETARRAYITEM_GC_F: rop.VEC_GETARRAYITEM_GC_F,
-    # note that there is no _PURE operation for vector operations.
-    # reason: currently we do not care if it is pure or not!
-    rop.GETARRAYITEM_GC_PURE_I: rop.VEC_GETARRAYITEM_GC_I,
-    rop.GETARRAYITEM_GC_PURE_F: rop.VEC_GETARRAYITEM_GC_F,
     rop.RAW_STORE:        rop.VEC_RAW_STORE,
     rop.SETARRAYITEM_RAW: rop.VEC_SETARRAYITEM_RAW,
     rop.SETARRAYITEM_GC: rop.VEC_SETARRAYITEM_GC,
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to