@@ -1306,7 +1306,7 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
13061306 subject = _Py_uop_sym_new_unknown (ctx );
13071307 PyObject * one_obj = PyLong_FromLong (1 );
13081308 JitOptRef const_one = _Py_uop_sym_new_const (ctx , one_obj );
1309- if (PyJitRef_IsNull (subject ) || PyJitRef_IsNull (const_one )) {
1309+ if (PyJitRef_IsNull (subject ) || one_obj == NULL || PyJitRef_IsNull (const_one )) {
13101310 goto fail ;
13111311 }
13121312 ref = _Py_uop_sym_new_predicate (ctx , subject , const_one , JIT_PRED_IS );
@@ -1317,9 +1317,9 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
13171317 TEST_PREDICATE (_Py_uop_sym_is_const (ctx , subject ), "predicate narrowing did not const-narrow subject (1)" );
13181318 TEST_PREDICATE (_Py_uop_sym_get_const (ctx , subject ) == one_obj , "predicate narrowing did not narrow subject to 1" );
13191319
1320- // Test narrowing subject to numerical constant from EQ predicate
1320+ // Test narrowing subject to constant from EQ predicate for int
13211321 subject = _Py_uop_sym_new_unknown (ctx );
1322- if (PyJitRef_IsNull (subject ) || PyJitRef_IsNull ( const_one ) ) {
1322+ if (PyJitRef_IsNull (subject )) {
13231323 goto fail ;
13241324 }
13251325 ref = _Py_uop_sym_new_predicate (ctx , subject , const_one , JIT_PRED_EQ );
@@ -1330,7 +1330,7 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
13301330 TEST_PREDICATE (_Py_uop_sym_is_const (ctx , subject ), "predicate narrowing did not const-narrow subject (1)" );
13311331 TEST_PREDICATE (_Py_uop_sym_get_const (ctx , subject ) == one_obj , "predicate narrowing did not narrow subject to 1" );
13321332
1333- // Resolving EQ predicate to False should not narrow subject
1333+ // Resolving EQ predicate to False should not narrow subject for int
13341334 subject = _Py_uop_sym_new_unknown (ctx );
13351335 if (PyJitRef_IsNull (subject )) {
13361336 goto fail ;
@@ -1342,9 +1342,9 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
13421342 _Py_uop_sym_apply_predicate_narrowing (ctx , ref , false);
13431343 TEST_PREDICATE (!_Py_uop_sym_is_const (ctx , subject ), "predicate narrowing incorrectly narrowed subject (inverted/true)" );
13441344
1345- // Test narrowing subject to numerical constant from NE predicate
1345+ // Test narrowing subject to constant from NE predicate for int
13461346 subject = _Py_uop_sym_new_unknown (ctx );
1347- if (PyJitRef_IsNull (subject ) || PyJitRef_IsNull ( const_one ) ) {
1347+ if (PyJitRef_IsNull (subject )) {
13481348 goto fail ;
13491349 }
13501350 ref = _Py_uop_sym_new_predicate (ctx , subject , const_one , JIT_PRED_NE );
@@ -1355,7 +1355,7 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
13551355 TEST_PREDICATE (_Py_uop_sym_is_const (ctx , subject ), "predicate narrowing did not const-narrow subject (1)" );
13561356 TEST_PREDICATE (_Py_uop_sym_get_const (ctx , subject ) == one_obj , "predicate narrowing did not narrow subject to 1" );
13571357
1358- // Resolving NE predicate to true should not narrow subject
1358+ // Resolving NE predicate to true should not narrow subject for int
13591359 subject = _Py_uop_sym_new_unknown (ctx );
13601360 if (PyJitRef_IsNull (subject )) {
13611361 goto fail ;
@@ -1367,6 +1367,58 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
13671367 _Py_uop_sym_apply_predicate_narrowing (ctx , ref , true);
13681368 TEST_PREDICATE (!_Py_uop_sym_is_const (ctx , subject ), "predicate narrowing incorrectly narrowed subject (inverted/true)" );
13691369
1370+ // Test narrowing subject to constant from EQ predicate for float
1371+ subject = _Py_uop_sym_new_unknown (ctx );
1372+ PyObject * float_tenth_obj = PyFloat_FromDouble (0.1 );
1373+ JitOptRef const_float_tenth = _Py_uop_sym_new_const (ctx , float_tenth_obj );
1374+ if (PyJitRef_IsNull (subject ) || float_tenth_obj == NULL || PyJitRef_IsNull (const_float_tenth )) {
1375+ goto fail ;
1376+ }
1377+ ref = _Py_uop_sym_new_predicate (ctx , subject , const_float_tenth , JIT_PRED_EQ );
1378+ if (PyJitRef_IsNull (ref )) {
1379+ goto fail ;
1380+ }
1381+ _Py_uop_sym_apply_predicate_narrowing (ctx , ref , true);
1382+ TEST_PREDICATE (_Py_uop_sym_is_const (ctx , subject ), "predicate narrowing did not const-narrow subject (float)" );
1383+ TEST_PREDICATE (_Py_uop_sym_get_const (ctx , subject ) == float_tenth_obj , "predicate narrowing did not narrow subject to 0.1" );
1384+
1385+ // Resolving EQ predicate to False should not narrow subject for float
1386+ subject = _Py_uop_sym_new_unknown (ctx );
1387+ if (PyJitRef_IsNull (subject )) {
1388+ goto fail ;
1389+ }
1390+ ref = _Py_uop_sym_new_predicate (ctx , subject , const_float_tenth , JIT_PRED_EQ );
1391+ if (PyJitRef_IsNull (ref )) {
1392+ goto fail ;
1393+ }
1394+ _Py_uop_sym_apply_predicate_narrowing (ctx , ref , false);
1395+ TEST_PREDICATE (!_Py_uop_sym_is_const (ctx , subject ), "predicate narrowing incorrectly narrowed subject (inverted/true)" );
1396+
1397+ // Test narrowing subject to constant from NE predicate for float
1398+ subject = _Py_uop_sym_new_unknown (ctx );
1399+ if (PyJitRef_IsNull (subject )) {
1400+ goto fail ;
1401+ }
1402+ ref = _Py_uop_sym_new_predicate (ctx , subject , const_float_tenth , JIT_PRED_NE );
1403+ if (PyJitRef_IsNull (ref )) {
1404+ goto fail ;
1405+ }
1406+ _Py_uop_sym_apply_predicate_narrowing (ctx , ref , false);
1407+ TEST_PREDICATE (_Py_uop_sym_is_const (ctx , subject ), "predicate narrowing did not const-narrow subject (float)" );
1408+ TEST_PREDICATE (_Py_uop_sym_get_const (ctx , subject ) == float_tenth_obj , "predicate narrowing did not narrow subject to 0.1" );
1409+
1410+ // Resolving NE predicate to true should not narrow subject for float
1411+ subject = _Py_uop_sym_new_unknown (ctx );
1412+ if (PyJitRef_IsNull (subject )) {
1413+ goto fail ;
1414+ }
1415+ ref = _Py_uop_sym_new_predicate (ctx , subject , const_float_tenth , JIT_PRED_NE );
1416+ if (PyJitRef_IsNull (ref )) {
1417+ goto fail ;
1418+ }
1419+ _Py_uop_sym_apply_predicate_narrowing (ctx , ref , true);
1420+ TEST_PREDICATE (!_Py_uop_sym_is_const (ctx , subject ), "predicate narrowing incorrectly narrowed subject (inverted/true)" );
1421+
13701422 val_big = PyNumber_Lshift (_PyLong_GetOne (), PyLong_FromLong (66 ));
13711423 if (val_big == NULL ) {
13721424 goto fail ;
0 commit comments