You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please don't work on this. I'm planning on sprinting on this with new contributors at an event this weekend.
Currently, the JIT optimizer uses the _COMPARE_OP family, _CONTAINS_OP, _IS_OP, and the _TO_BOOL family to narrow the types of the input values and the type of the output value.
However, by "peeking ahead" and seeing how a value will be used, we can narrow these types to constants as well. As a simple example, consider _TO_BOOL_INT + _GUARD_IS_FALSE_CHECK on an unknown value. After the _TO_BOOL_INT, it can be narrowed to a known class, int (we do this today). However, after the _GUARD_IS_FALSE_CHECK, we can actually narrow it to a constant value, 0.
This is related, but a bit more involved, since we need a way to pop two values from the stack and push a constant (_POP_TWO_LOAD_CONST_INLINE_BORROW). We should also teach remove_unneeded_uops about this new instruction.
Please don't work on this. I'm planning on sprinting on this with new contributors at an event this weekend.
Currently, the JIT optimizer uses the
_COMPARE_OPfamily,_CONTAINS_OP,_IS_OP, and the_TO_BOOLfamily to narrow the types of the input values and the type of the output value.However, by "peeking ahead" and seeing how a value will be used, we can narrow these types to constants as well. As a simple example, consider
_TO_BOOL_INT + _GUARD_IS_FALSE_CHECKon an unknown value. After the_TO_BOOL_INT, it can be narrowed to a known class,int(we do this today). However, after the_GUARD_IS_FALSE_CHECK, we can actually narrow it to a constant value,0.An example implementation of this idea for
_TO_BOOL_BOOLis here: main...brandtbucher:cpython:hack-night-to-bool-boolI've divided this work into 3 "waves" of increasing complexity. Tasks in bold are probably a bit harder, tasks in italics are probably a bit easier.
Narrow types to constants in branches involving truthiness:
_TO_BOOL + _GUARD_IS_*_POPgh-130659_TO_BOOL_BOOL + _GUARD_IS_*_POPgh-130659_TO_BOOL_INT + _GUARD_IS_*_POPgh-130772_TO_BOOL_LIST + _GUARD_IS_*_POP_TO_BOOL_STR + _GUARD_IS_*_POPgh-130476Narrow types to constants in branches involving comparisons with a constant:
_COMPARE_OP + _GUARD_IS_*_POP(==,!=)_COMPARE_OP_FLOAT + _GUARD_IS_*_POP(==,!=) gh-130415: Narrow types to constants in branches involving specialized comparisons with a constant #144150_COMPARE_OP_INT + _GUARD_IS_*_POP(==,!=) gh-130415: Narrow types to constants in branches involving specialized comparisons with a constant #144150_COMPARE_OP_STR + _GUARD_IS_*_POP(==,!=) gh-130415: Narrow types to constants in branches involving specialized comparisons with a constant #144150_CONTAINS_OP + _GUARD_IS_*_POP(in,not in)_IS_OP + _GUARD_IS_*_POP(is,is not) gh-130415: Narrowing to constants in branches involvingiscomparisons with a constant #143895Evaluate comparisons involving two constants:
This is related, but a bit more involved, since we need a way to pop two values from the stack and push a constant (
_POP_TWO_LOAD_CONST_INLINE_BORROW). We should also teachremove_unneeded_uopsabout this new instruction._COMPARE_OP(==,!=,<,>,<=,>=)_COMPARE_OP_FLOAT(==,!=,<,>,<=,>=) gh-137062_COMPARE_OP_INT(==,!=,<,>,<=,>=) gh-131489_COMPARE_OP_STR(==,!=,<,>,<=,>=) gh-137062_CONTAINS_OP(in,not in)_IS_OP(is,is not)Linked PRs
strto""based on boolean tests #130476intto0based on boolean tests #130772sym_matches_typecalls in the JIT optimizer #131778POP_TWO_LOAD_CONST_INLINE_BORROW#134241COMPARE_OP_INT/FLOAT/STR#137062iscomparisons with a constant #143895