Skip to content

Commit 349b414

Browse files
markshannonadorilson
authored andcommitted
pythonGH-115687: Most comparisons create Booleans, so propagate that information (pythonGH-116360)
Most comparisons create booleans
1 parent b41d07d commit 349b414

File tree

2 files changed

+68
-16
lines changed

2 files changed

+68
-16
lines changed

Python/optimizer_bytecodes.c

+29
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,35 @@ dummy_func(void) {
351351
}
352352
}
353353

354+
op(_COMPARE_OP, (left, right -- res)) {
355+
if (oparg & 16) {
356+
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
357+
}
358+
else {
359+
OUT_OF_SPACE_IF_NULL(res = _Py_uop_sym_new_not_null(ctx));
360+
}
361+
}
362+
363+
op(_COMPARE_OP_INT, (left, right -- res)) {
364+
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
365+
}
366+
367+
op(_COMPARE_OP_FLOAT, (left, right -- res)) {
368+
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
369+
}
370+
371+
op(_COMPARE_OP_STR, (left, right -- res)) {
372+
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
373+
}
374+
375+
op(_IS_OP, (left, right -- res)) {
376+
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
377+
}
378+
379+
op(_CONTAINS_OP, (left, right -- res)) {
380+
OUT_OF_SPACE_IF_NULL(res = sym_new_type(ctx, &PyBool_Type));
381+
}
382+
354383
op(_LOAD_CONST, (-- value)) {
355384
// There should be no LOAD_CONST. It should be all
356385
// replaced by peephole_opt.

Python/optimizer_cases.c.h

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

0 commit comments

Comments
 (0)