Commits

Carl Friedrich Bolz committed 341b780

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.

  • Participants
  • Parent commits c2f3df4
  • Branches small-unroll-improvements

Comments (0)

Files changed (2)

File rpython/jit/metainterp/optimizeopt/test/test_virtualstate.py

             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)

File rpython/jit/metainterp/optimizeopt/virtualstate.py

         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)