@@ -574,7 +574,7 @@ def _run_with_optimizer(self, testfunc, arg):
574574 def test_int_type_propagation (self ):
575575 def testfunc (loops ):
576576 num = 0
577- while num < loops :
577+ for i in range ( loops ) :
578578 x = num + num
579579 a = x + 1
580580 num += 1
@@ -593,7 +593,7 @@ def double(x):
593593 return x + x
594594 def testfunc (loops ):
595595 num = 0
596- while num < loops :
596+ for i in range ( loops ) :
597597 x = num + num
598598 a = double (x )
599599 num += 1
@@ -617,7 +617,7 @@ def double(x):
617617 return x + x
618618 def testfunc (loops ):
619619 num = 0
620- while num < loops :
620+ for i in range ( loops ) :
621621 a = double (num )
622622 x = a + a
623623 num += 1
@@ -821,6 +821,59 @@ def testfunc(n):
821821 # We'll also need to verify that propagation actually occurs.
822822 self .assertIn ("_BINARY_OP_MULTIPLY_FLOAT" , uops )
823823
824+ def test_compare_op_type_propagation_float (self ):
825+ def testfunc (n ):
826+ a = 1.0
827+ for _ in range (n ):
828+ x = a == a
829+ x = a == a
830+ x = a == a
831+ x = a == a
832+ return x
833+
834+ res , ex = self ._run_with_optimizer (testfunc , 32 )
835+ self .assertTrue (res )
836+ self .assertIsNotNone (ex )
837+ uops = {opname for opname , _ , _ in ex }
838+ guard_both_float_count = [opname for opname , _ , _ in ex if opname == "_GUARD_BOTH_FLOAT" ]
839+ self .assertLessEqual (len (guard_both_float_count ), 1 )
840+ self .assertIn ("_COMPARE_OP_FLOAT" , uops )
841+
842+ def test_compare_op_type_propagation_int (self ):
843+ def testfunc (n ):
844+ a = 1
845+ for _ in range (n ):
846+ x = a == a
847+ x = a == a
848+ x = a == a
849+ x = a == a
850+ return x
851+
852+ res , ex = self ._run_with_optimizer (testfunc , 32 )
853+ self .assertTrue (res )
854+ self .assertIsNotNone (ex )
855+ uops = {opname for opname , _ , _ in ex }
856+ guard_both_float_count = [opname for opname , _ , _ in ex if opname == "_GUARD_BOTH_INT" ]
857+ self .assertLessEqual (len (guard_both_float_count ), 1 )
858+ self .assertIn ("_COMPARE_OP_INT" , uops )
859+
860+ def test_compare_op_type_propagation_unicode (self ):
861+ def testfunc (n ):
862+ a = ""
863+ for _ in range (n ):
864+ x = a == a
865+ x = a == a
866+ x = a == a
867+ x = a == a
868+ return x
869+
870+ res , ex = self ._run_with_optimizer (testfunc , 32 )
871+ self .assertTrue (res )
872+ self .assertIsNotNone (ex )
873+ uops = {opname for opname , _ , _ in ex }
874+ guard_both_float_count = [opname for opname , _ , _ in ex if opname == "_GUARD_BOTH_UNICODE" ]
875+ self .assertLessEqual (len (guard_both_float_count ), 1 )
876+ self .assertIn ("_COMPARE_OP_STR" , uops )
824877
825878if __name__ == "__main__" :
826879 unittest .main ()
0 commit comments