-
-
Notifications
You must be signed in to change notification settings - Fork 32k
GH-130415: Optimize JIT path for _TO_BOOL_INT branching #130477
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
Changes from 2 commits
76793af
c647e39
a1139cf
b1702f2
debc65d
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 |
---|---|---|
|
@@ -1437,6 +1437,67 @@ def crash_addition(): | |
|
||
crash_addition() | ||
|
||
def test_narrow_type_to_constant_int_zero(self): | ||
def f(n): | ||
trace = [] | ||
for i in range(n): | ||
# f is always (int) 0, but we can only prove that it's a integer: | ||
f = i - i # at this point python knows f is an int, but doesnt know that it is 0 (we know it is 0 though) | ||
trace.append("A") | ||
if not f: # Kept. | ||
trace.append("B") | ||
if not f: # Removed! | ||
trace.append("C") | ||
trace.append("D") | ||
if f: # Removed! | ||
trace.append("X") | ||
trace.append("E") | ||
trace.append("F") | ||
if f: # Removed! | ||
trace.append("X") | ||
trace.append("G") | ||
return trace | ||
|
||
trace, ex = self._run_with_optimizer(f, TIER2_THRESHOLD) | ||
self.assertEqual(trace, list("ABCDEFG") * TIER2_THRESHOLD) | ||
self.assertIsNotNone(ex) | ||
uops = get_opnames(ex) | ||
# Only one guard remains: | ||
self.assertEqual(uops.count("_GUARD_IS_FALSE_POP"), 1) | ||
self.assertEqual(uops.count("_GUARD_IS_TRUE_POP"), 0) | ||
# But all of the appends we care about are still there: | ||
self.assertEqual(uops.count("_CALL_LIST_APPEND"), len("ABCDEFG")) | ||
|
||
# def test_narrow_type_to_constant_bool_true(self): | ||
# def f(n): | ||
# trace = [] | ||
# for i in range(n): | ||
# # f is always True, but we can only prove that it's a bool: | ||
# f = i != TIER2_THRESHOLD | ||
# trace.append("A") | ||
# if f: # Kept. | ||
# trace.append("B") | ||
# if not f: # Removed! | ||
# trace.append("X") | ||
# trace.append("C") | ||
# if f: # Removed! | ||
# trace.append("D") | ||
# trace.append("E") | ||
# trace.append("F") | ||
# if not f: # Removed! | ||
# trace.append("X") | ||
# trace.append("G") | ||
# return trace | ||
|
||
# trace, ex = self._run_with_optimizer(f, TIER2_THRESHOLD) | ||
# self.assertEqual(trace, list("ABCDEFG") * TIER2_THRESHOLD) | ||
# self.assertIsNotNone(ex) | ||
# uops = get_opnames(ex) | ||
# # Only one guard remains: | ||
# self.assertEqual(uops.count("_GUARD_IS_FALSE_POP"), 0) | ||
# self.assertEqual(uops.count("_GUARD_IS_TRUE_POP"), 1) | ||
# # But all of the appends we care about are still there: | ||
# self.assertEqual(uops.count("_CALL_LIST_APPEND"), len("ABCDEFG")) | ||
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. Can you remove this commented test? |
||
|
||
def global_identity(x): | ||
return x | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Improve JIT understanding of integers in boolean context. | ||
Klaus117 marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -407,6 +407,23 @@ dummy_func(void) { | |||||||||
sym_set_type(value, &PyLong_Type); | ||||||||||
res = sym_new_type(ctx, &PyBool_Type); | ||||||||||
} | ||||||||||
if (!sym_is_const(value)) { | ||||||||||
assert(sym_matches_type(value, &PyLong_Type)); | ||||||||||
int next_opcode = (this_instr + 1)->opcode; | ||||||||||
assert(next_opcode == _CHECK_VALIDITY_AND_SET_IP); | ||||||||||
next_opcode = (this_instr + 2)->opcode; | ||||||||||
// If the next uop is a guard, we can narrow value. However, we | ||||||||||
// *can't* narrow res, since that would cause the guard to be | ||||||||||
// removed and the narrowed value to be invalid: | ||||||||||
if (next_opcode == _GUARD_IS_FALSE_POP) { | ||||||||||
sym_set_const(value, Py_GetConstant(Py_CONSTANT_ZERO)); | ||||||||||
res = sym_new_type(ctx, &PyLong_Type); | ||||||||||
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. This is always a boolean, since it's the output of the
Suggested change
|
||||||||||
} | ||||||||||
// else if (next_opcode == _GUARD_IS_TRUE_POP) { | ||||||||||
// sym_set_const(value, Py_True); | ||||||||||
// res = sym_new_type(ctx, &PyBool_Type); | ||||||||||
// } | ||||||||||
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.
Suggested change
|
||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
op(_TO_BOOL_LIST, (value -- res)) { | ||||||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Can you rename
f
in this function tozero
?