Author: Carl Friedrich Bolz <cfb...@gmx.de>
Branch: better-storesink
Changeset: r87171:84b5c1af401b
Date: 2016-09-16 14:46 +0200
http://bitbucket.org/pypy/pypy/changeset/84b5c1af401b/

Log:    factor out the rewriting to same_as, with an extra safety check

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
@@ -213,6 +213,12 @@
                     effects, self.analyzer.analyze(op))
         self._clear_heapcache_for_effects(effects)
 
+    def _replace_with_result(self, op, res):
+        assert op.result.concretetype == res.concretetype
+        op.opname = 'same_as'
+        op.args = [res]
+        self.new_unions.union(res, op.result)
+
     def cse_block(self, block):
         def representative_arg(arg):
             if isinstance(arg, Variable):
@@ -228,14 +234,13 @@
                 tup = (arg0, op.args[0].concretetype, fieldname)
                 res = self.heapcache.get(tup, None)
                 if res is not None:
-                    op.opname = 'same_as'
-                    op.args = [res]
+                    self._replace_with_result(op, res)
                     added_same_as += 1
-                    self.new_unions.union(res, op.result)
                 else:
                     self.heapcache[tup] = op.result
                 continue
             if op.opname == 'setfield':
+                # XXX check whether value is the same already
                 concretetype = op.args[0].concretetype
                 target = representative_arg(op.args[0])
                 fieldname = op.args[1].value
@@ -253,10 +258,8 @@
                    tuple([representative_arg(arg) for arg in op.args]))
             res = self.purecache.get(key, None)
             if res is not None:
-                op.opname = 'same_as'
-                op.args = [res]
+                self._replace_with_result(op, res)
                 added_same_as += 1
-                self.new_unions.union(res, op.result)
             else:
                 self.purecache[key] = op.result
             if op.opname == "cast_pointer":
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to