gh-138302: Specialize int ops only if ints are compact (GH-138347)

This commit is contained in:
Tapeline 2025-09-01 22:33:15 +05:00 committed by GitHub
parent 6528cf47a0
commit ea77feecbb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 3 deletions

View file

@ -2595,7 +2595,7 @@ _Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *in
specialize(instr, BINARY_OP_ADD_UNICODE);
return;
}
if (PyLong_CheckExact(lhs)) {
if (_PyLong_CheckExactAndCompact(lhs) && _PyLong_CheckExactAndCompact(rhs)) {
specialize(instr, BINARY_OP_ADD_INT);
return;
}
@ -2609,7 +2609,7 @@ _Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *in
if (!Py_IS_TYPE(lhs, Py_TYPE(rhs))) {
break;
}
if (PyLong_CheckExact(lhs)) {
if (_PyLong_CheckExactAndCompact(lhs) && _PyLong_CheckExactAndCompact(rhs)) {
specialize(instr, BINARY_OP_MULTIPLY_INT);
return;
}
@ -2623,7 +2623,7 @@ _Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *in
if (!Py_IS_TYPE(lhs, Py_TYPE(rhs))) {
break;
}
if (PyLong_CheckExact(lhs)) {
if (_PyLong_CheckExactAndCompact(lhs) && _PyLong_CheckExactAndCompact(rhs)) {
specialize(instr, BINARY_OP_SUBTRACT_INT);
return;
}