Author: Carl Friedrich Bolz <[email protected]>
Branch: better-storesink
Changeset: r87163:a01cd9612fb4
Date: 2016-09-09 15:26 +0200
http://bitbucket.org/pypy/pypy/changeset/a01cd9612fb4/
Log: safer mechanism for storing new equivalencies than updating the
variable_families
diff --git a/rpython/translator/backendopt/cse.py
b/rpython/translator/backendopt/cse.py
--- a/rpython/translator/backendopt/cse.py
+++ b/rpython/translator/backendopt/cse.py
@@ -39,6 +39,7 @@
self.heapcache = heapcache
self.variable_families = variable_families
self.analyzer = analyzer
+ self.new_unions = {} # mapping var from this block -> older var
def copy(self):
return Cache(
@@ -47,6 +48,7 @@
self.heapcache.copy())
def _var_rep(self, var):
+ var = self.new_unions.get(var, var)
return self.variable_families.find_rep(var)
def _key_with_replacement(self, key, index, var):
@@ -216,6 +218,7 @@
op.opname = 'same_as'
op.args = [res]
added_same_as += 1
+ self.new_unions[op.result] = res
else:
self.heapcache[tup] = op.result
continue
@@ -239,7 +242,7 @@
op.opname = 'same_as'
op.args = [res]
added_same_as += 1
- self.variable_families.union(res, op.result)
+ self.new_unions[op.result] = res
else:
self.purecache[key] = op.result
return added_same_as
diff --git a/rpython/translator/backendopt/test/test_cse.py
b/rpython/translator/backendopt/test/test_cse.py
--- a/rpython/translator/backendopt/test/test_cse.py
+++ b/rpython/translator/backendopt/test/test_cse.py
@@ -165,6 +165,29 @@
self.check(f, [int], getfield=1)
+ def test_two_getfields(self):
+ class A(object):
+ pass
+ class B(object):
+ pass
+ a1 = A()
+ a1.next = B()
+ a1.next.x = 1
+ a2 = A()
+ a2.next = B()
+ a2.next.x = 5
+
+
+ def f(i):
+ if i:
+ a = a1
+ else:
+ a = a2
+ return a.next.x + a.next.x + i
+
+ self.check(f, [int], getfield=2)
+
+
def test_bug_1(self):
class A(object):
pass
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit