Author: Carl Friedrich Bolz <[email protected]>
Branch: regalloc-playground
Changeset: r92198:dfada6cd5c1a
Date: 2017-08-21 15:27 +0200
http://bitbucket.org/pypy/pypy/changeset/dfada6cd5c1a/
Log: tweak: pick the longest-living useless variable
diff --git a/rpython/jit/backend/llsupport/regalloc.py
b/rpython/jit/backend/llsupport/regalloc.py
--- a/rpython/jit/backend/llsupport/regalloc.py
+++ b/rpython/jit/backend/llsupport/regalloc.py
@@ -420,8 +420,8 @@
"""
cur_max_age = -1
candidate = None
- # YYY we should pick a variable to spill that is only used in failargs
- # from now on
+ cur_max_age_failargs = -1
+ candidate_from_failargs = None
for next in self.reg_bindings:
reg = self.reg_bindings[next]
if next in forbidden_vars:
@@ -434,18 +434,22 @@
if need_lower_byte and reg in self.no_lower_byte_regs:
continue
lifetime = self.longevity[next]
+ max_age = lifetime.last_usage
if lifetime.is_last_real_use_before(self.position):
# this variable has no "real" use as an argument to an op left
# it is only used in failargs, and maybe in a jump. spilling is
# fine
- return next
- max_age = lifetime.last_usage
+ if cur_max_age_failargs < max_age:
+ cur_max_age_failargs = max_age
+ candidate_from_failargs = next
if cur_max_age < max_age:
cur_max_age = max_age
candidate = next
- if candidate is None:
- raise NoVariableToSpill
- return candidate
+ if candidate_from_failargs is not None:
+ return candidate_from_failargs
+ if candidate is not None:
+ return candidate
+ raise NoVariableToSpill
def force_allocate_reg(self, v, forbidden_vars=[], selected_reg=None,
need_lower_byte=False):
diff --git a/rpython/jit/backend/llsupport/test/test_regalloc.py
b/rpython/jit/backend/llsupport/test/test_regalloc.py
--- a/rpython/jit/backend/llsupport/test/test_regalloc.py
+++ b/rpython/jit/backend/llsupport/test/test_regalloc.py
@@ -397,9 +397,9 @@
def test_spill_useless_vars_first(self):
b0, b1, b2, b3, b4, b5 = newboxes(0, 1, 2, 3, 4, 5)
- longevity = {b0: Lifetime(0, 5), b1: Lifetime(0, 5),
- # b3 becomes useless but b2 lives longer
- b3: Lifetime(0, 5, 3), b2: Lifetime(0, 6),
+ longevity = {b0: Lifetime(0, 5), b1: Lifetime(0, 10),
+ # b2 and b3 become useless but b3 lives longer
+ b3: Lifetime(0, 7, 3), b2: Lifetime(0, 6, 3),
b4: Lifetime(4, 5), b5: Lifetime(4, 7)}
fm = TFrameManager()
asm = MockAsm()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit