[pypy-commit] pypy int-tag-untag-as-operations: refactor the int_tag/untag optimization to fit the new style

cfbolz noreply at buildbot.pypy.org
Fri Nov 25 12:54:19 CET 2011


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: int-tag-untag-as-operations
Changeset: r49786:7ef7273f3fcc
Date: 2011-11-17 10:33 +0100
http://bitbucket.org/pypy/pypy/changeset/7ef7273f3fcc/

Log:	refactor the int_tag/untag optimization to fit the new style

diff --git a/pypy/jit/metainterp/optimizeopt/intbounds.py b/pypy/jit/metainterp/optimizeopt/intbounds.py
--- a/pypy/jit/metainterp/optimizeopt/intbounds.py
+++ b/pypy/jit/metainterp/optimizeopt/intbounds.py
@@ -171,18 +171,16 @@
     def optimize_GUARD_NO_OVERFLOW(self, op):
         lastop = self.last_emitted_operation
         if lastop is not None:
+            # If the INT_xxx_OVF was replaced with INT_xxx, then we can kill
+            # the GUARD_NO_OVERFLOW.
+            if not lastop.is_ovf():
+                return
             opnum = lastop.getopnum()
             args = lastop.getarglist()
             result = lastop.result
-            # If the INT_xxx_OVF was replaced with INT_xxx, then we can kill
-            # the GUARD_NO_OVERFLOW.
-            if (opnum == rop.INT_ADD or
-                opnum == rop.INT_SUB or
-                opnum == rop.INT_MUL):
-                return
             # Else, synthesize the non overflowing op for optimize_default to
-            # reuse, as well as the reverse op
-            elif opnum == rop.INT_ADD_OVF:
+            # reuse, as well as the reverse ops
+            if opnum == rop.INT_ADD_OVF:
                 self.pure(rop.INT_ADD, args[:], result)
                 self.pure(rop.INT_SUB, [result, args[1]], args[0])
                 self.pure(rop.INT_SUB, [result, args[0]], args[1])
@@ -192,6 +190,11 @@
                 self.pure(rop.INT_SUB, [args[0], result], args[1])
             elif opnum == rop.INT_MUL_OVF:
                 self.pure(rop.INT_MUL, args[:], result)
+            elif opnum == rop.INT_TAG_OVF:
+                v1 = self.getvalue(lastop.getarg(0))
+                maxbounds = IntBound((-sys.maxint-1) >> 1, sys.maxint >> 1)
+                v1.intbound.intersect(maxbounds)
+                self.pure(rop.INT_UNTAG, [result], args[0])
         self.emit_operation(op)
 
     def optimize_GUARD_OVERFLOW(self, op):
@@ -201,7 +204,7 @@
         if lastop is None:
             raise InvalidLoop
         opnum = lastop.getopnum()
-        if opnum not in (rop.INT_ADD_OVF, rop.INT_SUB_OVF, rop.INT_MUL_OVF):
+        if not lastop.is_ovf():
             raise InvalidLoop
         self.emit_operation(op)
 
@@ -307,18 +310,11 @@
         r = self.getvalue(op.result)
         resbound = v1.intbound.mul(2).add(1)
         r.intbound.intersect(resbound)
-        no_guard = False
-        if self.nextop.getopnum() == rop.GUARD_NO_OVERFLOW:
-            maxbounds = IntBound((-sys.maxint-1) >> 1, sys.maxint >> 1)
-            v1.intbound.intersect(maxbounds)
-            self.pure(rop.INT_UNTAG, [op.result], op.getarg(0))
-            no_guard = resbound.has_lower and resbound.has_upper
-        if no_guard:
+        if resbound.bounded():
             op = op.copy_and_change(rop.INT_TAG)
             self.optimize_INT_TAG(op) # emit the op
         else:
             self.emit_operation(op)
-            self.emit_operation(self.nextop)
 
     def optimize_INT_TAG(self, op):
         v1 = self.getvalue(op.getarg(0))


More information about the pypy-commit mailing list