GH-130415: Narrow int to 0 based on boolean tests (GH-130772)

This commit is contained in:
Klaus117 2025-03-04 12:44:09 -08:00 committed by GitHub
parent e20e47dda6
commit c989e74446
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 38 additions and 2 deletions

View file

@ -406,7 +406,7 @@ dummy_func(void) {
op(_TO_BOOL_INT, (value -- res)) {
if (!optimize_to_bool(this_instr, ctx, value, &res)) {
sym_set_type(value, &PyLong_Type);
res = sym_new_type(ctx, &PyBool_Type);
res = sym_new_truthiness(ctx, value, true);
}
}

View file

@ -178,7 +178,7 @@
value = stack_pointer[-1];
if (!optimize_to_bool(this_instr, ctx, value, &res)) {
sym_set_type(value, &PyLong_Type);
res = sym_new_type(ctx, &PyBool_Type);
res = sym_new_truthiness(ctx, value, true);
}
stack_pointer[-1] = res;
break;

View file

@ -299,6 +299,9 @@ _Py_uop_sym_set_const(JitOptContext *ctx, JitOptSymbol *sym, PyObject *const_val
else if (type == &PyBool_Type) {
_Py_uop_sym_set_const(ctx, value, Py_False);
}
else if (type == &PyLong_Type) {
_Py_uop_sym_set_const(ctx, value, Py_GetConstant(Py_CONSTANT_ZERO));
}
// TODO: More types (GH-130415)!
make_const(sym, const_val);
return;