Author: Carl Friedrich Bolz <cfb...@gmx.de>
Branch: better-storesink
Changeset: r87169:a9034e8630f8
Date: 2016-09-13 14:20 +0200
http://bitbucket.org/pypy/pypy/changeset/a9034e8630f8/

Log:    just call constfold after cse to remove constant operations, instead
        of doing it badly in CSE itself

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
@@ -6,7 +6,7 @@
 from rpython.flowspace.model import mkentrymap, Variable, Constant
 from rpython.translator.backendopt import removenoops
 from rpython.translator import simplify
-from rpython.translator.backendopt import ssa
+from rpython.translator.backendopt import ssa, constfold
 from rpython.translator.backendopt.writeanalyze import WriteAnalyzer
 
 from rpython.translator.backendopt.support import log
@@ -224,18 +224,8 @@
                 fieldname = op.args[1].value
                 concretetype = op.args[0].concretetype
                 arg0 = representative_arg(op.args[0])
-                res = None
-                if isinstance(arg0, Constant):
-                    PTRTYPE = concretetype.TO
-                    if PTRTYPE._immutable_field(fieldname):
-                        # can constant-fold:
-                        FIELDTYPE = getattr(PTRTYPE, fieldname)
-                        const = lltype.cast_pointer(concretetype, arg0.value)
-                        value = getattr(const, fieldname)
-                        res = Constant(value, FIELDTYPE)
-                if res is None:
-                    tup = (arg0, op.args[0].concretetype, fieldname)
-                    res = self.heapcache.get(tup, None)
+                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]
@@ -342,6 +332,7 @@
         if added_same_as:
             ssa.SSA_to_SSI(graph)
             removenoops.remove_same_as(graph)
+            constfold.constant_fold_graph(graph) # make use of extra constants
         simplify.transform_dead_op_vars(graph)
         if added_same_as:
             if self.translator.config.translation.verbose:
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
@@ -379,13 +379,18 @@
             _immutable_fields_ = ['a']
             def __init__(self, a):
                 self.a = a
+        class B(object):
+            pass
         a1 = A(5)
         a2 = A(8)
 
         def read(i):
+            b = B()
             if i:
-                return a1.a
-            return a2.a
+                b.a = a1
+                return b.a.a
+            b.a = a2
+            return b.a.a
         self.check(read, [int], getfield=0)
 
         # not immutable
@@ -429,7 +434,7 @@
         class Cls(object):
             pass
         class Sub(Cls):
-            pass
+            _immutable_fields_ = ['user_overridden_class']
         cls1 = Cls()
         cls2 = Sub()
         cls2.user_overridden_class = True
@@ -455,7 +460,7 @@
                 cls = a.cls
                 assert type(cls) is Sub
                 return cls.user_overridden_class
-        self.check(f, [int], getfield=2)
+        self.check(f, [int], getfield=0)
 
 
 
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to