@@ -899,16 +899,17 @@ def return_1():
899899 v = return_1 ()
900900 for _ in range (n ):
901901 if v == 1 :
902- hits += v + 1
902+ if v == 1 :
903+ hits += 1
903904 return hits
904905
905906 res , ex = self ._run_with_optimizer (f , TIER2_THRESHOLD )
906- self .assertEqual (res , TIER2_THRESHOLD * 2 )
907+ self .assertEqual (res , TIER2_THRESHOLD )
907908 self .assertIsNotNone (ex )
908909 uops = get_opnames (ex )
909910
910- # v + 1 should be constant folded
911- self .assertLessEqual (count_ops (ex , "_BINARY_OP_ADD_INT " ), 1 )
911+ # Constant narrowing allows constant folding for second comparison
912+ self .assertLessEqual (count_ops (ex , "_COMPARE_OP_INT " ), 1 )
912913
913914 def test_compare_int_ne_narrows_to_constant (self ):
914915 def f (n ):
@@ -921,16 +922,17 @@ def return_1():
921922 if v != 1 :
922923 hits += 1000
923924 else :
924- hits += v + 1
925+ if v == 1 :
926+ hits += v + 1
925927 return hits
926928
927929 res , ex = self ._run_with_optimizer (f , TIER2_THRESHOLD )
928930 self .assertEqual (res , TIER2_THRESHOLD * 2 )
929931 self .assertIsNotNone (ex )
930932 uops = get_opnames (ex )
931933
932- # v + 1 should be constant folded
933- self .assertLessEqual (count_ops (ex , "_BINARY_OP_ADD_INT " ), 1 )
934+ # Constant narrowing allows constant folding for second comparison
935+ self .assertLessEqual (count_ops (ex , "_COMPARE_OP_INT " ), 1 )
934936
935937 def test_compare_float_eq_narrows_to_constant (self ):
936938 def f (n ):
@@ -950,6 +952,7 @@ def return_tenth():
950952 self .assertIsNotNone (ex )
951953 uops = get_opnames (ex )
952954
955+ # Constant narrowing allows constant folding for second comparison
953956 self .assertLessEqual (count_ops (ex , "_COMPARE_OP_FLOAT" ), 1 )
954957
955958 def test_compare_float_ne_narrows_to_constant (self ):
@@ -972,6 +975,7 @@ def return_tenth():
972975 self .assertIsNotNone (ex )
973976 uops = get_opnames (ex )
974977
978+ # Constant narrowing allows constant folding for second comparison
975979 self .assertLessEqual (count_ops (ex , "_COMPARE_OP_FLOAT" ), 1 )
976980
977981 @unittest .skip ("gh-139109 WIP" )
0 commit comments