Skip to content
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-118093: Don't lose confidence when tracing through 100% biased branches #124813

Merged
merged 5 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improve the experimental JIT compiler's ability to stay "on trace" when
encountering highly-biased branches.
6 changes: 2 additions & 4 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,14 +643,12 @@ translate_bytecode_to_trace(
int bitcount = _Py_popcount32(counter);
int jump_likely = bitcount > 8;
/* If bitcount is 8 (half the jumps were taken), adjust confidence by 50%.
If it's 16 or 0 (all or none were taken), adjust by 10%
(since the future is still somewhat uncertain).
For values in between, adjust proportionally. */
if (jump_likely) {
confidence = confidence * (bitcount + 2) / 20;
confidence = confidence * bitcount / 16;
}
else {
confidence = confidence * (18 - bitcount) / 20;
confidence = confidence * (16 - bitcount) / 16;
}
uint32_t uopcode = BRANCH_TO_GUARD[opcode - POP_JUMP_IF_FALSE][jump_likely];
DPRINTF(2, "%d: %s(%d): counter=%04x, bitcount=%d, likely=%d, confidence=%d, uopcode=%s\n",
Expand Down
Loading