Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r56455:42d7b417d645 Date: 2012-07-26 09:49 +0200 http://bitbucket.org/pypy/pypy/changeset/42d7b417d645/
Log: Fix test_newlist() and improve it. Don't generate int_force_ge_zero() on constant arguments. diff --git a/pypy/jit/codewriter/jtransform.py b/pypy/jit/codewriter/jtransform.py --- a/pypy/jit/codewriter/jtransform.py +++ b/pypy/jit/codewriter/jtransform.py @@ -1430,10 +1430,19 @@ def do_fixed_newlist(self, op, args, arraydescr): v_length = self._get_initial_newlist_length(op, args) - v = Variable('new_length') - v.concretetype = lltype.Signed - return [SpaceOperation('int_force_ge_zero', [v_length], v), - SpaceOperation('new_array', [arraydescr, v], op.result)] + assert v_length.concretetype is lltype.Signed + ops = [] + if isinstance(v_length, Constant): + if v_length.value >= 0: + v = v_length + else: + v = Constant(0, lltype.Signed) + else: + v = Variable('new_length') + v.concretetype = lltype.Signed + ops.append(SpaceOperation('int_force_ge_zero', [v_length], v)) + ops.append(SpaceOperation('new_array', [arraydescr, v], op.result)) + return ops def do_fixed_list_len(self, op, args, arraydescr): if args[0] in self.vable_array_vars: # virtualizable array diff --git a/pypy/jit/codewriter/test/test_list.py b/pypy/jit/codewriter/test/test_list.py --- a/pypy/jit/codewriter/test/test_list.py +++ b/pypy/jit/codewriter/test/test_list.py @@ -85,8 +85,11 @@ """new_array <ArrayDescr>, $0 -> %r0""") builtin_test('newlist', [Constant(5, lltype.Signed)], FIXEDLIST, """new_array <ArrayDescr>, $5 -> %r0""") + builtin_test('newlist', [Constant(-2, lltype.Signed)], FIXEDLIST, + """new_array <ArrayDescr>, $0 -> %r0""") builtin_test('newlist', [varoftype(lltype.Signed)], FIXEDLIST, - """new_array <ArrayDescr>, %i0 -> %r0""") + """int_force_ge_zero %i0 -> %i1\n""" + """new_array <ArrayDescr>, %i1 -> %r0""") builtin_test('newlist', [Constant(5, lltype.Signed), Constant(0, lltype.Signed)], FIXEDLIST, """new_array <ArrayDescr>, $5 -> %r0""") _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit