File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3534,6 +3534,40 @@ def test_is_none(n):
35343534 self .assertIn ("_POP_TOP_NOP" , uops )
35353535 self .assertLessEqual (count_ops (ex , "_POP_TOP" ), 2 )
35363536
3537+ def test_is_true_narrows_to_constant (self ):
3538+ def f (n ):
3539+ hits = 0
3540+ for i in range (n ):
3541+ v = True if i != TIER2_THRESHOLD else - 1
3542+ if v is True :
3543+ # Redundant after narrowing
3544+ if v is True :
3545+ hits += 1
3546+ return hits
3547+
3548+ res , ex = self ._run_with_optimizer (f , TIER2_THRESHOLD )
3549+ self .assertEqual (res , TIER2_THRESHOLD )
3550+ self .assertIsNotNone (ex )
3551+
3552+ self .assertLessEqual (count_ops (ex , "_IS_OP" ), 1 )
3553+
3554+ def test_is_false_narrows_to_constant (self ):
3555+ def f (n ):
3556+ hits = 0
3557+ for i in range (n ):
3558+ v = False if i != TIER2_THRESHOLD else - 1
3559+ if v is False :
3560+ # Redundant after narrowing
3561+ if v is False :
3562+ hits += 1
3563+ return hits
3564+
3565+ res , ex = self ._run_with_optimizer (f , TIER2_THRESHOLD )
3566+ self .assertEqual (res , TIER2_THRESHOLD )
3567+ self .assertIsNotNone (ex )
3568+
3569+ self .assertLessEqual (count_ops (ex , "_IS_OP" ), 1 )
3570+
35373571 def test_for_iter_gen_frame (self ):
35383572 def f (n ):
35393573 for i in range (n ):
You can’t perform that action at this time.
0 commit comments