@@ -1614,6 +1614,55 @@ def f(n):
16141614 # But all of the appends we care about are still there:
16151615 self .assertEqual (uops .count ("_CALL_LIST_APPEND" ), len ("ABCDEFG" ))
16161616
1617+ def test_replace_with_true_pop_top_load_const_inline_borrow (self ):
1618+ def testfunc (n ):
1619+ x = 0
1620+ for _ in range (n ):
1621+ a = 42
1622+ result = bool (a )
1623+ if result :
1624+ x += 1
1625+ return x
1626+ res , ex = self ._run_with_optimizer (testfunc , TIER2_THRESHOLD )
1627+ self .assertEqual (res , TIER2_THRESHOLD )
1628+ self .assertIsNotNone (ex )
1629+ uops = get_opnames (ex )
1630+ self .assertNotIn ("_REPLACE_WITH_TRUE" , uops )
1631+ self .assertNotIn ("_POP_TOP_LOAD_CONST_INLINE_BORROW" , uops )
1632+
1633+ def test_to_bool_none_pop_top_load_const_inline_borrow (self ):
1634+ def testfunc (n ):
1635+ x = 0
1636+ for _ in range (n ):
1637+ a = None
1638+ result = bool (a )
1639+ if result :
1640+ x += 1
1641+ return x
1642+ res , ex = self ._run_with_optimizer (testfunc , TIER2_THRESHOLD )
1643+ self .assertEqual (res , 0 )
1644+ self .assertIsNotNone (ex )
1645+ uops = get_opnames (ex )
1646+ self .assertNotIn ("_TO_BOOL_NONE" , uops )
1647+ self .assertNotIn ("_POP_TOP_LOAD_CONST_INLINE_BORROW" , uops )
1648+
1649+ def test_get_len_pop_top_load_const_inline_borrow (self ):
1650+ def testfunc (n ):
1651+ x = 0
1652+ for _ in range (n ):
1653+ a = "foo"
1654+ result = len (a )
1655+ if result :
1656+ x += 1
1657+ return x
1658+
1659+ res , ex = self ._run_with_optimizer (testfunc , TIER2_THRESHOLD )
1660+ self .assertEqual (res , TIER2_THRESHOLD )
1661+ self .assertIsNotNone (ex )
1662+ uops = get_opnames (ex )
1663+ self .assertNotIn ("_GET_LEN" , uops )
1664+ self .assertNotIn ("_POP_TOP_LOAD_CONST_INLINE_BORROW" , uops )
1665+
16171666 def test_compare_op_pop_two_load_const_inline_borrow (self ):
16181667 def testfunc (n ):
16191668 x = 0
0 commit comments