Skip to content

Commit dd97d0c

Browse files
committed
Don't promote borrowed references in STORE_FAST
This reduces the number of changes to the interpreter loop and leaves the various STORE_FAST instructions unmodified. It means that we cannot optimize LOAD_FAST instructions that are consumed by STORE_FAST instructions, but I think this is a net positive. It speeds up STORE_FAST and doesn't appreciably reduce the number of optimized instructions in the benchmark suite.
1 parent bf6222b commit dd97d0c

File tree

4 files changed

+33
-21
lines changed

4 files changed

+33
-21
lines changed

Python/bytecodes.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ dummy_func(
339339

340340
replicate(8) inst(STORE_FAST, (value --)) {
341341
_PyStackRef tmp = GETLOCAL(oparg);
342-
GETLOCAL(oparg) = _PyStackRef_StealIfUnborrowed(value);
342+
GETLOCAL(oparg) = value;
343343
DEAD(value);
344344
PyStackRef_XCLOSE(tmp);
345345
}
@@ -352,7 +352,7 @@ dummy_func(
352352
uint32_t oparg1 = oparg >> 4;
353353
uint32_t oparg2 = oparg & 15;
354354
_PyStackRef tmp = GETLOCAL(oparg1);
355-
GETLOCAL(oparg1) = _PyStackRef_StealIfUnborrowed(value1);
355+
GETLOCAL(oparg1) = value1;
356356
DEAD(value1);
357357
value2 = PyStackRef_DUP(GETLOCAL(oparg2));
358358
PyStackRef_XCLOSE(tmp);
@@ -362,11 +362,11 @@ dummy_func(
362362
uint32_t oparg1 = oparg >> 4;
363363
uint32_t oparg2 = oparg & 15;
364364
_PyStackRef tmp = GETLOCAL(oparg1);
365-
GETLOCAL(oparg1) = _PyStackRef_StealIfUnborrowed(value1);
365+
GETLOCAL(oparg1) = value1;
366366
DEAD(value1);
367367
PyStackRef_XCLOSE(tmp);
368368
tmp = GETLOCAL(oparg2);
369-
GETLOCAL(oparg2) = _PyStackRef_StealIfUnborrowed(value2);
369+
GETLOCAL(oparg2) = value2;
370370
DEAD(value2);
371371
PyStackRef_XCLOSE(tmp);
372372
}

Python/executor_cases.c.h

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/flowgraph.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,22 +2614,34 @@ optimize_load_fast(cfg_builder *g)
26142614

26152615
case STORE_FAST: {
26162616
kill_local(has_killed_refs, &refs, oparg);
2617-
ref_stack_pop(&refs);
2617+
ref r = ref_stack_pop(&refs);
2618+
if (r.instr != -1) {
2619+
has_killed_refs[r.instr] = true;
2620+
}
26182621
break;
26192622
}
26202623

26212624
case STORE_FAST_LOAD_FAST: {
26222625
kill_local(has_killed_refs, &refs, oparg >> 4);
2623-
ref_stack_pop(&refs);
2626+
ref r = ref_stack_pop(&refs);
2627+
if (r.instr != -1) {
2628+
has_killed_refs[r.instr] = true;
2629+
}
26242630
ref_stack_push(&refs, (ref){i, oparg & 15});
26252631
break;
26262632
}
26272633

26282634
case STORE_FAST_STORE_FAST: {
26292635
kill_local(has_killed_refs, &refs, oparg >> 4);
26302636
kill_local(has_killed_refs, &refs, oparg & 15);
2631-
ref_stack_pop(&refs);
2632-
ref_stack_pop(&refs);
2637+
ref r = ref_stack_pop(&refs);
2638+
if (r.instr != -1) {
2639+
has_killed_refs[r.instr] = true;
2640+
}
2641+
r = ref_stack_pop(&refs);
2642+
if (r.instr != -1) {
2643+
has_killed_refs[r.instr] = true;
2644+
}
26332645
break;
26342646
}
26352647

Python/generated_cases.c.h

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)