Skip to content

Commit f537ca0

Browse files
Optimize compare_op_float, add tests and header
1 parent db7f2e7 commit f537ca0

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,23 @@ def testfunc(n):
16481648
self.assertNotIn("_COMPARE_OP_STR", uops)
16491649
self.assertNotIn("_POP_TWO_LOAD_CONST_INLINE_BORROW", uops)
16501650

1651+
def test_compare_op_float_pop_two_load_const_inline_borrow(self):
1652+
def testfunc(n):
1653+
x = 0
1654+
for _ in range(n):
1655+
a = 1.0
1656+
b = 1.0
1657+
if a == b:
1658+
x += 1
1659+
return x
1660+
1661+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
1662+
self.assertEqual(res, TIER2_THRESHOLD)
1663+
self.assertIsNotNone(ex)
1664+
uops = get_opnames(ex)
1665+
self.assertNotIn("_COMPARE_OP_FLOAT", uops)
1666+
self.assertNotIn("_POP_TWO_LOAD_CONST_INLINE_BORROW", uops)
1667+
16511668
def test_to_bool_bool_contains_op_set(self):
16521669
"""
16531670
Test that _TO_BOOL_BOOL is removed from code like:

Python/optimizer_analysis.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "pycore_range.h"
2929
#include "pycore_unicodeobject.h"
3030
#include "pycore_ceval.h"
31+
#include "pycore_floatobject.h"
3132

3233
#include <stdarg.h>
3334
#include <stdbool.h>

0 commit comments

Comments
 (0)