Author: Alex Gaynor <alex.gay...@gmail.com> Branch: Changeset: r48350:13caa6fd920e Date: 2011-10-22 17:01 -0700 http://bitbucket.org/pypy/pypy/changeset/13caa6fd920e/
Log: optimize int_floordiv(0, i) to always return 0. diff --git a/pypy/jit/metainterp/optimizeopt/rewrite.py b/pypy/jit/metainterp/optimizeopt/rewrite.py --- a/pypy/jit/metainterp/optimizeopt/rewrite.py +++ b/pypy/jit/metainterp/optimizeopt/rewrite.py @@ -448,6 +448,9 @@ if v2.is_constant() and v2.box.getint() == 1: self.make_equal_to(op.result, v1) return + elif v1.is_constant() and v1.box.getint() == 0: + self.make_constant_int(op.result, 0) + return if v1.intbound.known_ge(IntBound(0, 0)) and v2.is_constant(): val = v2.box.getint() if val & (val - 1) == 0 and val > 0: # val == 2**shift diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py --- a/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py +++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizebasic.py @@ -2181,6 +2181,17 @@ """ self.optimize_loop(ops, expected) + ops = """ + [i0] + i1 = int_floordiv(0, i0) + jump(i1) + """ + expected = """ + [i0] + jump(0) + """ + self.optimize_loop(ops, expected) + def test_fold_partially_constant_ops_ovf(self): ops = """ [i0] _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit