Commits

Antonio Cuni committed cd6bf05

port and improve test_boolrewrite_invers; please review

Comments (0)

Files changed (1)

pypy/module/pypyjit/test_pypy_c/test_pypy_c_new.py

             --TICK--
             jump(p0, p1, p2, p3, p4, i9, i6, descr=<Loop0>)
         """)
+
+    def test_boolrewrite_invers(self):
+        for a, b, res, opt_applied in (('2000', '2000', 20001000, True),
+                                       ( '500',  '500', 15001500, True),
+                                       ( '300',  '600', 16001700, False),
+                                       (   'a',    'b', 16001700, False),
+                                       (   'a',    'a', 13001700, True)):
+            src = """
+                def main():
+                    sa = 0
+                    a = 300
+                    b = 600
+                    for i in range(1000):
+                        if i < %s:         # ID: lt
+                            sa += 1
+                        else:
+                            sa += 2
+                        #
+                        if i >= %s:        # ID: ge
+                            sa += 10000
+                        else:
+                            sa += 20000
+                    return sa
+            """ % (a, b)
+            #
+            log = self.run(src, [], threshold=400)
+            assert log.result == res
+            loop, = log.loops_by_filename(self.filepath)
+            le_ops = log.opnames(loop.ops_by_id('lt'))
+            ge_ops = log.opnames(loop.ops_by_id('ge'))
+            assert le_ops.count('int_lt') == 1
+            #
+            if opt_applied:
+                assert ge_ops.count('int_ge') == 0
+            else:
+                # if this assert fails it means that the optimization was
+                # applied even if we don't expect to. Check whether the
+                # optimization is valid, and either fix the code or fix the
+                # test :-)
+                assert ge_ops.count('int_ge') == 1