Author: Carl Friedrich Bolz <cfb...@gmx.de> Branch: guard-compatible Changeset: r83194:a4b0c15a715b Date: 2016-03-20 14:09 +0100 http://bitbucket.org/pypy/pypy/changeset/a4b0c15a715b/
Log: only store the parts of the op that are needed in PureCallCondition, also deduplicate PureCallCondition diff --git a/rpython/jit/metainterp/compatible.py b/rpython/jit/metainterp/compatible.py --- a/rpython/jit/metainterp/compatible.py +++ b/rpython/jit/metainterp/compatible.py @@ -56,6 +56,9 @@ self.last_quasi_immut_field_op = None def record_condition(self, cond, res, optimizer): + for oldcond in self.conditions: + if oldcond.same_cond(cond, res): + return cond.activate(res, optimizer) self.conditions.append(cond) @@ -117,16 +120,22 @@ def activate_secondary(self, ref, loop_token): pass + def same_cond(self, other, res): + return False + class PureCallCondition(Condition): def __init__(self, op): - self.op = op + args = op.getarglist()[:] + args[1] = None + self.args = args + self.descr = op.getdescr() def check(self, cpu, ref): from rpython.rlib.debug import debug_print, debug_start, debug_stop - calldescr = self.op.getdescr() + calldescr = self.descr # change exactly the first argument - arglist = self.op.getarglist() + arglist = self.args arglist[1] = newconst(ref) try: res = do_call(cpu, arglist, calldescr) @@ -135,10 +144,27 @@ debug_print("call to elidable_compatible function raised") debug_stop("jit-guard-compatible") return False + finally: + arglist[1] = None if not res.same_constant(self.res): return False return True + def same_cond(self, other, res): + if type(other) != PureCallCondition: + return False + if len(self.args) != len(other.args): + return False + if not self.res.same_constant(res): + return False + assert self.args[1] is other.args[1] is None + for i in range(len(self.args)): + if i == 1: + continue + if not self.args[i].same_constant(other.args[i]): + return False + return True + class QuasiimmutGetfieldAndPureCallCondition(PureCallCondition): def __init__(self, op, qmutdescr): diff --git a/rpython/jit/metainterp/optimizeopt/test/test_compatible.py b/rpython/jit/metainterp/optimizeopt/test/test_compatible.py --- a/rpython/jit/metainterp/optimizeopt/test/test_compatible.py +++ b/rpython/jit/metainterp/optimizeopt/test/test_compatible.py @@ -109,3 +109,35 @@ assert descr._compatibility_conditions is not None assert descr._compatibility_conditions.known_valid.same_constant(ConstPtr(self.myptr)) assert len(descr._compatibility_conditions.conditions) == 2 + + def test_deduplicate_conditions(self): + call_pure_results = { + (ConstInt(123), ConstPtr(self.myptr)): ConstInt(5), + } + ops = """ + [p1] + guard_compatible(p1, ConstPtr(myptr)) [] + i3 = call_pure_i(123, p1, descr=plaincalldescr) + i4 = call_pure_i(123, p1, descr=plaincalldescr) + i5 = call_pure_i(123, p1, descr=plaincalldescr) + i6 = call_pure_i(123, p1, descr=plaincalldescr) + escape_n(i3) + escape_n(i4) + escape_n(i5) + escape_n(i6) + jump(ConstPtr(myptr)) + """ + expected = """ + [p1] + guard_compatible(p1, ConstPtr(myptr)) [] + escape_n(5) + escape_n(5) + escape_n(5) + escape_n(5) + jump(ConstPtr(myptr)) + """ + self.optimize_loop(ops, expected, call_pure_results=call_pure_results) + descr = self.loop.operations[1].getdescr() + assert descr._compatibility_conditions is not None + assert descr._compatibility_conditions.known_valid.same_constant(ConstPtr(self.myptr)) + assert len(descr._compatibility_conditions.conditions) == 1 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit