GeezerVison is showing github.com — Implement simple dead store elimination in cfg opt · corona10/cpython@477a02c
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Lib/test/test_dis.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -811,7 +811,7 @@ def extended_arg_quick(): | 811 | 811 | %3d 2 LOAD_CONST 1 (Ellipsis) | 812 | 812 | 4 EXTENDED_ARG 1 | 813 | 813 | 6 UNPACK_EX 256 | 814 | | - 8 STORE_FAST 0 (_) | | 814 | + 8 POP_TOP | 815 | 815 | 10 STORE_FAST 0 (_) | 816 | 816 | 12 RETURN_CONST 0 (None) | 817 | 817 | """% (extended_arg_quick.__code__.co_firstlineno, | |
Collapse file Copy file name to clipboardExpand all lines: Lib/test/test_peepholer.py +11-1Lines changed: 11 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1071,7 +1071,17 @@ def test_no_unsafe_static_swap(self): | 1071 | 1071 | ('POP_TOP', 0, 4), | 1072 | 1072 | ('RETURN_VALUE', 5) | 1073 | 1073 | ] | 1074 | | - self.cfg_optimization_test(insts, insts, consts=list(range(3)), nlocals=1) | | 1074 | + expected_insts = [ | | 1075 | + ('LOAD_CONST', 0, 1), | | 1076 | + ('LOAD_CONST', 1, 2), | | 1077 | + ('LOAD_CONST', 2, 3), | | 1078 | + ('SWAP', 3, 4), | | 1079 | + ('POP_TOP', 0, 4), | | 1080 | + ('STORE_FAST', 1, 4), | | 1081 | + ('POP_TOP', 0, 4), | | 1082 | + ('RETURN_VALUE', 5) | | 1083 | + ] | | 1084 | + self.cfg_optimization_test(insts, expected_insts, consts=list(range(3)), nlocals=1) | 1075 | 1085 |
| 1076 | 1086 | if __name__ == "__main__": | 1077 | 1087 | unittest.main() |
Collapse file Copy file name to clipboardExpand all lines: Python/flowgraph.c +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1515,6 +1515,12 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts) | 1515 | 1515 | */ | 1516 | 1516 | } | 1517 | 1517 | break; | | 1518 | + case STORE_FAST: | | 1519 | + if (opcode == nextop && oparg == bb->b_instr[i+1].i_oparg) { | | 1520 | + bb->b_instr[i].i_opcode = POP_TOP; | | 1521 | + bb->b_instr[i].i_oparg = 0; | | 1522 | + } | | 1523 | + break; | 1518 | 1524 | case SWAP: | 1519 | 1525 | if (oparg == 1) { | 1520 | 1526 | INSTR_SET_OP0(inst, NOP); | |
|