-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-130480: Move LOAD_SMALL_INT
optimization from codegen to CFG
#130481
base: main
Are you sure you want to change the base?
Conversation
if (maybe_instr_make_load_smallint(inst, constant, consts, const_cache)) { | ||
assert(inst->i_opcode == LOAD_SMALL_INT); | ||
} | ||
Py_DECREF(constant); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For small ints this is effectively no-op as they are immortal, but it helps readability because get_const_value
returns new reference.
if (inst->i_opcode == LOAD_CONST) { | ||
PyObject *constant = get_const_value(inst->i_opcode, inst->i_oparg, consts); | ||
if (maybe_instr_make_load_smallint(inst, constant, consts, const_cache)) { | ||
assert(inst->i_opcode == LOAD_SMALL_INT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the assert needed? If so, maybe you can assert inside maybe_instr_make_load_smallint
(then we could also get rid of the if
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It helps readability IMO, and performance-wise (if this is your concern), asserts are stripped out on non-debug builds so compiler should eliminate this branch.
@@ -1992,6 +2006,13 @@ basicblock_optimize_load_const(PyObject *const_cache, basicblock *bb, PyObject * | |||
int oparg = 0; | |||
for (int i = 0; i < bb->b_iused; i++) { | |||
cfg_instr *inst = &bb->b_instr[i]; | |||
if (inst->i_opcode == LOAD_CONST) { | |||
PyObject *constant = get_const_value(inst->i_opcode, inst->i_oparg, consts); | |||
if (maybe_instr_make_load_smallint(inst, constant, consts, const_cache)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that having an if
with just one assert
feels a bit weird.
LOAD_SMALL_INT
optimization from codegen to CFG #130480cc @Eclips4 @tomasr8