Author: Carl Friedrich Bolz <cfb...@gmx.de> Branch: int-tag-untag-as-operations Changeset: r48367:c7b823622f57 Date: 2011-10-24 08:35 +0200 http://bitbucket.org/pypy/pypy/changeset/c7b823622f57/
Log: check that operations on untagged integers get their overflow checks removed 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 @@ -1,3 +1,4 @@ +import sys from pypy.jit.metainterp.optimizeopt.optimizer import Optimization, CONST_1, CONST_0, \ MODE_ARRAY, MODE_STR, MODE_UNICODE from pypy.jit.metainterp.history import ConstInt @@ -286,14 +287,25 @@ def optimize_INT_TAG(self, op): self.emit_operation(op) # XXX for now - self.emit_operation(self.nextop) + v1 = self.getvalue(op.getarg(0)) + 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 not no_guard: + self.emit_operation(self.nextop) def optimize_INT_UNTAG(self, op): + v1 = self.getvalue(op.getarg(0)) + self.pure(rop.INT_TAG, [op.result], op.getarg(0)) + r = self.getvalue(op.result) + r.intbound.intersect(v1.intbound.rshift_bound(IntBound(1, 1))) self.emit_operation(op) - self.pure(rop.INT_TAG, [op.result], op.getarg(0)) - def optimize_ARRAYLEN_GC(self, op): self.emit_operation(op) diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -5108,6 +5108,32 @@ """ self.optimize_loop(ops, expected) + def test_int_tag_remove_overflow_checking(self): + ops = """ + [i0] + i2 = int_tag(i0) + guard_no_overflow() [] + i3 = int_untag(i2) + i4 = int_add_ovf(i3, 1) + guard_no_overflow() [] + jump(i4) + """ + expected = """ + [i0] + i2 = int_tag(i0) + guard_no_overflow() [] + i3 = int_add(i0, 1) + jump(i3) + """ + preamble = """ + [i0] + i2 = int_tag(i0) + guard_no_overflow() [] + i3 = int_add(i0, 1) + jump(i3) + """ + self.optimize_loop(ops, expected, preamble) + def test_mul_ovf(self): ops = """ _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit