[pypy-commit] pypy default: Only strengthen guard_*_class to guard_value when the classes matches (might fix issue1207)
hakanardo
noreply at buildbot.pypy.org
Wed Jul 18 22:43:43 CEST 2012
Author: Hakan Ardo <hakan at debian.org>
Branch:
Changeset: r56199:5fcf9d1c9713
Date: 2012-07-18 22:37 +0200
http://bitbucket.org/pypy/pypy/changeset/5fcf9d1c9713/
Log: Only strengthen guard_*_class to guard_value when the classes
matches (might fix issue1207)
diff --git a/pypy/jit/metainterp/optimizeopt/rewrite.py b/pypy/jit/metainterp/optimizeopt/rewrite.py
--- a/pypy/jit/metainterp/optimizeopt/rewrite.py
+++ b/pypy/jit/metainterp/optimizeopt/rewrite.py
@@ -241,6 +241,16 @@
# guard_nonnull_class on this value, which is rather silly.
# replace the original guard with a guard_value
old_guard_op = value.last_guard
+ if old_guard_op.getopnum() != rop.GUARD_NONNULL:
+ # 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)
+ expected_classbox = self.optimizer.cpu.ts.cls_of_box(op.getarg(1))
+ assert previous_classbox is not None
+ assert expected_classbox is not None
+ if not previous_classbox.same_constant(expected_classbox):
+ raise InvalidLoop('A GUARD_VALUE was proven to always fail')
op = old_guard_op.copy_and_change(rop.GUARD_VALUE,
args = [old_guard_op.getarg(0), op.getarg(1)])
self.optimizer.replaces_guard[op] = old_guard_op
@@ -251,6 +261,8 @@
assert isinstance(descr, compile.ResumeGuardDescr)
descr.guard_opnum = rop.GUARD_VALUE
descr.make_a_counter_per_value(op)
+ # to be safe
+ value.last_guard = None
constbox = op.getarg(1)
assert isinstance(constbox, Const)
self.optimize_guard(op, constbox)
diff --git a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_optimizeopt.py
@@ -7862,6 +7862,17 @@
"""
self.optimize_loop(ops, expected)
+ def test_only_strengthen_guard_if_class_matches(self):
+ ops = """
+ [p1]
+ guard_class(p1, ConstClass(node_vtable2)) []
+ guard_value(p1, ConstPtr(myptr)) []
+ jump(p1)
+ """
+ self.raises(InvalidLoop, self.optimize_loop,
+ ops, ops)
+
+
class TestLLtype(OptimizeOptTest, LLtypeMixin):
pass
More information about the pypy-commit
mailing list