Skip to content

gh-115687: Split up guards from COMPARE_OP #115688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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