File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -890,6 +890,48 @@ def testfunc(n):
890890 self .assertLessEqual (len (guard_nos_unicode_count ), 1 )
891891 self .assertIn ("_COMPARE_OP_STR" , uops )
892892
893+ def test_compare_int_eq_narrows_to_constant (self ):
894+ def f (n ):
895+ def return_1 ():
896+ return 1
897+
898+ hits = 0
899+ v = return_1 ()
900+ for _ in range (n ):
901+ if v == 1 :
902+ hits += v + 1
903+ return hits
904+
905+ res , ex = self ._run_with_optimizer (f , TIER2_THRESHOLD )
906+ self .assertEqual (res , TIER2_THRESHOLD * 2 )
907+ self .assertIsNotNone (ex )
908+ uops = get_opnames (ex )
909+
910+ # v + 1 should be constant folded
911+ self .assertLessEqual (count_ops (ex , "_BINARY_OP_ADD_INT" ), 1 )
912+
913+ def test_compare_int_ne_narrows_to_constant (self ):
914+ def f (n ):
915+ def return_1 ():
916+ return 1
917+
918+ hits = 0
919+ v = return_1 ()
920+ for _ in range (n ):
921+ if v != 1 :
922+ hits += 1000
923+ else :
924+ hits += v + 1
925+ return hits
926+
927+ res , ex = self ._run_with_optimizer (f , TIER2_THRESHOLD )
928+ self .assertEqual (res , TIER2_THRESHOLD * 2 )
929+ self .assertIsNotNone (ex )
930+ uops = get_opnames (ex )
931+
932+ # v + 1 should be constant folded
933+ self .assertLessEqual (count_ops (ex , "_BINARY_OP_ADD_INT" ), 1 )
934+
893935 @unittest .skip ("gh-139109 WIP" )
894936 def test_combine_stack_space_checks_sequential (self ):
895937 def dummy12 (x ):
You can’t perform that action at this time.
0 commit comments