[pypy-svn] pypy default: actually test the right thing in this test; before, the loops were specialized anyway because a and b were loop invariants

antocuni commits-noreply at bitbucket.org
Wed Apr 20 18:32:50 CEST 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r43492:f353797c847a
Date: 2011-04-20 18:32 +0200
http://bitbucket.org/pypy/pypy/changeset/f353797c847a/

Log:	actually test the right thing in this test; before, the loops were
	specialized anyway because a and b were loop invariants

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
@@ -1531,43 +1531,37 @@
         ## assert call.getarg(2).value == 3.0
 
     def test_xor(self):
-        def main(a, b):
-            i = sa = 0
-            while i < 300:
+        def main(b):
+            a = sa = 0
+            while a < 300:
                 if a > 0: # Specialises the loop
                     pass
                 if b > 10:
                     pass
-                if a^b >= 0:
-                    sa += 1    # ID: add
-                i += 1
+                if a^b >= 0:  # ID: guard
+                    sa += 1
+                sa += a^a     # ID: a_xor_a
+                a += 1
             return sa
 
-        # if both are >=0, a^b is known to be >=0
-        log = self.run(main, [3, 14], threshold=200)
+        log = self.run(main, [11], threshold=200)
         assert log.result == 300
         loop, = log.loops_by_filename(self.filepath)
-        assert loop.match("""
-            i9 = int_lt(i6, 300)
-            guard_true(i9, descr=...)
-            i11 = int_add_ovf(i7, 1)
-            guard_no_overflow(descr=...)
-            i13 = int_add(i6, 1)
-            --TICK--
-            jump(p0, p1, p2, p3, p4, p5, i13, i11, descr=<Loop0>)
+        # if both are >=0, a^b is known to be >=0
+        # note that we know that b>10
+        assert loop.match_by_id('guard', """
+            i10 = int_xor(i5, i7)
         """)
+        #
+        # x^x is always optimized to 0
+        assert loop.match_by_id('a_xor_a', "")
 
-        # XXX: I don't understand why this assert passes, because the
-        # optimizer doesn't know that b >=0
-        log = self.run(main, [3, 4], threshold=200)
+        log = self.run(main, [9], threshold=200)
         assert log.result == 300
         loop, = log.loops_by_filename(self.filepath)
-        assert loop.match("""
-            i9 = int_lt(i6, 300)
-            guard_true(i9, descr=...)
-            i11 = int_add_ovf(i7, 1)
-            guard_no_overflow(descr=...)
-            i13 = int_add(i6, 1)
-            --TICK--
-            jump(p0, p1, p2, p3, p4, p5, i13, i11, descr=<Loop0>)
+        # we don't know that b>10, hence we cannot optimize it
+        assert loop.match_by_id('guard', """
+            i10 = int_xor(i5, i7)
+            i12 = int_ge(i10, 0)
+            guard_true(i12, descr=...)
         """)


More information about the Pypy-commit mailing list