@@ -113,6 +113,9 @@ _PyUOpSymPrint(JitOptRef ref)
113113 case JIT_SYM_COMPACT_INT :
114114 printf ("<compact_int at %p>" , (void * )sym );
115115 break ;
116+ case JIT_SYM_PREDICATE_TAG :
117+ printf ("<predicate at %p>" , (void * )sym );
118+ break ;
116119 case JIT_SYM_DESCR_TAG : {
117120 PyTypeObject * descr_type = _PyType_LookupByVersion (sym -> descr .type_version );
118121 if (descr_type ) {
@@ -692,6 +695,7 @@ _Py_uop_sym_truthiness(JitOptContext *ctx, JitOptRef ref)
692695 case JIT_SYM_NON_NULL_TAG :
693696 case JIT_SYM_UNKNOWN_TAG :
694697 case JIT_SYM_COMPACT_INT :
698+ case JIT_SYM_PREDICATE_TAG :
695699 case JIT_SYM_DESCR_TAG :
696700 return -1 ;
697701 case JIT_SYM_KNOWN_CLASS_TAG :
@@ -1614,6 +1618,26 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
16141618 _Py_uop_sym_apply_predicate_narrowing (ctx , ref , true);
16151619 TEST_PREDICATE (!_Py_uop_sym_is_const (ctx , subject ), "predicate narrowing incorrectly narrowed subject (inverted/true)" );
16161620
1621+ subject = _Py_uop_sym_new_unknown (ctx );
1622+ value = _Py_uop_sym_new_const (ctx , one_obj );
1623+ ref = _Py_uop_sym_new_predicate (ctx , subject , value , JIT_PRED_IS );
1624+ if (PyJitRef_IsNull (subject ) || PyJitRef_IsNull (value ) || PyJitRef_IsNull (ref )) {
1625+ goto fail ;
1626+ }
1627+ TEST_PREDICATE (_Py_uop_sym_matches_type (ref , & PyBool_Type ), "predicate is not boolean" );
1628+ TEST_PREDICATE (_Py_uop_sym_truthiness (ctx , ref ) == -1 , "predicate is not unknown" );
1629+ TEST_PREDICATE (_Py_uop_sym_is_const (ctx , ref ) == false, "predicate is constant" );
1630+ TEST_PREDICATE (_Py_uop_sym_get_const (ctx , ref ) == NULL , "predicate is not NULL" );
1631+ TEST_PREDICATE (_Py_uop_sym_is_const (ctx , value ) == true, "value is not constant" );
1632+ TEST_PREDICATE (_Py_uop_sym_get_const (ctx , value ) == one_obj , "value is not 1" );
1633+ _Py_uop_sym_set_const (ctx , ref , Py_False );
1634+ TEST_PREDICATE (_Py_uop_sym_matches_type (ref , & PyBool_Type ), "predicate is not boolean" );
1635+ TEST_PREDICATE (_Py_uop_sym_truthiness (ctx , ref ) == 0 , "predicate is not False" );
1636+ TEST_PREDICATE (_Py_uop_sym_is_const (ctx , ref ) == true, "predicate is not constant" );
1637+ TEST_PREDICATE (_Py_uop_sym_get_const (ctx , ref ) == Py_False , "predicate is not False" );
1638+ TEST_PREDICATE (_Py_uop_sym_is_const (ctx , value ) == true, "value is not constant" );
1639+ TEST_PREDICATE (_Py_uop_sym_get_const (ctx , value ) == one_obj , "value is not 1" );
1640+
16171641 val_big = PyNumber_Lshift (_PyLong_GetOne (), PyLong_FromLong (66 ));
16181642 if (val_big == NULL ) {
16191643 goto fail ;
0 commit comments