[pypy-svn] pypy jit-int: Let the backend kill more resops with unused results

hakanardo commits-noreply at bitbucket.org
Sat Jan 8 10:22:36 CET 2011


Author: Hakan Ardo <hakan at debian.org>
Branch: jit-int
Changeset: r40484:e9177d6859dd
Date: 2011-01-07 14:47 +0100
http://bitbucket.org/pypy/pypy/changeset/e9177d6859dd/

Log:	Let the backend kill more resops with unused results

diff --git a/pypy/jit/backend/x86/test/test_regalloc.py b/pypy/jit/backend/x86/test/test_regalloc.py
--- a/pypy/jit/backend/x86/test/test_regalloc.py
+++ b/pypy/jit/backend/x86/test/test_regalloc.py
@@ -500,6 +500,22 @@
         self.interpret(ops, [s, ord('a')])
         assert s[1] == 'a'
 
+    def test_division_optimized(self):
+        ops = '''
+        [i7, i6]
+        i18 = int_floordiv(i7, i6)
+        i19 = int_xor(i7, i6)
+        i21 = int_lt(i19, 0)
+        i22 = int_mod(i7, i6)
+        i23 = int_is_true(i22)
+        i24 = int_eq(i6, 4)
+        guard_false(i24) [i18]
+        jump(i18, i6)
+        '''
+        self.interpret(ops, [10, 4])
+        assert self.getint(0) == 2
+        # FIXME: Verify that i19 - i23 are removed
+
 class TestRegallocFloats(BaseTestRegalloc):
     def test_float_add(self):
         ops = '''

diff --git a/pypy/jit/backend/x86/regalloc.py b/pypy/jit/backend/x86/regalloc.py
--- a/pypy/jit/backend/x86/regalloc.py
+++ b/pypy/jit/backend/x86/regalloc.py
@@ -375,35 +375,42 @@
     def _compute_vars_longevity(self, inputargs, operations):
         # compute a dictionary that maps variables to index in
         # operations that is a "last-time-seen"
-        longevity = {}
-        start_live = {}
-        for inputarg in inputargs:
-            start_live[inputarg] = 0
-        for i in range(len(operations)):
+        produced = {}
+        last_used = {}
+        for i in range(len(operations)-1, -1, -1):
             op = operations[i]
-            if op.result is not None:
-                start_live[op.result] = i
+            if op.result:
+                if op.result not in last_used and op.has_no_side_effect():
+                    continue
+                assert op.result not in produced
+                produced[op.result] = i
             for j in range(op.numargs()):
                 arg = op.getarg(j)
-                if isinstance(arg, Box):
-                    if arg not in start_live:
-                        not_implemented("Bogus arg in operation %d at %d" %
-                                        (op.getopnum(), i))
-                    longevity[arg] = (start_live[arg], i)
+                if isinstance(arg, Box) and arg not in last_used:
+                    last_used[arg] = i
             if op.is_guard():
                 for arg in op.getfailargs():
                     if arg is None: # hole
                         continue
                     assert isinstance(arg, Box)
-                    if arg not in start_live:
-                        not_implemented("Bogus arg in guard %d at %d" %
-                                        (op.getopnum(), i))
-                    longevity[arg] = (start_live[arg], i)
+                    if arg not in last_used:
+                        last_used[arg] = i
+                        
+        longevity = {}
+        for arg in produced:
+            if arg in last_used:
+                assert isinstance(arg, Box)
+                assert produced[arg] < last_used[arg]
+                longevity[arg] = (produced[arg], last_used[arg])
+                del last_used[arg]
         for arg in inputargs:
-            if arg not in longevity:
+            assert isinstance(arg, Box)
+            if arg not in last_used:
                 longevity[arg] = (-1, -1)
-        for arg in longevity:
-            assert isinstance(arg, Box)
+            else:
+                longevity[arg] = (0, last_used[arg])
+                del last_used[arg]
+        assert len(last_used) == 0
         return longevity
 
     def loc(self, v):


More information about the Pypy-commit mailing list