Skip to content

Commit

Permalink
pythongh-115687: Split up guards from COMPARE_OP (pythonGH-115688)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fidget-Spinner authored Feb 20, 2024
1 parent a2bb8ad commit dcba21f
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 163 deletions.
12 changes: 6 additions & 6 deletions Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

194 changes: 97 additions & 97 deletions Include/internal/pycore_uop_ids.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Include/internal/pycore_uop_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 56 additions & 3 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ def _run_with_optimizer(self, testfunc, arg):
def test_int_type_propagation(self):
def testfunc(loops):
num = 0
while num < loops:
for i in range(loops):
x = num + num
a = x + 1
num += 1
Expand All @@ -593,7 +593,7 @@ def double(x):
return x + x
def testfunc(loops):
num = 0
while num < loops:
for i in range(loops):
x = num + num
a = double(x)
num += 1
Expand All @@ -617,7 +617,7 @@ def double(x):
return x + x
def testfunc(loops):
num = 0
while num < loops:
for i in range(loops):
a = double(num)
x = a + a
num += 1
Expand Down Expand Up @@ -821,6 +821,59 @@ def testfunc(n):
# We'll also need to verify that propagation actually occurs.
self.assertIn("_BINARY_OP_MULTIPLY_FLOAT", uops)

def test_compare_op_type_propagation_float(self):
def testfunc(n):
a = 1.0
for _ in range(n):
x = a == a
x = a == a
x = a == a
x = a == a
return x

res, ex = self._run_with_optimizer(testfunc, 32)
self.assertTrue(res)
self.assertIsNotNone(ex)
uops = {opname for opname, _, _ in ex}
guard_both_float_count = [opname for opname, _, _ in ex if opname == "_GUARD_BOTH_FLOAT"]
self.assertLessEqual(len(guard_both_float_count), 1)
self.assertIn("_COMPARE_OP_FLOAT", uops)

def test_compare_op_type_propagation_int(self):
def testfunc(n):
a = 1
for _ in range(n):
x = a == a
x = a == a
x = a == a
x = a == a
return x

res, ex = self._run_with_optimizer(testfunc, 32)
self.assertTrue(res)
self.assertIsNotNone(ex)
uops = {opname for opname, _, _ in ex}
guard_both_float_count = [opname for opname, _, _ in ex if opname == "_GUARD_BOTH_INT"]
self.assertLessEqual(len(guard_both_float_count), 1)
self.assertIn("_COMPARE_OP_INT", uops)

def test_compare_op_type_propagation_unicode(self):
def testfunc(n):
a = ""
for _ in range(n):
x = a == a
x = a == a
x = a == a
x = a == a
return x

res, ex = self._run_with_optimizer(testfunc, 32)
self.assertTrue(res)
self.assertIsNotNone(ex)
uops = {opname for opname, _, _ in ex}
guard_both_float_count = [opname for opname, _, _ in ex if opname == "_GUARD_BOTH_UNICODE"]
self.assertLessEqual(len(guard_both_float_count), 1)
self.assertIn("_COMPARE_OP_STR", uops)

if __name__ == "__main__":
unittest.main()
Loading

0 comments on commit dcba21f

Please sign in to comment.