Commits

Maciej Fijalkowski committed 9c5843a

Transplant changes from out-of-line guards that are relevant to
optimizeopt. Notably: ccf0847294c02a4d96bbfa36f5a2268e3ceb

  • Participants
  • Parent commits 76034ab
  • Branches guard-improvements

Comments (0)

Files changed (3)

File pypy/jit/metainterp/optimizeopt/optimizer.py

         self.interned_refs = self.cpu.ts.new_ref_dict()
         self.resumedata_memo = resume.ResumeDataLoopMemo(metainterp_sd)
         self.bool_boxes = {}
+        self.int_to_bool_nullity = {} # a mapping from bool boxes to
+        # respective ints, to know their value
         self.loop_invariant_results = {}
         self.pure_operations = args_dict()
         self.producer = {}

File pypy/jit/metainterp/optimizeopt/rewrite.py

         self.optimize_guard(op, constbox, emit_operation, dryrun)
 
     def optimize_GUARD_TRUE(self, op, dryrun=False):
+        value = self.getvalue(op.getarg(0))
+        v = self.optimizer.int_to_bool_nullity.get(value)
+        if v:
+            v, int_is_true = v
+            if int_is_true:
+                if not v.is_nonnull():
+                    v.make_nonnull(len(self.optimizer.newoperations) - 1)
+            else:
+                v.make_constant(CONST_0)
         self.optimize_guard(op, CONST_1, dryrun=dryrun)
 
     def optimize_GUARD_FALSE(self, op, dryrun=False):
+        value = self.getvalue(op.getarg(0))
+        v = self.optimizer.int_to_bool_nullity.get(value)
+        if v:
+            v, int_is_true = v
+            if int_is_true:
+                v.make_constant(ConstInt(0))
+            elif not v.is_nonnull():
+                v.make_nonnull(len(self.optimizer.newoperations) - 1)
         self.optimize_guard(op, CONST_0, dryrun=dryrun)
 
     def optimize_GUARD_CLASS(self, op, dryrun=False):
             self.emit_operation(op)
 
     def optimize_INT_IS_TRUE(self, op):
-        if self.getvalue(op.getarg(0)) in self.optimizer.bool_boxes:
-            self.make_equal_to(op.result, self.getvalue(op.getarg(0)))
+        v = self.getvalue(op.getarg(0))
+        if v in self.optimizer.bool_boxes:
+            self.make_equal_to(op.result, v)
             return
         self._optimize_nullness(op, op.getarg(0), True)
+        self.optimizer.int_to_bool_nullity[self.getvalue(op.result)] = (v, True)
 
     def optimize_INT_IS_ZERO(self, op):
+        v = self.getvalue(op.getarg(0))
         self._optimize_nullness(op, op.getarg(0), False)
+        self.optimizer.int_to_bool_nullity[self.getvalue(op.result)] = (v,
+                                                                        False)
 
     def _optimize_oois_ooisnot(self, op, expect_isnot):
         value0 = self.getvalue(op.getarg(0))

File pypy/jit/metainterp/test/test_optimizeopt.py

         self.optimize_loop(ops, expected, preamble)
 
     def test_int_is_true_is_zero(self):
-        py.test.skip("XXX implement me")
         ops = """
         [i0]
         i1 = int_is_true(i0)
         """
         self.optimize_loop(ops, expected)
 
+    def test_int_is_true_is_zero2(self):
+        ops = """
+        [i0]
+        i2 = int_is_zero(i0)
+        guard_false(i2) []
+        i1 = int_is_true(i0)
+        guard_true(i1) []
+        jump(i0)
+        """
+        expected = """
+        [i0]
+        i1 = int_is_zero(i0)
+        guard_false(i1) []
+        jump(i0)
+        """
+        self.optimize_loop(ops, 'Not', expected)
+
     def test_ooisnull_oononnull_2(self):
         ops = """
         [p0]
         # can be raised by ll_str2unicode()
 
 
-
 ##class TestOOtype(OptimizeOptTest, OOtypeMixin):
 
 ##    def test_instanceof(self):