Skip to content

Commit 972a295

Browse files
authored
GH-130415: Remove redundant sym_matches_type calls in the JIT optimizer (GH-131778)
1 parent a096a41 commit 972a295

File tree

2 files changed

+26
-48
lines changed

2 files changed

+26
-48
lines changed

Diff for: Python/optimizer_bytecodes.c

+13-24
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,7 @@ dummy_func(void) {
224224
}
225225

226226
op(_BINARY_OP_ADD_INT, (left, right -- res)) {
227-
if (sym_is_const(ctx, left) && sym_is_const(ctx, right) &&
228-
sym_matches_type(left, &PyLong_Type) && sym_matches_type(right, &PyLong_Type))
229-
{
227+
if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) {
230228
assert(PyLong_CheckExact(sym_get_const(ctx, left)));
231229
assert(PyLong_CheckExact(sym_get_const(ctx, right)));
232230
PyObject *temp = _PyLong_Add((PyLongObject *)sym_get_const(ctx, left),
@@ -245,9 +243,7 @@ dummy_func(void) {
245243
}
246244

247245
op(_BINARY_OP_SUBTRACT_INT, (left, right -- res)) {
248-
if (sym_is_const(ctx, left) && sym_is_const(ctx, right) &&
249-
sym_matches_type(left, &PyLong_Type) && sym_matches_type(right, &PyLong_Type))
250-
{
246+
if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) {
251247
assert(PyLong_CheckExact(sym_get_const(ctx, left)));
252248
assert(PyLong_CheckExact(sym_get_const(ctx, right)));
253249
PyObject *temp = _PyLong_Subtract((PyLongObject *)sym_get_const(ctx, left),
@@ -266,9 +262,7 @@ dummy_func(void) {
266262
}
267263

268264
op(_BINARY_OP_MULTIPLY_INT, (left, right -- res)) {
269-
if (sym_is_const(ctx, left) && sym_is_const(ctx, right) &&
270-
sym_matches_type(left, &PyLong_Type) && sym_matches_type(right, &PyLong_Type))
271-
{
265+
if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) {
272266
assert(PyLong_CheckExact(sym_get_const(ctx, left)));
273267
assert(PyLong_CheckExact(sym_get_const(ctx, right)));
274268
PyObject *temp = _PyLong_Multiply((PyLongObject *)sym_get_const(ctx, left),
@@ -287,9 +281,7 @@ dummy_func(void) {
287281
}
288282

289283
op(_BINARY_OP_ADD_FLOAT, (left, right -- res)) {
290-
if (sym_is_const(ctx, left) && sym_is_const(ctx, right) &&
291-
sym_matches_type(left, &PyFloat_Type) && sym_matches_type(right, &PyFloat_Type))
292-
{
284+
if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) {
293285
assert(PyFloat_CheckExact(sym_get_const(ctx, left)));
294286
assert(PyFloat_CheckExact(sym_get_const(ctx, right)));
295287
PyObject *temp = PyFloat_FromDouble(
@@ -309,9 +301,7 @@ dummy_func(void) {
309301
}
310302

311303
op(_BINARY_OP_SUBTRACT_FLOAT, (left, right -- res)) {
312-
if (sym_is_const(ctx, left) && sym_is_const(ctx, right) &&
313-
sym_matches_type(left, &PyFloat_Type) && sym_matches_type(right, &PyFloat_Type))
314-
{
304+
if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) {
315305
assert(PyFloat_CheckExact(sym_get_const(ctx, left)));
316306
assert(PyFloat_CheckExact(sym_get_const(ctx, right)));
317307
PyObject *temp = PyFloat_FromDouble(
@@ -331,9 +321,7 @@ dummy_func(void) {
331321
}
332322

333323
op(_BINARY_OP_MULTIPLY_FLOAT, (left, right -- res)) {
334-
if (sym_is_const(ctx, left) && sym_is_const(ctx, right) &&
335-
sym_matches_type(left, &PyFloat_Type) && sym_matches_type(right, &PyFloat_Type))
336-
{
324+
if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) {
337325
assert(PyFloat_CheckExact(sym_get_const(ctx, left)));
338326
assert(PyFloat_CheckExact(sym_get_const(ctx, right)));
339327
PyObject *temp = PyFloat_FromDouble(
@@ -353,8 +341,9 @@ dummy_func(void) {
353341
}
354342

355343
op(_BINARY_OP_ADD_UNICODE, (left, right -- res)) {
356-
if (sym_is_const(ctx, left) && sym_is_const(ctx, right) &&
357-
sym_matches_type(left, &PyUnicode_Type) && sym_matches_type(right, &PyUnicode_Type)) {
344+
if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) {
345+
assert(PyUnicode_CheckExact(sym_get_const(ctx, left)));
346+
assert(PyUnicode_CheckExact(sym_get_const(ctx, right)));
358347
PyObject *temp = PyUnicode_Concat(sym_get_const(ctx, left), sym_get_const(ctx, right));
359348
if (temp == NULL) {
360349
goto error;
@@ -369,8 +358,9 @@ dummy_func(void) {
369358

370359
op(_BINARY_OP_INPLACE_ADD_UNICODE, (left, right -- )) {
371360
JitOptSymbol *res;
372-
if (sym_is_const(ctx, left) && sym_is_const(ctx, right) &&
373-
sym_matches_type(left, &PyUnicode_Type) && sym_matches_type(right, &PyUnicode_Type)) {
361+
if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) {
362+
assert(PyUnicode_CheckExact(sym_get_const(ctx, left)));
363+
assert(PyUnicode_CheckExact(sym_get_const(ctx, right)));
374364
PyObject *temp = PyUnicode_Concat(sym_get_const(ctx, left), sym_get_const(ctx, right));
375365
if (temp == NULL) {
376366
goto error;
@@ -446,8 +436,7 @@ dummy_func(void) {
446436
}
447437

448438
op(_COMPARE_OP_INT, (left, right -- res)) {
449-
if (sym_is_const(ctx, left) && sym_is_const(ctx, right))
450-
{
439+
if (sym_is_const(ctx, left) && sym_is_const(ctx, right)) {
451440
assert(PyLong_CheckExact(sym_get_const(ctx, left)));
452441
assert(PyLong_CheckExact(sym_get_const(ctx, right)));
453442
PyObject *tmp = PyObject_RichCompare(sym_get_const(ctx, left),

Diff for: Python/optimizer_cases.c.h

+13-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)