[pypy-commit] pypy default: some passing cases, and comments how they work
cfbolz
pypy.commits at gmail.com
Wed Oct 11 04:41:44 EDT 2017
Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch:
Changeset: r92713:47ef5366ae73
Date: 2017-10-11 10:41 +0200
http://bitbucket.org/pypy/pypy/changeset/47ef5366ae73/
Log: some passing cases, and comments how they work
diff --git a/rpython/jit/metainterp/optimizeopt/intbounds.py b/rpython/jit/metainterp/optimizeopt/intbounds.py
--- a/rpython/jit/metainterp/optimizeopt/intbounds.py
+++ b/rpython/jit/metainterp/optimizeopt/intbounds.py
@@ -305,6 +305,10 @@
# Transform into INT_ADD. The following guard will be killed
# by optimize_GUARD_NO_OVERFLOW; if we see instead an
# optimize_GUARD_OVERFLOW, then InvalidLoop.
+
+ # NB: this case also takes care of int_add_ovf with 0 as on of the
+ # arguments: the result will be bounded, and then the optimization
+ # for int_add with 0 as argument will remove the op.
op = self.replace_op_with(op, rop.INT_ADD)
return self.emit(op)
@@ -325,6 +329,7 @@
return None
resbound = b0.sub_bound(b1)
if resbound.bounded():
+ # this case takes care of int_sub_ovf(x, 0) as well
op = self.replace_op_with(op, rop.INT_SUB)
return self.emit(op)
@@ -342,6 +347,7 @@
b2 = self.getintbound(op.getarg(1))
resbound = b1.mul_bound(b2)
if resbound.bounded():
+ # this case also takes care of multiplication with 0 and 1
op = self.replace_op_with(op, rop.INT_MUL)
return self.emit(op)
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
@@ -1962,6 +1962,55 @@
"""
self.optimize_loop(ops, expected)
+ ops = """
+ [i0]
+ i1 = int_mul_ovf(0, i0)
+ guard_no_overflow() []
+ jump(i1)
+ """
+ expected = """
+ [i0]
+ jump(0)
+ """
+ self.optimize_loop(ops, expected)
+
+ ops = """
+ [i0]
+ i1 = int_mul_ovf(i0, 0)
+ guard_no_overflow() []
+ jump(i1)
+ """
+ expected = """
+ [i0]
+ jump(0)
+ """
+ self.optimize_loop(ops, expected)
+
+ ops = """
+ [i0]
+ i1 = int_mul_ovf(1, i0)
+ guard_no_overflow() []
+ jump(i1)
+ """
+ expected = """
+ [i0]
+ jump(i0)
+ """
+ self.optimize_loop(ops, expected)
+
+ ops = """
+ [i0]
+ i1 = int_mul_ovf(i0, 1)
+ guard_no_overflow() []
+ jump(i1)
+ """
+ expected = """
+ [i0]
+ jump(i0)
+ """
+ self.optimize_loop(ops, expected)
+
+
def test_fold_constant_partial_ops_float(self):
ops = """
[f0]
More information about the pypy-commit
mailing list