Author: Carl Friedrich Bolz <[email protected]>
Branch: small-unroll-improvements
Changeset: r70434:341b7805d985
Date: 2014-04-04 13:09 +0200
http://bitbucket.org/pypy/pypy/changeset/341b7805d985/
Log: add one of the "Remaining cases are probably not interesting". When
jumping to a loop that expects something to be a constant, it's fine
to invent a new guard_value.
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py
b/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py
@@ -252,7 +252,24 @@
guards = []
vstate2.generate_guards(vstate3, [self.nodebox, self.nodebox],
self.cpu, guards)
-
+
+ def test_known_value_virtualstate(self):
+ box1 = BoxInt(1)
+ box2 = BoxInt(1)
+ value1 = OptValue(box1)
+ value2 = OptValue(box2)
+ value1.make_constant(ConstInt(1))
+ vstate1 = VirtualState([NotVirtualStateInfo(value1)])
+ vstate2 = VirtualState([NotVirtualStateInfo(value2)])
+ expected = """
+ [i0]
+ guard_value(i0, 1) []
+ """
+ guards = []
+ vstate1.generate_guards(vstate2, [box2], self.cpu, guards)
+ self.compare(guards, expected, [box2])
+
+
def test_virtuals_with_equal_fields(self):
info1 = VirtualStateInfo(ConstInt(42), [1, 2])
value = OptValue(self.nodebox)
diff --git a/rpython/jit/metainterp/optimizeopt/virtualstate.py
b/rpython/jit/metainterp/optimizeopt/virtualstate.py
--- a/rpython/jit/metainterp/optimizeopt/virtualstate.py
+++ b/rpython/jit/metainterp/optimizeopt/virtualstate.py
@@ -360,16 +360,20 @@
if self.is_opaque:
raise InvalidLoop('Generating guards for opaque pointers is not
safe')
+ # the following conditions always peek into the runtime value that the
+ # box had when tracing. This value is only used as an educated guess.
+ # It is used here to choose between either emitting a guard and jumping
+ # to an existing compiled loop or retracing the loop. Both alternatives
+ # will always generate correct behaviour, but performance will differ.
+ if (self.level == LEVEL_CONSTANT and
+ self.constbox.same_constant(box.constbox())):
+ op = ResOperation(rop.GUARD_VALUE, [box, self.constbox], None)
+ extra_guards.append(op)
+ return
+
if self.level == LEVEL_KNOWNCLASS and \
box.nonnull() and \
self.known_class.same_constant(cpu.ts.cls_of_box(box)):
- # Note: This is only a hint on what the class of box was
- # during the trace. There are actually no guarentees that this
- # box realy comes from a trace. The hint is used here to choose
- # between either eimtting a guard_class and jumping to an
- # excisting compiled loop or retracing the loop. Both
- # alternatives will always generate correct behaviour, but
- # performace will differ.
op = ResOperation(rop.GUARD_NONNULL, [box], None)
extra_guards.append(op)
op = ResOperation(rop.GUARD_CLASS, [box, self.known_class], None)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit