[pypy-svn] r74600 - in pypy/branch/blackhole-improvement/pypy/jit/codewriter: . test
arigo at codespeak.net
arigo at codespeak.net
Thu May 20 16:25:28 CEST 2010
Author: arigo
Date: Thu May 20 16:25:26 2010
New Revision: 74600
Modified:
pypy/branch/blackhole-improvement/pypy/jit/codewriter/jtransform.py
pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jtransform.py
Log:
Optimize a case that occurs in practice (see comment).
Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/jtransform.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/jtransform.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/jtransform.py Thu May 20 16:25:26 2010
@@ -123,9 +123,6 @@
if (v == c_last_exception or isinstance(v, tuple)
or v.concretetype != lltype.Bool):
return False
- for link in block.exits:
- if v in link.args:
- return False # variable escapes to next block
for op in block.operations[::-1]:
if v in op.args:
return False # variable is also used in cur block
@@ -139,6 +136,13 @@
# ok! optimize this case
block.operations.remove(op)
block.exitswitch = (op.opname,) + tuple(op.args)
+ # if the variable escape to the next block along a link,
+ # replace it with a constant, because we know its value
+ for link in block.exits:
+ while v in link.args:
+ index = link.args.index(v)
+ link.args[index] = Constant(link.llexitcase,
+ lltype.Bool)
return True
return False
Modified: pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jtransform.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jtransform.py (original)
+++ pypy/branch/blackhole-improvement/pypy/jit/codewriter/test/test_jtransform.py Thu May 20 16:25:26 2010
@@ -91,15 +91,22 @@
assert not Transformer().optimize_goto_if_not(block)
def test_optimize_goto_if_not__exit():
+ # this case occurs in practice, e.g. with RPython code like:
+ # return bool(p) and p.somefield > 0
v1 = Variable()
v2 = Variable()
v3 = Variable(); v3.concretetype = lltype.Bool
block = Block([v1, v2])
block.operations = [SpaceOperation('int_gt', [v1, v2], v3)]
block.exitswitch = v3
- block.exits = [FakeLink(False), FakeLink(True)]
+ block.exits = exits = [FakeLink(False), FakeLink(True)]
block.exits[1].args = [v3]
- assert not Transformer().optimize_goto_if_not(block)
+ res = Transformer().optimize_goto_if_not(block)
+ assert res == True
+ assert block.operations == []
+ assert block.exitswitch == ('int_gt', v1, v2)
+ assert block.exits == exits
+ assert exits[1].args == [Constant(True, lltype.Bool)]
def test_optimize_goto_if_not__unknownop():
v3 = Variable(); v3.concretetype = lltype.Bool
More information about the Pypy-commit
mailing list