mirror of
https://github.com/python/cpython.git
synced 2025-09-22 08:23:36 +00:00
bpo-46528: Simplify BUILD_TUPLE/UNPACK_SEQUENCE folding (GH-31039)
This commit is contained in:
parent
bebaa95fd0
commit
a0e55a571c
2 changed files with 8 additions and 15 deletions
|
@ -126,7 +126,7 @@ class TestTranforms(BytecodeTestCase):
|
||||||
code = compile(line,'','single')
|
code = compile(line,'','single')
|
||||||
self.assertInBytecode(code, elem)
|
self.assertInBytecode(code, elem)
|
||||||
self.assertNotInBytecode(code, 'BUILD_TUPLE')
|
self.assertNotInBytecode(code, 'BUILD_TUPLE')
|
||||||
self.assertNotInBytecode(code, 'UNPACK_TUPLE')
|
self.assertNotInBytecode(code, 'UNPACK_SEQUENCE')
|
||||||
self.check_lnotab(code)
|
self.check_lnotab(code)
|
||||||
|
|
||||||
def test_folding_of_tuples_of_constants(self):
|
def test_folding_of_tuples_of_constants(self):
|
||||||
|
|
|
@ -8661,29 +8661,22 @@ optimize_basic_block(struct compiler *c, basicblock *bb, PyObject *consts)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try to fold tuples of constants.
|
/* Try to fold tuples of constants.
|
||||||
Skip over BUILD_SEQN 1 UNPACK_SEQN 1.
|
Skip over BUILD_TUPLE(1) UNPACK_SEQUENCE(1).
|
||||||
Replace BUILD_SEQN 2 UNPACK_SEQN 2 with ROT2.
|
Replace BUILD_TUPLE(2) UNPACK_SEQUENCE(2) with SWAP(2).
|
||||||
Replace BUILD_SEQN 3 UNPACK_SEQN 3 with ROT3 ROT2. */
|
Replace BUILD_TUPLE(3) UNPACK_SEQUENCE(3) with SWAP(3). */
|
||||||
case BUILD_TUPLE:
|
case BUILD_TUPLE:
|
||||||
if (nextop == UNPACK_SEQUENCE && oparg == bb->b_instr[i+1].i_oparg) {
|
if (nextop == UNPACK_SEQUENCE && oparg == bb->b_instr[i+1].i_oparg) {
|
||||||
switch(oparg) {
|
switch(oparg) {
|
||||||
case 1:
|
case 1:
|
||||||
inst->i_opcode = NOP;
|
inst->i_opcode = NOP;
|
||||||
bb->b_instr[i+1].i_opcode = NOP;
|
bb->b_instr[i+1].i_opcode = NOP;
|
||||||
break;
|
continue;
|
||||||
case 2:
|
case 2:
|
||||||
inst->i_opcode = SWAP;
|
|
||||||
inst->i_oparg = 2;
|
|
||||||
bb->b_instr[i+1].i_opcode = NOP;
|
|
||||||
i--;
|
|
||||||
break;
|
|
||||||
case 3:
|
case 3:
|
||||||
inst->i_opcode = SWAP;
|
inst->i_opcode = NOP;
|
||||||
inst->i_oparg = 3;
|
bb->b_instr[i+1].i_opcode = SWAP;
|
||||||
bb->b_instr[i+1].i_opcode = NOP;
|
continue;
|
||||||
i--;
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (i >= oparg) {
|
if (i >= oparg) {
|
||||||
if (fold_tuple_on_constants(c, inst-oparg, oparg, consts)) {
|
if (fold_tuple_on_constants(c, inst-oparg, oparg, consts)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue