[pypy-commit] pypy better-storesink: a few corner cases
cfbolz
pypy.commits at gmail.com
Fri Sep 16 17:12:55 EDT 2016
Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: better-storesink
Changeset: r87155:a5ab790844f4
Date: 2016-09-06 19:06 +0200
http://bitbucket.org/pypy/pypy/changeset/a5ab790844f4/
Log: a few corner cases
diff --git a/rpython/translator/backendopt/all.py b/rpython/translator/backendopt/all.py
--- a/rpython/translator/backendopt/all.py
+++ b/rpython/translator/backendopt/all.py
@@ -8,7 +8,7 @@
from rpython.translator.backendopt import mallocprediction
from rpython.translator.backendopt.removeassert import remove_asserts
from rpython.translator.backendopt.support import log
-from rpython.translator.backendopt.storesink import storesink_graph
+from rpython.translator.backendopt.cse import common_subexpression_elimination
from rpython.translator.backendopt import gilanalysis
from rpython.flowspace.model import checkgraph
@@ -101,8 +101,7 @@
print_statistics(translator.graphs[0], translator)
if config.storesink:
- for graph in graphs:
- storesink_graph(graph)
+ common_subexpression_elimination(translator, graphs)
if config.profile_based_inline and not secondary:
threshold = config.profile_based_inline_threshold
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
@@ -42,7 +42,7 @@
self.heapcache.copy())
- def merge(self, firstlink, tuples):
+ def merge(self, firstlink, tuples, backedges):
purecache = {}
block = firstlink.target
# copy all operations that exist in *all* blocks over. need to add a new
@@ -82,6 +82,8 @@
for linkindex, (link, cache) in enumerate(tuples):
link.args.append(results[linkindex])
block.inputargs.append(newres)
+ for backedge in backedges:
+ backedge.args.append(newres)
purecache[newkey] = newres
for key, res in self.purecache.iteritems():
@@ -97,6 +99,8 @@
for link, cache in tuples:
link.args.append(cache.purecache[key])
block.inputargs.append(newres)
+ for backedge in backedges:
+ backedge.args.append(newres)
purecache[key] = newres
# ______________________
@@ -132,6 +136,8 @@
for linkindex, (link, cache) in enumerate(tuples):
link.args.append(results[linkindex])
block.inputargs.append(newres)
+ for backedge in backedges:
+ backedge.args.append(newres)
heapcache[newkey] = newres
# regular merge
@@ -147,6 +153,8 @@
for link, cache in tuples:
link.args.append(cache.heapcache[key])
block.inputargs.append(newres)
+ for backedge in backedges:
+ backedge.args.append(newres)
heapcache[key] = newres
@@ -220,7 +228,7 @@
self.purecache[key] = op.result
return added_some_same_as
-def _merge(tuples, variable_families, analyzer, loop_blocks=None):
+def _merge(tuples, variable_families, analyzer, loop_blocks, backedges):
if not tuples:
return Cache(variable_families, analyzer)
if len(tuples) == 1:
@@ -228,7 +236,7 @@
result = cache.copy()
else:
firstlink, firstcache = tuples[0]
- result = firstcache.merge(firstlink, tuples)
+ result = firstcache.merge(firstlink, tuples, backedges)
if loop_blocks:
# for all blocks in the loop, clean the heapcache for their effects
# that way, loop-invariant reads can be removed, if no one writes to
@@ -261,13 +269,19 @@
while todo:
block = todo.popleft()
+ assert block not in done
+
+ current_backedges = [link for link in entrymap[block]
+ if link in backedges]
if block.operations:
cache = _merge(
caches_to_merge[block], variable_families, self.analyzer,
- loops.get(block, None))
+ loops.get(block, None), current_backedges)
changed_block = cache.cse_block(block)
added_some_same_as = changed_block or added_some_same_as
+ else:
+ cache = Cache(variable_families, self.analyzer)
done.add(block)
# add all target blocks where all predecessors are already done
for exit in block.exits:
@@ -275,7 +289,7 @@
if lnk.prevblock not in done and lnk not in backedges:
break
else:
- if exit.target not in done:
+ if exit.target not in done and exit.target not in todo: # XXX
todo.append(exit.target)
caches_to_merge[exit.target].append((exit, cache))
if added_some_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
@@ -293,3 +293,33 @@
res += a.x
return res
self.check(f, [int], getfield=0)
+
+ def test_loopinvariant_heap_merge(self):
+ class A(object):
+ pass
+ def f(i):
+ res = 0
+ x = i
+ a = A()
+ if i == 0:
+ a.x = 1
+ else:
+ a.x = i
+ while x:
+ x -= 1
+ res += a.x
+ return res
+ self.check(f, [int], getfield=0)
+
+ def test_direct_merge(self):
+ def f(i):
+ a = i + 1
+ if i:
+ x = a
+ else:
+ x = a
+ res = 0
+ while a:
+ res += i + 1
+ return a + (i + 1)
+ self.check(f, [int], add=0)
More information about the pypy-commit
mailing list