@@ -1515,20 +1515,18 @@ fold_tuple_of_constants(basicblock *bb, int i, PyObject *consts,
15151515 ...
15161516 LOAD_CONST cN
15171517 LIST_APPEND/SET_ADD 1
1518- [CALL_INTRINSIC_1 INTRINSIC_LIST_TO_TUPLE] <-- when expected_append is true
1518+ [CALL_INTRINSIC_1 INTRINSIC_LIST_TO_TUPLE] <-- optional
15191519 with:
15201520 LOAD_CONST (c1, c2, ... cN)
1521- When expected_append is true, the instruction at `i` is the LIST_TO_TUPLE
1522- intrinsic (so the immediately preceding non-NOP instruction is expected
1523- to be a LIST_APPEND), and only the BUILD_LIST/LIST_APPEND form is
1524- considered. When expected_append is false, the instruction at `i` is the
1525- trailing LIST_APPEND or SET_ADD itself, the matching BUILD_LIST/BUILD_SET
1526- start is selected from its opcode, and for sets the result is wrapped in
1527- a frozenset.
1521+ The instruction at `i` is either the LIST_TO_TUPLE intrinsic (so the
1522+ immediately preceding non-NOP instruction is expected to be a
1523+ LIST_APPEND, and only the BUILD_LIST/LIST_APPEND form is considered),
1524+ or the trailing LIST_APPEND or SET_ADD itself, in which case the
1525+ matching BUILD_LIST/BUILD_SET start is selected from its opcode, and
1526+ for sets the result is wrapped in a frozenset.
15281527*/
15291528static int
15301529fold_constant_seq_into_load_const (basicblock * bb , int i ,
1531- bool expected_append ,
15321530 PyObject * consts , PyObject * const_cache ,
15331531 _Py_hashtable_t * consts_index )
15341532{
@@ -1538,6 +1536,10 @@ fold_constant_seq_into_load_const(basicblock *bb, int i,
15381536 assert (i < bb -> b_iused );
15391537
15401538 cfg_instr * target = & bb -> b_instr [i ];
1539+ assert (target -> i_opcode == LIST_APPEND || target -> i_opcode == SET_ADD ||
1540+ (target -> i_opcode == CALL_INTRINSIC_1 &&
1541+ target -> i_oparg == INTRINSIC_LIST_TO_TUPLE ));
1542+ bool expected_append = target -> i_opcode == CALL_INTRINSIC_1 ;
15411543 int append_op = expected_append ? LIST_APPEND : target -> i_opcode ;
15421544 assert (append_op == LIST_APPEND || append_op == SET_ADD );
15431545 int build_op = append_op == LIST_APPEND ? BUILD_LIST : BUILD_SET ;
@@ -1618,17 +1620,6 @@ fold_constant_seq_into_load_const(basicblock *bb, int i,
16181620 return SUCCESS ;
16191621}
16201622
1621- static int
1622- fold_constant_intrinsic_list_to_tuple (basicblock * bb , int i ,
1623- PyObject * consts , PyObject * const_cache ,
1624- _Py_hashtable_t * consts_index )
1625- {
1626- assert (bb -> b_instr [i ].i_opcode == CALL_INTRINSIC_1 );
1627- assert (bb -> b_instr [i ].i_oparg == INTRINSIC_LIST_TO_TUPLE );
1628- return fold_constant_seq_into_load_const (bb , i , true,
1629- consts , const_cache , consts_index );
1630- }
1631-
16321623#define MIN_CONST_SEQUENCE_SIZE 3
16331624/*
16341625Optimize lists and sets for:
@@ -2543,7 +2534,7 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts,
25432534 INSTR_SET_OP0 (inst , NOP );
25442535 }
25452536 else {
2546- RETURN_IF_ERROR (fold_constant_intrinsic_list_to_tuple (bb , i , consts , const_cache , consts_index ));
2537+ RETURN_IF_ERROR (fold_constant_seq_into_load_const (bb , i , consts , const_cache , consts_index ));
25472538 }
25482539 }
25492540 else if (oparg == INTRINSIC_UNARY_POSITIVE ) {
@@ -2554,8 +2545,7 @@ optimize_basic_block(PyObject *const_cache, basicblock *bb, PyObject *consts,
25542545 case SET_ADD :
25552546 if (oparg == 1 && (nextop == GET_ITER || nextop == CONTAINS_OP )) {
25562547 RETURN_IF_ERROR (fold_constant_seq_into_load_const (
2557- bb , i , false,
2558- consts , const_cache , consts_index ));
2548+ bb , i , consts , const_cache , consts_index ));
25592549 }
25602550 break ;
25612551 case BINARY_OP :
0 commit comments