Skip to content

Commit e0d71a9

Browse files
Fidget-SpinnerLukasWoodtli
authored andcommitted
pythongh-115687: Split up guards from COMPARE_OP (pythonGH-115688)
1 parent 3520150 commit e0d71a9

9 files changed

+249
-163
lines changed

Include/internal/pycore_opcode_metadata.h

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_ids.h

Lines changed: 97 additions & 97 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/test/test_capi/test_opt.py

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ def _run_with_optimizer(self, testfunc, arg):
574574
def test_int_type_propagation(self):
575575
def testfunc(loops):
576576
num = 0
577-
while num < loops:
577+
for i in range(loops):
578578
x = num + num
579579
a = x + 1
580580
num += 1
@@ -593,7 +593,7 @@ def double(x):
593593
return x + x
594594
def testfunc(loops):
595595
num = 0
596-
while num < loops:
596+
for i in range(loops):
597597
x = num + num
598598
a = double(x)
599599
num += 1
@@ -617,7 +617,7 @@ def double(x):
617617
return x + x
618618
def testfunc(loops):
619619
num = 0
620-
while num < loops:
620+
for i in range(loops):
621621
a = double(num)
622622
x = a + a
623623
num += 1
@@ -821,6 +821,59 @@ def testfunc(n):
821821
# We'll also need to verify that propagation actually occurs.
822822
self.assertIn("_BINARY_OP_MULTIPLY_FLOAT", uops)
823823

824+
def test_compare_op_type_propagation_float(self):
825+
def testfunc(n):
826+
a = 1.0
827+
for _ in range(n):
828+
x = a == a
829+
x = a == a
830+
x = a == a
831+
x = a == a
832+
return x
833+
834+
res, ex = self._run_with_optimizer(testfunc, 32)
835+
self.assertTrue(res)
836+
self.assertIsNotNone(ex)
837+
uops = {opname for opname, _, _ in ex}
838+
guard_both_float_count = [opname for opname, _, _ in ex if opname == "_GUARD_BOTH_FLOAT"]
839+
self.assertLessEqual(len(guard_both_float_count), 1)
840+
self.assertIn("_COMPARE_OP_FLOAT", uops)
841+
842+
def test_compare_op_type_propagation_int(self):
843+
def testfunc(n):
844+
a = 1
845+
for _ in range(n):
846+
x = a == a
847+
x = a == a
848+
x = a == a
849+
x = a == a
850+
return x
851+
852+
res, ex = self._run_with_optimizer(testfunc, 32)
853+
self.assertTrue(res)
854+
self.assertIsNotNone(ex)
855+
uops = {opname for opname, _, _ in ex}
856+
guard_both_float_count = [opname for opname, _, _ in ex if opname == "_GUARD_BOTH_INT"]
857+
self.assertLessEqual(len(guard_both_float_count), 1)
858+
self.assertIn("_COMPARE_OP_INT", uops)
859+
860+
def test_compare_op_type_propagation_unicode(self):
861+
def testfunc(n):
862+
a = ""
863+
for _ in range(n):
864+
x = a == a
865+
x = a == a
866+
x = a == a
867+
x = a == a
868+
return x
869+
870+
res, ex = self._run_with_optimizer(testfunc, 32)
871+
self.assertTrue(res)
872+
self.assertIsNotNone(ex)
873+
uops = {opname for opname, _, _ in ex}
874+
guard_both_float_count = [opname for opname, _, _ in ex if opname == "_GUARD_BOTH_UNICODE"]
875+
self.assertLessEqual(len(guard_both_float_count), 1)
876+
self.assertIn("_COMPARE_OP_STR", uops)
824877

825878
if __name__ == "__main__":
826879
unittest.main()

0 commit comments

Comments
 (0)