gh-100239: Specialize more binary operations using BINARY_OP_EXTEND (GH-128956)

This commit is contained in:
Pieter Eendebak 2026-04-16 10:22:41 +02:00 committed by GitHub
parent 9d38143088
commit 1f6a09fb36
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 1850 additions and 1224 deletions

View file

@ -485,6 +485,46 @@ dummy_func(void) {
r = right;
}
op(_GUARD_BINARY_OP_EXTEND_LHS, (descr/4, left, right -- left, right)) {
_PyBinaryOpSpecializationDescr *d = (_PyBinaryOpSpecializationDescr *)descr;
assert(d != NULL && d->guard == NULL && d->lhs_type != NULL);
if (sym_matches_type(left, d->lhs_type)) {
ADD_OP(_NOP, 0, 0);
}
sym_set_type(left, d->lhs_type);
}
op(_GUARD_BINARY_OP_EXTEND_RHS, (descr/4, left, right -- left, right)) {
_PyBinaryOpSpecializationDescr *d = (_PyBinaryOpSpecializationDescr *)descr;
assert(d != NULL && d->guard == NULL && d->rhs_type != NULL);
if (sym_matches_type(right, d->rhs_type)) {
ADD_OP(_NOP, 0, 0);
}
sym_set_type(right, d->rhs_type);
}
op(_GUARD_BINARY_OP_EXTEND, (descr/4, left, right -- left, right)) {
_PyBinaryOpSpecializationDescr *d = (_PyBinaryOpSpecializationDescr *)descr;
if (d != NULL && d->guard == NULL) {
/* guard == NULL means the check is purely a type test against
lhs_type/rhs_type, so eliminate it when types are already known. */
assert(d->lhs_type != NULL && d->rhs_type != NULL);
bool lhs_known = sym_matches_type(left, d->lhs_type);
bool rhs_known = sym_matches_type(right, d->rhs_type);
if (lhs_known && rhs_known) {
ADD_OP(_NOP, 0, 0);
}
else if (lhs_known) {
ADD_OP(_GUARD_BINARY_OP_EXTEND_RHS, 0, (uintptr_t)d);
sym_set_type(right, d->rhs_type);
}
else if (rhs_known) {
ADD_OP(_GUARD_BINARY_OP_EXTEND_LHS, 0, (uintptr_t)d);
sym_set_type(left, d->lhs_type);
}
}
}
op(_BINARY_OP_EXTEND, (descr/4, left, right -- res, l, r)) {
_PyBinaryOpSpecializationDescr *d = (_PyBinaryOpSpecializationDescr *)descr;
if (d != NULL && d->result_type != NULL) {