[pypy-commit] pypy regalloc-playground: use LEA even for additions that involve the stack

cfbolz pypy.commits at gmail.com
Tue Sep 5 15:44:55 EDT 2017


Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: regalloc-playground
Changeset: r92326:ec41cc35c5d8
Date: 2017-09-04 09:30 +0200
http://bitbucket.org/pypy/pypy/changeset/ec41cc35c5d8/

Log:	use LEA even for additions that involve the stack (that way we can
	move the stack argument to a register, where it might be used soon
	again)

diff --git a/rpython/jit/backend/x86/regalloc.py b/rpython/jit/backend/x86/regalloc.py
--- a/rpython/jit/backend/x86/regalloc.py
+++ b/rpython/jit/backend/x86/regalloc.py
@@ -531,28 +531,25 @@
         loc, argloc = self._consider_binop_part(op, symm=True)
         self.perform(op, [loc, argloc], loc)
 
-    def _consider_lea(self, op, loc):
+    def _consider_lea(self, op):
+        loc = self.make_sure_var_in_reg(op.getarg(0))
         argloc = self.loc(op.getarg(1))
         resloc = self.force_allocate_reg(op)
         self.perform(op, [loc, argloc], resloc)
 
     def consider_int_add(self, op):
-        loc = self.loc(op.getarg(0))
         y = op.getarg(1)
-        if (isinstance(loc, RegLoc) and
-            isinstance(y, ConstInt) and rx86.fits_in_32bits(y.value)):
-            self._consider_lea(op, loc)
+        if isinstance(y, ConstInt) and rx86.fits_in_32bits(y.value):
+            self._consider_lea(op)
         else:
             self._consider_binop_symm(op)
 
     consider_nursery_ptr_increment = consider_int_add
 
     def consider_int_sub(self, op):
-        loc = self.loc(op.getarg(0))
         y = op.getarg(1)
-        if (isinstance(loc, RegLoc) and
-            isinstance(y, ConstInt) and rx86.fits_in_32bits(-y.value)):
-            self._consider_lea(op, loc)
+        if isinstance(y, ConstInt) and rx86.fits_in_32bits(-y.value):
+            self._consider_lea(op)
         else:
             self._consider_binop(op)
 
diff --git a/rpython/jit/backend/x86/test/test_regalloc.py b/rpython/jit/backend/x86/test/test_regalloc.py
--- a/rpython/jit/backend/x86/test/test_regalloc.py
+++ b/rpython/jit/backend/x86/test/test_regalloc.py
@@ -85,6 +85,17 @@
         self.interpret(ops, [5, 6, 7, 8])
         assert len([entry for entry in self.log if entry.args[0] == "int_add"]) == 1
 
+    def test_use_lea_even_for_stack(self):
+        ops = '''
+        [i0, i1, i2, i3]
+        i9 = int_add(i3, 16)
+        i4 = int_add(i3, 26)
+        i6 = int_add(i9, i4)
+        finish(i6)
+        '''
+        self.interpret(ops, [5, 6, 7, 8])
+        assert len(self.filter_log_moves()) == 2
+
     def test_call_use_correct_regs(self):
         ops = '''
         [i0, i1, i2, i3]


More information about the pypy-commit mailing list