https://github.com/python/cpython/commit/016a46ab572fc681e4a06760147b9ae311b21881
commit: 016a46ab572fc681e4a06760147b9ae311b21881
branch: main
author: Irit Katriel <[email protected]>
committer: iritkatriel <[email protected]>
date: 2024-05-29T11:44:04+01:00
summary:

gh-93554: add test for quickening of code in loops ending with conditional 
statement (#119485)

files:
M Lib/test/test_dis.py

diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index 67a630e1346109..b1a1b77c53e8cb 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -1207,6 +1207,36 @@ def test_loop_quicken(self):
         expected = dis_loop_test_quickened_code
         self.do_disassembly_compare(got, expected)
 
+    @cpython_only
+    @requires_specialization
+    def test_loop_with_conditional_at_end_is_quickened(self):
+        def for_loop_true(x):
+            for i in range(10):
+                if x:
+                    pass
+
+        for_loop_true(True)
+        self.assertIn('FOR_ITER_RANGE',
+                      self.get_disassembly(for_loop_true, adaptive=True))
+
+        def for_loop_false(x):
+            for i in range(10):
+                if x:
+                    pass
+
+        for_loop_false(False)
+        self.assertIn('FOR_ITER_RANGE',
+                      self.get_disassembly(for_loop_false, adaptive=True))
+
+        def while_loop():
+            i = 0
+            while i < 10:
+                i += 1
+
+        while_loop()
+        self.assertIn('COMPARE_OP_INT',
+                      self.get_disassembly(while_loop, adaptive=True))
+
     @cpython_only
     def test_extended_arg_quick(self):
         got = self.get_disassembly(extended_arg_quick)

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to