Skip to content

Commit 016a46a

Browse files
authored
gh-93554: add test for quickening of code in loops ending with conditional statement (#119485)
1 parent 18c1a8d commit 016a46a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Lib/test/test_dis.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,36 @@ def test_loop_quicken(self):
12071207
expected = dis_loop_test_quickened_code
12081208
self.do_disassembly_compare(got, expected)
12091209

1210+
@cpython_only
1211+
@requires_specialization
1212+
def test_loop_with_conditional_at_end_is_quickened(self):
1213+
def for_loop_true(x):
1214+
for i in range(10):
1215+
if x:
1216+
pass
1217+
1218+
for_loop_true(True)
1219+
self.assertIn('FOR_ITER_RANGE',
1220+
self.get_disassembly(for_loop_true, adaptive=True))
1221+
1222+
def for_loop_false(x):
1223+
for i in range(10):
1224+
if x:
1225+
pass
1226+
1227+
for_loop_false(False)
1228+
self.assertIn('FOR_ITER_RANGE',
1229+
self.get_disassembly(for_loop_false, adaptive=True))
1230+
1231+
def while_loop():
1232+
i = 0
1233+
while i < 10:
1234+
i += 1
1235+
1236+
while_loop()
1237+
self.assertIn('COMPARE_OP_INT',
1238+
self.get_disassembly(while_loop, adaptive=True))
1239+
12101240
@cpython_only
12111241
def test_extended_arg_quick(self):
12121242
got = self.get_disassembly(extended_arg_quick)

0 commit comments

Comments
 (0)