@@ -836,7 +836,7 @@ _Py_uop_sym_set_compact_int(JitOptContext *ctx, JitOptRef ref)
836836}
837837
838838JitOptRef
839- _Py_uop_sym_new_predicate (JitOptContext * ctx , JitOptRef lhs_ref , JitOptRef rhs_ref , JitOptPredicateKind kind , bool invert )
839+ _Py_uop_sym_new_predicate (JitOptContext * ctx , JitOptRef lhs_ref , JitOptRef rhs_ref , JitOptPredicateKind kind )
840840{
841841 JitOptSymbol * lhs = PyJitRef_Unwrap (lhs_ref );
842842 JitOptSymbol * rhs = PyJitRef_Unwrap (rhs_ref );
@@ -847,7 +847,6 @@ _Py_uop_sym_new_predicate(JitOptContext *ctx, JitOptRef lhs_ref, JitOptRef rhs_r
847847 }
848848
849849 res -> tag = JIT_SYM_PREDICATE_TAG ;
850- res -> predicate .invert = invert ;
851850 res -> predicate .kind = kind ;
852851 res -> predicate .lhs = (uint16_t )(lhs - allocation_base (ctx ));
853852 res -> predicate .rhs = (uint16_t )(rhs - allocation_base (ctx ));
@@ -864,34 +863,40 @@ _Py_uop_sym_apply_predicate_narrowing(JitOptContext *ctx, JitOptRef ref, bool br
864863 }
865864
866865 JitOptPredicate pred = sym -> predicate ;
867- bool narrow = (branch_is_true && !pred .invert ) || (!branch_is_true && pred .invert );
868- if (!narrow ) {
869- return ;
870- }
871866
872867 JitOptRef lhs_ref = PyJitRef_Wrap (allocation_base (ctx ) + pred .lhs );
873868 JitOptRef rhs_ref = PyJitRef_Wrap (allocation_base (ctx ) + pred .rhs );
874869
875870 bool lhs_is_const = _Py_uop_sym_is_const (ctx , lhs_ref );
876871 bool rhs_is_const = _Py_uop_sym_is_const (ctx , rhs_ref );
872+ if (!lhs_is_const && !rhs_is_const ) {
873+ return ;;
874+ }
877875
876+ bool narrow = false;
878877 switch (pred .kind ) {
879- case JIT_PRED_IS : {
880- if (!lhs_is_const && !rhs_is_const ) {
881- break ;
882- }
883- JitOptRef subject_ref = lhs_is_const ? rhs_ref : lhs_ref ;
884- JitOptRef const_ref = lhs_is_const ? lhs_ref : rhs_ref ;
885-
886- PyObject * const_val = _Py_uop_sym_get_const (ctx , const_ref );
887- if (const_val == NULL ) {
888- break ;
889- }
890- _Py_uop_sym_set_const (ctx , subject_ref , const_val );
891- assert (_Py_uop_sym_is_const (ctx , subject_ref ));
878+ case JIT_PRED_IS :
879+ narrow = branch_is_true ;
892880 break ;
893- }
881+ case JIT_PRED_IS_NOT :
882+ narrow = !branch_is_true ;
883+ break ;
884+ default :
885+ break ;
886+ }
887+ if (!narrow ) {
888+ return ;
889+ }
890+
891+ JitOptRef subject_ref = lhs_is_const ? rhs_ref : lhs_ref ;
892+ JitOptRef const_ref = lhs_is_const ? lhs_ref : rhs_ref ;
893+
894+ PyObject * const_val = _Py_uop_sym_get_const (ctx , const_ref );
895+ if (const_val == NULL ) {
896+ return ;
894897 }
898+ _Py_uop_sym_set_const (ctx , subject_ref , const_val );
899+ assert (_Py_uop_sym_is_const (ctx , subject_ref ));
895900}
896901
897902JitOptRef
@@ -1236,7 +1241,7 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
12361241 if (PyJitRef_IsNull (subject ) || PyJitRef_IsNull (const_true )) {
12371242 goto fail ;
12381243 }
1239- ref = _Py_uop_sym_new_predicate (ctx , subject , const_true , JIT_PRED_IS , false );
1244+ ref = _Py_uop_sym_new_predicate (ctx , subject , const_true , JIT_PRED_IS );
12401245 if (PyJitRef_IsNull (ref )) {
12411246 goto fail ;
12421247 }
@@ -1249,7 +1254,7 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
12491254 if (PyJitRef_IsNull (subject )) {
12501255 goto fail ;
12511256 }
1252- ref = _Py_uop_sym_new_predicate (ctx , subject , const_true , JIT_PRED_IS , false );
1257+ ref = _Py_uop_sym_new_predicate (ctx , subject , const_true , JIT_PRED_IS );
12531258 if (PyJitRef_IsNull (ref )) {
12541259 goto fail ;
12551260 }
@@ -1261,7 +1266,7 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
12611266 if (PyJitRef_IsNull (subject )) {
12621267 goto fail ;
12631268 }
1264- ref = _Py_uop_sym_new_predicate (ctx , subject , const_true , JIT_PRED_IS , true );
1269+ ref = _Py_uop_sym_new_predicate (ctx , subject , const_true , JIT_PRED_IS_NOT );
12651270 if (PyJitRef_IsNull (ref )) {
12661271 goto fail ;
12671272 }
@@ -1274,7 +1279,7 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
12741279 if (PyJitRef_IsNull (subject )) {
12751280 goto fail ;
12761281 }
1277- ref = _Py_uop_sym_new_predicate (ctx , subject , const_true , JIT_PRED_IS , true );
1282+ ref = _Py_uop_sym_new_predicate (ctx , subject , const_true , JIT_PRED_IS_NOT );
12781283 if (PyJitRef_IsNull (ref )) {
12791284 goto fail ;
12801285 }
@@ -1287,7 +1292,7 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
12871292 if (PyJitRef_IsNull (subject ) || PyJitRef_IsNull (const_none )) {
12881293 goto fail ;
12891294 }
1290- ref = _Py_uop_sym_new_predicate (ctx , subject , const_none , JIT_PRED_IS , false );
1295+ ref = _Py_uop_sym_new_predicate (ctx , subject , const_none , JIT_PRED_IS );
12911296 if (PyJitRef_IsNull (ref )) {
12921297 goto fail ;
12931298 }
@@ -1302,7 +1307,7 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
13021307 if (PyJitRef_IsNull (subject ) || PyJitRef_IsNull (const_one )) {
13031308 goto fail ;
13041309 }
1305- ref = _Py_uop_sym_new_predicate (ctx , subject , const_one , JIT_PRED_IS , false );
1310+ ref = _Py_uop_sym_new_predicate (ctx , subject , const_one , JIT_PRED_IS );
13061311 if (PyJitRef_IsNull (ref )) {
13071312 goto fail ;
13081313 }
0 commit comments