Author: Alex Gaynor <alex.gay...@gmail.com>
Branch: 
Changeset: r44191:ce505f035396
Date: 2011-05-15 13:25 -0500
http://bitbucket.org/pypy/pypy/changeset/ce505f035396/

Log:    Optimize away uint_floordiv(i0, 1). Updated test_pypy_c_new to
        reflect this.

diff --git a/pypy/jit/metainterp/optimizeopt/rewrite.py 
b/pypy/jit/metainterp/optimizeopt/rewrite.py
--- a/pypy/jit/metainterp/optimizeopt/rewrite.py
+++ b/pypy/jit/metainterp/optimizeopt/rewrite.py
@@ -15,7 +15,7 @@
 
     def reconstruct_for_next_iteration(self, optimizer, valuemap):
         return self
-    
+
     def propagate_forward(self, op):
         args = self.optimizer.make_args_key(op)
         if self.find_rewritable_bool(op, args):
@@ -40,7 +40,7 @@
                     return False
         return self.is_emittable(op)
 
-        
+
     def try_boolinvers(self, op, targs):
         oldop = self.optimizer.pure_operations.get(targs, None)
         if oldop is not None and oldop.getdescr() is op.getdescr():
@@ -69,7 +69,7 @@
         try:
             oldopnum = opboolreflex[op.getopnum()] # FIXME: add INT_ADD, 
INT_MUL
             targs = self.optimizer.make_args_key(ResOperation(oldopnum, 
[args[1], args[0]],
-                                                              None))           
 
+                                                              None))
             oldop = self.optimizer.pure_operations.get(targs, None)
             if oldop is not None and oldop.getdescr() is op.getdescr():
                 self.make_equal_to(op.result, self.getvalue(oldop.result))
@@ -80,7 +80,7 @@
         try:
             oldopnum = opboolinvers[opboolreflex[op.getopnum()]]
             targs = self.optimizer.make_args_key(ResOperation(oldopnum, 
[args[1], args[0]],
-                                                              None))           
 
+                                                              None))
             if self.try_boolinvers(op, targs):
                 return True
         except KeyError:
@@ -157,6 +157,15 @@
 
             self.emit_operation(op)
 
+    def optimize_UINT_FLOORDIV(self, op):
+        v1 = self.getvalue(op.getarg(0))
+        v2 = self.getvalue(op.getarg(1))
+
+        if v2.is_constant() and v2.box.getint() == 1:
+            self.make_equal_to(op.result, v1)
+        else:
+            self.emit_operation(op)
+
     def optimize_INT_LSHIFT(self, op):
         v1 = self.getvalue(op.getarg(0))
         v2 = self.getvalue(op.getarg(1))
@@ -322,7 +331,7 @@
         self.emit_operation(op)
         resvalue = self.getvalue(op.result)
         self.optimizer.loop_invariant_results[key] = resvalue
-    
+
     def _optimize_nullness(self, op, box, expect_nonnull):
         value = self.getvalue(box)
         if value.is_nonnull():
@@ -381,7 +390,7 @@
 ##        if realclassbox is not None:
 ##            checkclassbox = self.optimizer.cpu.typedescr2classbox(op.descr)
 ##            result = self.optimizer.cpu.ts.subclassOf(self.optimizer.cpu,
-##                                                      realclassbox, 
+##                                                      realclassbox,
 ##                                                      checkclassbox)
 ##            self.make_constant_int(op.result, result)
 ##            return
diff --git a/pypy/jit/metainterp/test/test_optimizeopt.py 
b/pypy/jit/metainterp/test/test_optimizeopt.py
--- a/pypy/jit/metainterp/test/test_optimizeopt.py
+++ b/pypy/jit/metainterp/test/test_optimizeopt.py
@@ -2843,6 +2843,18 @@
         """
         self.optimize_loop(ops, expected)
 
+    def test_fold_partially_constant_uint_floordiv(self):
+        ops = """
+        [i0]
+        i1 = uint_floordiv(i0, 1)
+        jump(i1)
+        """
+        expected = """
+        [i0]
+        jump(i0)
+        """
+        self.optimize_loop(ops, expected)
+
     # ----------
 
 class TestLLtype(OptimizeOptTest, LLtypeMixin):
@@ -5746,7 +5758,7 @@
         """
         expected = """
         []
-        guard_not_invalidated() []        
+        guard_not_invalidated() []
         escape(-4247)
         jump()
         """
diff --git a/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py 
b/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
--- a/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py
@@ -1043,17 +1043,13 @@
         assert loop.match("""
             i10 = int_lt(i5, i6)
             guard_true(i10, descr=<Guard3>)
-            # This can be improved if the JIT realized the lookup of i5 
produces
-            # a constant and thus can be removed entirely
             i120 = int_add(i5, 1)
             guard_not_invalidated(descr=<Guard4>)
             i140 = int_lt(0, i120)
             guard_true(i140, descr=<Guard5>)
-            i13 = uint_floordiv(i5, 1)       # XXX we could remove that
-            i15 = int_add(i13, 1)
-            i17 = int_lt(i15, 0)
+            i17 = int_lt(i120, 0)
             guard_false(i17, descr=<Guard6>)
-            i20 = int_sub(i15, i5)
+            i20 = int_sub(i120, i5)
             i21 = int_add_ovf(i5, i20)
             guard_no_overflow(descr=<Guard7>)
             --TICK--
@@ -1092,7 +1088,7 @@
             --TICK--
             jump(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, i28, i25, i19, i13, 
p14, p15, descr=<Loop0>)
         """)
-        
+
     def test_mutate_class(self):
         def fn(n):
             class A(object):
@@ -1497,7 +1493,7 @@
         def main():
             i=0
             sa=0
-            while i < 300: 
+            while i < 300:
                 sa+=min(max(i, 3000), 4000)
                 i+=1
             return sa
@@ -1534,7 +1530,7 @@
             p76 = call_may_force(ConstClass(min_max_loop__max), _, _, 
descr=...)
             ...
         """)
-        
+
     def test_iter_max(self):
         def main():
             i = 2
@@ -1552,7 +1548,7 @@
         assert len(guards) < 20
         assert loop.match_by_id('max',"""
             ...
-            p76 = call_may_force(ConstClass(min_max_loop__max), _, _, 
descr=...)            
+            p76 = call_may_force(ConstClass(min_max_loop__max), _, _, 
descr=...)
             ...
         """)
 
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to