@@ -1419,6 +1419,58 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
14191419 _Py_uop_sym_apply_predicate_narrowing (ctx , ref , true);
14201420 TEST_PREDICATE (!_Py_uop_sym_is_const (ctx , subject ), "predicate narrowing incorrectly narrowed subject (inverted/true)" );
14211421
1422+ // Test narrowing subject to constant from EQ predicate for str
1423+ subject = _Py_uop_sym_new_unknown (ctx );
1424+ PyObject * str_hello_obj = PyUnicode_FromString ("hello" );
1425+ JitOptRef const_str_hello = _Py_uop_sym_new_const (ctx , str_hello_obj );
1426+ if (PyJitRef_IsNull (subject ) || str_hello_obj == NULL || PyJitRef_IsNull (const_str_hello )) {
1427+ goto fail ;
1428+ }
1429+ ref = _Py_uop_sym_new_predicate (ctx , subject , const_str_hello , JIT_PRED_EQ );
1430+ if (PyJitRef_IsNull (ref )) {
1431+ goto fail ;
1432+ }
1433+ _Py_uop_sym_apply_predicate_narrowing (ctx , ref , true);
1434+ TEST_PREDICATE (_Py_uop_sym_is_const (ctx , subject ), "predicate narrowing did not const-narrow subject (str)" );
1435+ TEST_PREDICATE (_Py_uop_sym_get_const (ctx , subject ) == str_hello_obj , "predicate narrowing did not narrow subject to hello" );
1436+
1437+ // Resolving EQ predicate to False should not narrow subject for str
1438+ subject = _Py_uop_sym_new_unknown (ctx );
1439+ if (PyJitRef_IsNull (subject )) {
1440+ goto fail ;
1441+ }
1442+ ref = _Py_uop_sym_new_predicate (ctx , subject , const_str_hello , JIT_PRED_EQ );
1443+ if (PyJitRef_IsNull (ref )) {
1444+ goto fail ;
1445+ }
1446+ _Py_uop_sym_apply_predicate_narrowing (ctx , ref , false);
1447+ TEST_PREDICATE (!_Py_uop_sym_is_const (ctx , subject ), "predicate narrowing incorrectly narrowed subject (inverted/true)" );
1448+
1449+ // Test narrowing subject to constant from NE predicate for str
1450+ subject = _Py_uop_sym_new_unknown (ctx );
1451+ if (PyJitRef_IsNull (subject )) {
1452+ goto fail ;
1453+ }
1454+ ref = _Py_uop_sym_new_predicate (ctx , subject , const_str_hello , JIT_PRED_NE );
1455+ if (PyJitRef_IsNull (ref )) {
1456+ goto fail ;
1457+ }
1458+ _Py_uop_sym_apply_predicate_narrowing (ctx , ref , false);
1459+ TEST_PREDICATE (_Py_uop_sym_is_const (ctx , subject ), "predicate narrowing did not const-narrow subject (str)" );
1460+ TEST_PREDICATE (_Py_uop_sym_get_const (ctx , subject ) == str_hello_obj , "predicate narrowing did not narrow subject to hello" );
1461+
1462+ // Resolving NE predicate to true should not narrow subject for str
1463+ subject = _Py_uop_sym_new_unknown (ctx );
1464+ if (PyJitRef_IsNull (subject )) {
1465+ goto fail ;
1466+ }
1467+ ref = _Py_uop_sym_new_predicate (ctx , subject , const_str_hello , JIT_PRED_NE );
1468+ if (PyJitRef_IsNull (ref )) {
1469+ goto fail ;
1470+ }
1471+ _Py_uop_sym_apply_predicate_narrowing (ctx , ref , true);
1472+ TEST_PREDICATE (!_Py_uop_sym_is_const (ctx , subject ), "predicate narrowing incorrectly narrowed subject (inverted/true)" );
1473+
14221474 val_big = PyNumber_Lshift (_PyLong_GetOne (), PyLong_FromLong (66 ));
14231475 if (val_big == NULL ) {
14241476 goto fail ;
0 commit comments