gh-115859: Re-enable T2 optimizer pass by default (#116062)

This undoes the *temporary* default disabling of the T2 optimizer pass in gh-115860.

- Add a new test that reproduces Brandt's example from gh-115859; it indeed crashes before gh-116028 with PYTHONUOPSOPTIMIZE=1
- Re-enable the optimizer pass in T2, stop checking PYTHONUOPSOPTIMIZE
- Rename the env var to disable T2 entirely to PYTHON_UOPS_OPTIMIZE (must be explicitly set to 0 to disable)
- Fix skipIf conditions on tests in test_opt.py accordingly
- Export sym_is_bottom() (for debugging)
- Fix various things in the `_BINARY_OP_` specializations in the abstract interpreter:
  - DECREF(temp)
  - out-of-space check after sym_new_const()
  - add sym_matches_type() checks, so even if we somehow reach a binary op with symbolic constants of the wrong type on the stack we won't trigger the type assert
This commit is contained in:
Guido van Rossum 2024-02-28 14:38:01 -08:00 committed by GitHub
parent 75c6c05fea
commit 3409bc29c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 96 additions and 28 deletions

View file

@ -183,7 +183,9 @@
_Py_UopsSymbol *res;
right = stack_pointer[-1];
left = stack_pointer[-2];
if (sym_is_const(left) && sym_is_const(right)) {
if (sym_is_const(left) && sym_is_const(right) &&
sym_matches_type(left, &PyLong_Type) && sym_matches_type(right, &PyLong_Type))
{
assert(PyLong_CheckExact(sym_get_const(left)));
assert(PyLong_CheckExact(sym_get_const(right)));
PyObject *temp = _PyLong_Multiply((PyLongObject *)sym_get_const(left),
@ -191,7 +193,9 @@
if (temp == NULL) {
goto error;
}
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
res = sym_new_const(ctx, temp);
Py_DECREF(temp);
OUT_OF_SPACE_IF_NULL(res);
// TODO gh-115506:
// replace opcode with constant propagated one and add tests!
}
@ -209,7 +213,9 @@
_Py_UopsSymbol *res;
right = stack_pointer[-1];
left = stack_pointer[-2];
if (sym_is_const(left) && sym_is_const(right)) {
if (sym_is_const(left) && sym_is_const(right) &&
sym_matches_type(left, &PyLong_Type) && sym_matches_type(right, &PyLong_Type))
{
assert(PyLong_CheckExact(sym_get_const(left)));
assert(PyLong_CheckExact(sym_get_const(right)));
PyObject *temp = _PyLong_Add((PyLongObject *)sym_get_const(left),
@ -217,7 +223,9 @@
if (temp == NULL) {
goto error;
}
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
res = sym_new_const(ctx, temp);
Py_DECREF(temp);
OUT_OF_SPACE_IF_NULL(res);
// TODO gh-115506:
// replace opcode with constant propagated one and add tests!
}
@ -235,7 +243,9 @@
_Py_UopsSymbol *res;
right = stack_pointer[-1];
left = stack_pointer[-2];
if (sym_is_const(left) && sym_is_const(right)) {
if (sym_is_const(left) && sym_is_const(right) &&
sym_matches_type(left, &PyLong_Type) && sym_matches_type(right, &PyLong_Type))
{
assert(PyLong_CheckExact(sym_get_const(left)));
assert(PyLong_CheckExact(sym_get_const(right)));
PyObject *temp = _PyLong_Subtract((PyLongObject *)sym_get_const(left),
@ -243,7 +253,9 @@
if (temp == NULL) {
goto error;
}
OUT_OF_SPACE_IF_NULL(res = sym_new_const(ctx, temp));
res = sym_new_const(ctx, temp);
Py_DECREF(temp);
OUT_OF_SPACE_IF_NULL(res);
// TODO gh-115506:
// replace opcode with constant propagated one and add tests!
}
@ -275,7 +287,9 @@
_Py_UopsSymbol *res;
right = stack_pointer[-1];
left = stack_pointer[-2];
if (sym_is_const(left) && sym_is_const(right)) {
if (sym_is_const(left) && sym_is_const(right) &&
sym_matches_type(left, &PyFloat_Type) && sym_matches_type(right, &PyFloat_Type))
{
assert(PyFloat_CheckExact(sym_get_const(left)));
assert(PyFloat_CheckExact(sym_get_const(right)));
PyObject *temp = PyFloat_FromDouble(
@ -285,6 +299,8 @@
goto error;
}
res = sym_new_const(ctx, temp);
Py_DECREF(temp);
OUT_OF_SPACE_IF_NULL(res);
// TODO gh-115506:
// replace opcode with constant propagated one and update tests!
}
@ -302,7 +318,9 @@
_Py_UopsSymbol *res;
right = stack_pointer[-1];
left = stack_pointer[-2];
if (sym_is_const(left) && sym_is_const(right)) {
if (sym_is_const(left) && sym_is_const(right) &&
sym_matches_type(left, &PyFloat_Type) && sym_matches_type(right, &PyFloat_Type))
{
assert(PyFloat_CheckExact(sym_get_const(left)));
assert(PyFloat_CheckExact(sym_get_const(right)));
PyObject *temp = PyFloat_FromDouble(
@ -312,6 +330,8 @@
goto error;
}
res = sym_new_const(ctx, temp);
Py_DECREF(temp);
OUT_OF_SPACE_IF_NULL(res);
// TODO gh-115506:
// replace opcode with constant propagated one and update tests!
}
@ -329,7 +349,9 @@
_Py_UopsSymbol *res;
right = stack_pointer[-1];
left = stack_pointer[-2];
if (sym_is_const(left) && sym_is_const(right)) {
if (sym_is_const(left) && sym_is_const(right) &&
sym_matches_type(left, &PyFloat_Type) && sym_matches_type(right, &PyFloat_Type))
{
assert(PyFloat_CheckExact(sym_get_const(left)));
assert(PyFloat_CheckExact(sym_get_const(right)));
PyObject *temp = PyFloat_FromDouble(
@ -339,6 +361,8 @@
goto error;
}
res = sym_new_const(ctx, temp);
Py_DECREF(temp);
OUT_OF_SPACE_IF_NULL(res);
// TODO gh-115506:
// replace opcode with constant propagated one and update tests!
}