Author: Maciej Fijalkowski <fij...@gmail.com>
Branch: share-guard-info
Changeset: r79798:30d0f05cdae5
Date: 2015-09-23 19:46 +0200
http://bitbucket.org/pypy/pypy/changeset/30d0f05cdae5/

Log:    fix heap.py, but a huge blunder in check_history too, fixing tests

diff --git a/rpython/jit/metainterp/history.py 
b/rpython/jit/metainterp/history.py
--- a/rpython/jit/metainterp/history.py
+++ b/rpython/jit/metainterp/history.py
@@ -540,6 +540,9 @@
     def check_consistency_of_branch(operations, seen, check_descr=True):
         "NOT_RPYTHON"
         for num, op in enumerate(operations):
+            if op.is_ovf():
+                assert operations[num + 1].getopnum() in 
(rop.GUARD_NO_OVERFLOW,
+                                                          rop.GUARD_OVERFLOW)
             for i in range(op.numargs()):
                 box = op.getarg(i)
                 if not isinstance(box, Const):
@@ -750,7 +753,6 @@
         return tokens
 
     def check_history(self, expected=None, **check):
-        return
         insns = {}
         for op in self.operations:
             opname = op.getopname()
diff --git a/rpython/jit/metainterp/optimizeopt/heap.py 
b/rpython/jit/metainterp/optimizeopt/heap.py
--- a/rpython/jit/metainterp/optimizeopt/heap.py
+++ b/rpython/jit/metainterp/optimizeopt/heap.py
@@ -298,9 +298,18 @@
                     origin_pc == op.rd_frame_info_list.pc):
                     self.optimizer.origin_jitcode = None
                     self.optimizer.origin_pc = 0
+                elif op.getopnum() == rop.GUARD_NO_OVERFLOW:
+                    if self.postponed_op:
+                        # XXX is this always the case?
+                        assert self.postponed_op.is_ovf()
+                        newop = self.optimizer.replace_op_with_no_ovf(
+                            self.postponed_op)
+                        self.postponed_op = newop
+                    else:
+                        self.optimizer.potentially_change_ovf_op_to_no_ovf(op)
+                    return # we optimize the guard
                 elif op.getopnum() != rop.GUARD_OVERFLOW:
-                    self.optimizer.potentially_change_ovf_op_to_no_ovf(op)
-                    return # we optimize the guard
+                    return
         
         self.emitting_operation(op)
         self.emit_postponed_op()
diff --git a/rpython/jit/metainterp/optimizeopt/optimizer.py 
b/rpython/jit/metainterp/optimizeopt/optimizer.py
--- a/rpython/jit/metainterp/optimizeopt/optimizer.py
+++ b/rpython/jit/metainterp/optimizeopt/optimizer.py
@@ -616,15 +616,19 @@
         op = self._newoperations[-1]
         if not op.is_ovf():
             return
+        newop = self.replace_op_with_no_ovf(op)
+        self._newoperations[-1] = newop
+
+    def replace_op_with_no_ovf(self, op):
         if op.getopnum() == rop.INT_MUL_OVF:
-            newop = self.replace_op_with(op, rop.INT_MUL)
+            return self.replace_op_with(op, rop.INT_MUL)
         elif op.getopnum() == rop.INT_ADD_OVF:
-            newop = self.replace_op_with(op, rop.INT_ADD)
+            return self.replace_op_with(op, rop.INT_ADD)
         elif op.getopnum() == rop.INT_SUB_OVF:
-            newop = self.replace_op_with(op, rop.INT_SUB)
+            return self.replace_op_with(op, rop.INT_SUB)
         else:
             assert False
-        self._newoperations[-1] = newop
+
 
     def _copy_resume_data_from(self, guard_op, last_guard_op):
         if guard_op.getopnum() in (rop.GUARD_NO_EXCEPTION, 
rop.GUARD_EXCEPTION):
diff --git a/rpython/jit/metainterp/test/test_ajit.py 
b/rpython/jit/metainterp/test/test_ajit.py
--- a/rpython/jit/metainterp/test/test_ajit.py
+++ b/rpython/jit/metainterp/test/test_ajit.py
@@ -406,7 +406,7 @@
             return externfn(n, n+1)
         res = self.interp_operations(f, [6])
         assert res == 42
-        self.check_operations_history(int_add=1, int_mul=0, call=1, 
guard_no_exception=0)
+        self.check_operations_history(int_add=1, int_mul=0, call_i=1, 
guard_no_exception=0)
 
     def test_residual_call_elidable(self):
         def externfn(x, y):
@@ -419,7 +419,7 @@
         assert res == 42
         # CALL_PURE is not recorded in the history if all-constant args
         self.check_operations_history(int_add=0, int_mul=0,
-                                      call=0, call_pure_i=0)
+                                      call_i=0, call_pure_i=0)
 
     def test_residual_call_elidable_1(self):
         @elidable
@@ -431,7 +431,7 @@
         assert res == 42
         # CALL_PURE is recorded in the history if not-all-constant args
         self.check_operations_history(int_add=1, int_mul=0,
-                                      call=0, call_pure_i=1)
+                                      call_i=0, call_pure_i=1)
 
     def test_residual_call_elidable_2(self):
         myjitdriver = JitDriver(greens = [], reds = ['n'])
@@ -659,11 +659,11 @@
         #
         res = self.meta_interp(f, [3, 6], repeat=7, function_threshold=0)
         assert res == 6 - 4 - 5
-        self.check_history(call=0)   # because the trace starts in the middle
+        self.check_history(call_n=0)   # because the trace starts in the middle
         #
         res = self.meta_interp(f, [60, 84], repeat=7)
         assert res == 84 - 61 - 62
-        self.check_history(call=1)   # because the trace starts immediately
+        self.check_history(call_n=1)   # because the trace starts immediately
 
     def test_unroll_one_loop_iteration(self):
         def unroll(code):
@@ -685,11 +685,11 @@
 
         res = self.meta_interp(f, [1, 4, 1], enable_opts="", inline=True)
         assert res == f(1, 4, 1)
-        self.check_history(call_assembler=0)
+        self.check_history(call_assembler_i=0)
 
         res = self.meta_interp(f, [1, 4, 2], enable_opts="", inline=True)
         assert res == f(1, 4, 2)
-        self.check_history(call_assembler=1)
+        self.check_history(call_assembler_i=1)
 
     def test_format(self):
         def f(n):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to