Author: Maciej Fijalkowski <[email protected]>
Branch: fast-slowpath
Changeset: r65626:840cbb52a15f
Date: 2013-07-24 21:21 +0200
http://bitbucket.org/pypy/pypy/changeset/840cbb52a15f/
Log: a crucial optimizations
diff --git a/rpython/jit/metainterp/optimizeopt/rewrite.py
b/rpython/jit/metainterp/optimizeopt/rewrite.py
--- a/rpython/jit/metainterp/optimizeopt/rewrite.py
+++ b/rpython/jit/metainterp/optimizeopt/rewrite.py
@@ -250,7 +250,7 @@
# This is only safe if the class of the guard_value matches the
# class of the guard_*_class, otherwise the intermediate ops
might
# be executed with wrong classes.
- previous_classbox =
value.get_constant_class(self.optimizer.cpu)
+ previous_classbox =
value.get_constant_class(self.optimizer.cpu)
expected_classbox =
self.optimizer.cpu.ts.cls_of_box(op.getarg(1))
assert previous_classbox is not None
assert expected_classbox is not None
@@ -343,6 +343,15 @@
resvalue = self.getvalue(op.result)
self.loop_invariant_results[key] = resvalue
+ def optimize_COND_CALL(self, op):
+ arg = op.getarg(0)
+ val = self.getvalue(arg)
+ if val.is_constant():
+ if val.box.same_constant(CONST_0):
+ return
+ op = op.copy_and_change(rop.CALL, args=op.getarglist()[1:])
+ self.emit_operation(op)
+
def _optimize_nullness(self, op, box, expect_nonnull):
value = self.getvalue(box)
if value.is_nonnull():
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
@@ -54,7 +54,7 @@
expected_short = self.parse(expected_short)
preamble = self.unroll_and_optimize(loop, call_pure_results)
-
+
#
print
print "Preamble:"
@@ -219,7 +219,7 @@
"""
self.optimize_loop(ops, expected)
- def test_reverse_of_cast_2(self):
+ def test_reverse_of_cast_2(self):
ops = """
[p0]
i1 = cast_ptr_to_int(p0)
@@ -1290,7 +1290,7 @@
p30 = new_with_vtable(ConstClass(node_vtable))
setfield_gc(p30, i28, descr=nextdescr)
setfield_gc(p3, p30, descr=valuedescr)
- p46 = same_as(p30) # This same_as should be killed by backend
+ p46 = same_as(p30) # This same_as should be killed by backend
jump(i29, p30, p3)
"""
expected = """
@@ -2582,7 +2582,7 @@
p2 = new_with_vtable(ConstClass(node_vtable))
setfield_gc(p2, p4, descr=nextdescr)
setfield_gc(p1, p2, descr=nextdescr)
- i101 = same_as(i4)
+ i101 = same_as(i4)
jump(p1, i2, i4, p4, i101)
"""
expected = """
@@ -3440,7 +3440,7 @@
setfield_gc(p1, i1, descr=valuedescr)
i3 = call_assembler(i1, descr=asmdescr)
setfield_gc(p1, i3, descr=valuedescr)
- i143 = same_as(i3) # Should be killed by backend
+ i143 = same_as(i3) # Should be killed by backend
jump(p1, i4, i3)
'''
self.optimize_loop(ops, ops, preamble)
@@ -3551,7 +3551,7 @@
escape(i2)
i4 = call(123456, 4, i0, 6, descr=plaincalldescr)
guard_no_exception() []
- i155 = same_as(i4)
+ i155 = same_as(i4)
jump(i0, i4, i155)
'''
expected = '''
@@ -6000,7 +6000,7 @@
[p1, i1, i2, i3]
escape(i3)
i4 = int_sub(i2, i1)
- i5 = same_as(i4)
+ i5 = same_as(i4)
jump(p1, i1, i2, i4, i5)
"""
expected = """
@@ -7258,7 +7258,7 @@
[i0]
i2 = int_lt(i0, 10)
guard_true(i2) []
- i1 = int_add(i0, 1)
+ i1 = int_add(i0, 1)
jump(i1)
"""
self.optimize_loop(ops, expected)
@@ -7976,7 +7976,7 @@
jump(i0, p0, i2)
"""
self.optimize_loop(ops, expected)
-
+
def test_constant_failargs(self):
ops = """
[p1, i2, i3]
@@ -8057,7 +8057,7 @@
jump()
"""
self.optimize_loop(ops, expected)
-
+
def test_issue1080_infinitie_loop_simple(self):
ops = """
@@ -8089,8 +8089,8 @@
def test_licm_boxed_opaque_getitem(self):
ops = """
[p1]
- p2 = getfield_gc(p1, descr=nextdescr)
- mark_opaque_ptr(p2)
+ p2 = getfield_gc(p1, descr=nextdescr)
+ mark_opaque_ptr(p2)
guard_class(p2, ConstClass(node_vtable)) []
i3 = getfield_gc(p2, descr=otherdescr)
i4 = call(i3, descr=nonwritedescr)
@@ -8106,8 +8106,8 @@
def test_licm_boxed_opaque_getitem_unknown_class(self):
ops = """
[p1]
- p2 = getfield_gc(p1, descr=nextdescr)
- mark_opaque_ptr(p2)
+ p2 = getfield_gc(p1, descr=nextdescr)
+ mark_opaque_ptr(p2)
i3 = getfield_gc(p2, descr=otherdescr)
i4 = call(i3, descr=nonwritedescr)
jump(p1)
@@ -8123,7 +8123,7 @@
def test_licm_unboxed_opaque_getitem(self):
ops = """
[p2]
- mark_opaque_ptr(p2)
+ mark_opaque_ptr(p2)
guard_class(p2, ConstClass(node_vtable)) []
i3 = getfield_gc(p2, descr=otherdescr)
i4 = call(i3, descr=nonwritedescr)
@@ -8139,22 +8139,20 @@
def test_licm_unboxed_opaque_getitem_unknown_class(self):
ops = """
[p2]
- mark_opaque_ptr(p2)
+ mark_opaque_ptr(p2)
i3 = getfield_gc(p2, descr=otherdescr)
i4 = call(i3, descr=nonwritedescr)
jump(p2)
"""
expected = """
[p2]
- i3 = getfield_gc(p2, descr=otherdescr)
+ i3 = getfield_gc(p2, descr=otherdescr)
i4 = call(i3, descr=nonwritedescr)
jump(p2)
"""
self.optimize_loop(ops, expected)
-
-
- def test_only_strengthen_guard_if_class_matches(self):
+ def test_only_strengthen_guard_if_class_matches_2(self):
ops = """
[p1]
guard_class(p1, ConstClass(node_vtable2)) []
@@ -8164,6 +8162,30 @@
self.raises(InvalidLoop, self.optimize_loop,
ops, ops)
+ def test_cond_call_with_a_constant(self):
+ ops = """
+ [p1]
+ cond_call(1, 123, p1, descr=plaincalldescr)
+ jump(p1)
+ """
+ expected = """
+ [p1]
+ call(123, p1, descr=plaincalldescr)
+ jump(p1)
+ """
+ self.optimize_loop(ops, expected)
+
+ def test_cond_call_with_a_constant_2(self):
+ ops = """
+ [p1]
+ cond_call(0, 123, p1, descr=plaincalldescr)
+ jump(p1)
+ """
+ expected = """
+ [p1]
+ jump(p1)
+ """
+ self.optimize_loop(ops, expected)
class TestLLtype(OptimizeOptTest, LLtypeMixin):
pass
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit