-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
GH-132732: Use pure op machinery to optimize various instructions with _POP_TOP
and _POP_TWO
#137577
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
base: main
Are you sure you want to change the base?
GH-132732: Use pure op machinery to optimize various instructions with _POP_TOP
and _POP_TWO
#137577
Changes from 12 commits
b4b2106
cc4b9ce
2d5f428
8e7023d
e75ca80
3b37082
e7a1e7e
f69228a
01a8e2a
443a924
49bd7c9
2ada46b
024690c
7945c19
55d098f
4c614a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Optimize ``_COMPARE_OP``, ``_CONTAINS_OP``, ``_GET_LEN``, ``_REPLACE_WITH_TRUE``, ``_TO_BOOL_NONE``, `_UNARY_NEGATIVE``, ``_UNARY_NOT``, and ``_UNARY_INVERT`` in JIT builds with constant-loading uops (``_POP_TWO_LOAD_CONST_INLINE_BORROW`` and ``_POP_TOP_LOAD_CONST_INLINE_BORROW``), and then remove both to reduce instruction count. | ||
savannahostrowski marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -362,6 +362,7 @@ dummy_func(void) { | |
} | ||
|
||
op(_TO_BOOL_NONE, (value -- res)) { | ||
REPLACE_OPCODE_IF_EVALUATES_PURE(value); | ||
savannahostrowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int already_bool = optimize_to_bool(this_instr, ctx, value, &res); | ||
if (!already_bool) { | ||
sym_set_const(value, Py_None); | ||
|
@@ -397,6 +398,7 @@ dummy_func(void) { | |
} | ||
|
||
op(_UNARY_NEGATIVE, (value -- res)) { | ||
REPLACE_OPCODE_IF_EVALUATES_PURE(value); | ||
if (sym_is_compact_int(value)) { | ||
res = sym_new_compact_int(ctx); | ||
} | ||
|
@@ -412,6 +414,7 @@ dummy_func(void) { | |
} | ||
|
||
op(_UNARY_INVERT, (value -- res)) { | ||
REPLACE_OPCODE_IF_EVALUATES_PURE(value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this isn't pure for bool. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oof, nice catch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it make sense to guard against booleans? Or are we saying that we can't do that/it's not worth it? Also, can one of you explain why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could guard against booleans I think. Anything that raises a warning isn't pure as that means the optimizer might cause a warning to be emitted during optimizing code, and we don't want that. To test it out, try typing ~True into the current main's CPython repl. It's a recent deprecation so it wont show up on your system cpython probably, but a warning is emitted. I found this out because I vaguely recalled reading about it somewhere https://discuss.python.org/t/bool-deprecation/62232 |
||
if (sym_matches_type(value, &PyLong_Type)) { | ||
res = sym_new_type(ctx, &PyLong_Type); | ||
} | ||
|
@@ -422,6 +425,7 @@ dummy_func(void) { | |
|
||
op(_COMPARE_OP, (left, right -- res)) { | ||
if (oparg & 16) { | ||
REPLACE_OPCODE_IF_EVALUATES_PURE(left, right); | ||
savannahostrowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
res = sym_new_type(ctx, &PyBool_Type); | ||
} | ||
else { | ||
|
@@ -449,6 +453,7 @@ dummy_func(void) { | |
} | ||
|
||
op(_CONTAINS_OP, (left, right -- b)) { | ||
REPLACE_OPCODE_IF_EVALUATES_PURE(left, right); | ||
b = sym_new_type(ctx, &PyBool_Type); | ||
} | ||
|
||
|
@@ -1023,7 +1028,7 @@ dummy_func(void) { | |
} | ||
|
||
op(_REPLACE_WITH_TRUE, (value -- res)) { | ||
REPLACE_OP(this_instr, _POP_TOP_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)Py_True); | ||
REPLACE_OPCODE_IF_EVALUATES_PURE(value); | ||
savannahostrowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
res = sym_new_const(ctx, Py_True); | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.