[pypy-commit] pypy default: the optimization does not actually work for -maxint-1
cfbolz
noreply at buildbot.pypy.org
Thu Mar 5 15:19:06 CET 2015
Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch:
Changeset: r76249:58bec7621db5
Date: 2015-03-05 15:17 +0100
http://bitbucket.org/pypy/pypy/changeset/58bec7621db5/
Log: the optimization does not actually work for -maxint-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
@@ -862,6 +862,7 @@
return resbox.constbox()
def pure_reverse(self, op):
+ import sys
if self.optpure is None:
return
optpure = self.optpure
@@ -875,10 +876,14 @@
if isinstance(arg0, ConstInt):
# invert the constant
i0 = arg0.getint()
+ if i0 == -sys.maxint - 1:
+ return
inv_arg0 = ConstInt(-i0)
elif isinstance(arg1, ConstInt):
# commutative
i0 = arg1.getint()
+ if i0 == -sys.maxint - 1:
+ return
inv_arg0 = ConstInt(-i0)
arg1 = arg0
else:
@@ -896,6 +901,8 @@
if isinstance(arg1, ConstInt):
# invert the constant
i1 = arg1.getint()
+ if i1 == -sys.maxint - 1:
+ return
inv_arg1 = ConstInt(-i1)
optpure.pure(rop.INT_ADD, [arg0, inv_arg1], op.result)
optpure.pure(rop.INT_ADD, [inv_arg1, arg0], op.result)
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
@@ -3704,6 +3704,7 @@
self.optimize_loop(ops, expected)
def test_int_add_sub_constants_inverse(self):
+ import sys
ops = """
[i0, i10, i11, i12, i13]
i2 = int_add(1, i0)
@@ -3748,6 +3749,14 @@
jump(i0, i2, i2, i2, i0, -1)
"""
self.optimize_loop(ops, expected)
+ ops = """
+ [i0, i10, i11, i12]
+ i2 = int_add(%s, i0)
+ i3 = int_add(i2, %s)
+ i4 = int_sub(i0, %s)
+ jump(i0, i2, i3, i4)
+ """ % ((-sys.maxint - 1, ) * 3)
+ self.optimize_loop(ops, ops) # does not crash
def test_framestackdepth_overhead(self):
ops = """
More information about the pypy-commit
mailing list