Author: Stefan Marr <h...@stefan-marr.de> Branch: Changeset: r71628:919ab79173d3 Date: 2014-05-21 11:33 +0100 http://bitbucket.org/pypy/pypy/changeset/919ab79173d3/
Log: (cfbolz, smarr): optimize int_sub_ovf(x, x) to 0 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 @@ -198,11 +198,11 @@ 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): + # If the INT_xxx_OVF was replaced with INT_xxx or removed + # completely, then we can kill the GUARD_NO_OVERFLOW. + if (opnum != rop.INT_ADD_OVF and + opnum != rop.INT_SUB_OVF and + opnum != rop.INT_MUL_OVF): return # Else, synthesize the non overflowing op for optimize_default to # reuse, as well as the reverse op @@ -248,6 +248,9 @@ def optimize_INT_SUB_OVF(self, op): v1 = self.getvalue(op.getarg(0)) v2 = self.getvalue(op.getarg(1)) + if v1 is v2: + self.make_constant_int(op.result, 0) + return resbound = v1.intbound.sub_bound(v2.intbound) if resbound.bounded(): op = op.copy_and_change(rop.INT_SUB) diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -3339,6 +3339,21 @@ """ self.optimize_loop(ops, expected) + def test_fold_int_sub_ovf_xx(self): + ops = """ + [i0] + i1 = int_sub_ovf(i0, i0) + guard_no_overflow() [] + escape(i1) + jump(i1) + """ + expected = """ + [] + escape(0) + jump() + """ + self.optimize_loop(ops, expected) + def test_fold_partially_constant_shift(self): ops = """ [i0] _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit