Skip to content

Commit 156b0df

Browse files
committed
Add optimizer symbol unit tests
1 parent e9548a2 commit 156b0df

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Python/optimizer_symbols.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,21 @@ _Py_uop_symbols_test(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored))
12891289
TEST_PREDICATE(_Py_uop_sym_is_const(ctx, subject), "predicate narrowing did not const-narrow subject (None)");
12901290
TEST_PREDICATE(_Py_uop_sym_get_const(ctx, subject) == Py_None, "predicate narrowing did not narrow subject to None");
12911291

1292+
// Test narrowing subject to numerical constant
1293+
subject = _Py_uop_sym_new_unknown(ctx);
1294+
PyObject *one_obj = PyLong_FromLong(1);
1295+
JitOptRef const_one = _Py_uop_sym_new_const(ctx, one_obj);
1296+
if (PyJitRef_IsNull(subject) || PyJitRef_IsNull(const_one)) {
1297+
goto fail;
1298+
}
1299+
ref = _Py_uop_sym_new_predicate(ctx, subject, const_one, JIT_PRED_IS, false);
1300+
if (PyJitRef_IsNull(ref)) {
1301+
goto fail;
1302+
}
1303+
_Py_uop_sym_apply_predicate_narrowing(ctx, ref, true);
1304+
TEST_PREDICATE(_Py_uop_sym_is_const(ctx, subject), "predicate narrowing did not const-narrow subject (1)");
1305+
TEST_PREDICATE(_Py_uop_sym_get_const(ctx, subject) == one_obj, "predicate narrowing did not narrow subject to 1");
1306+
12921307
val_big = PyNumber_Lshift(_PyLong_GetOne(), PyLong_FromLong(66));
12931308
if (val_big == NULL) {
12941309
goto fail;

0 commit comments

Comments
 (0)