Skip to content

Commit 70c1a9e

Browse files
committed
Move apply_static_swap to the last phase of bb optimization
1 parent 8126145 commit 70c1a9e

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

Lib/test/test_peepholer.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,9 +1074,7 @@ def test_no_unsafe_static_swap(self):
10741074
expected_insts = [
10751075
('LOAD_CONST', 0, 1),
10761076
('LOAD_CONST', 1, 2),
1077-
('LOAD_CONST', 2, 3),
1078-
('SWAP', 3, 4),
1079-
('POP_TOP', 0, 4),
1077+
('NOP', 0, 3),
10801078
('STORE_FAST', 1, 4),
10811079
('POP_TOP', 0, 4),
10821080
('RETURN_VALUE', 5)
@@ -1096,7 +1094,7 @@ def test_dead_store_elimination_in_same_lineno(self):
10961094
expected_insts = [
10971095
('LOAD_CONST', 0, 1),
10981096
('LOAD_CONST', 1, 2),
1099-
('NOP', None, 3),
1097+
('NOP', 0, 3),
11001098
('POP_TOP', 0, 4),
11011099
('STORE_FAST', 1, 4),
11021100
('RETURN_VALUE', 5)

Python/flowgraph.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,12 +1526,7 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts)
15261526
case SWAP:
15271527
if (oparg == 1) {
15281528
INSTR_SET_OP0(inst, NOP);
1529-
break;
1530-
}
1531-
if (swaptimize(bb, &i) < 0) {
1532-
goto error;
15331529
}
1534-
apply_static_swaps(bb, i);
15351530
break;
15361531
case KW_NAMES:
15371532
break;
@@ -1546,6 +1541,15 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts)
15461541
assert (!HAS_CONST(inst->i_opcode));
15471542
}
15481543
}
1544+
for (int i = 0; i < bb->b_iused; i++) {
1545+
cfg_instr *inst = &bb->b_instr[i];
1546+
if (inst->i_opcode == SWAP) {
1547+
if (swaptimize(bb, &i) < 0) {
1548+
goto error;
1549+
}
1550+
apply_static_swaps(bb, i);
1551+
}
1552+
}
15491553
return SUCCESS;
15501554
error:
15511555
return ERROR;

0 commit comments

Comments
 (0)