@@ -1522,9 +1522,32 @@ fold_constant_intrinsic_list_to_tuple(basicblock *bb, int i,
15221522
15231523 if (opcode == BUILD_LIST && oparg == 0 ) {
15241524 if (!expect_append ) {
1525+ /* Not a sequence start. */
15251526 return SUCCESS ;
15261527 }
1527- goto start_found ;
1528+
1529+ /* Sequence start, we are done. */
1530+ PyObject * newconst = PyTuple_New ((Py_ssize_t )consts_found );
1531+ if (newconst == NULL ) {
1532+ return ERROR ;
1533+ }
1534+
1535+ int nops = consts_found * 2 + 1 ;
1536+ for (pos = i - 1 ; pos >= 0 && consts_found > 0 ; pos -- ) {
1537+ instr = & bb -> b_instr [pos ];
1538+ if (loads_const (instr -> i_opcode )) {
1539+ PyObject * constant = get_const_value (instr -> i_opcode , instr -> i_oparg , consts );
1540+ if (constant == NULL ) {
1541+ Py_DECREF (newconst );
1542+ return ERROR ;
1543+ }
1544+ PyTuple_SET_ITEM (newconst , -- consts_found , constant );
1545+ }
1546+ }
1547+
1548+ assert (consts_found == 0 );
1549+ nop_out (bb , i - 1 , nops );
1550+ return instr_make_load_const (intrinsic , newconst , consts , const_cache );
15281551 }
15291552
15301553 if (expect_append ) {
@@ -1544,29 +1567,6 @@ fold_constant_intrinsic_list_to_tuple(basicblock *bb, int i,
15441567
15451568 /* Did not find sequence start. */
15461569 return SUCCESS ;
1547-
1548- start_found :;
1549- PyObject * newconst = PyTuple_New ((Py_ssize_t )consts_found );
1550- if (newconst == NULL ) {
1551- return ERROR ;
1552- }
1553-
1554- int nops = consts_found * 2 + 1 ;
1555- for (int pos = i - 1 ; pos >= 0 && consts_found > 0 ; pos -- ) {
1556- cfg_instr * instr = & bb -> b_instr [pos ];
1557- if (loads_const (instr -> i_opcode )) {
1558- PyObject * constant = get_const_value (instr -> i_opcode , instr -> i_oparg , consts );
1559- if (constant == NULL ) {
1560- Py_DECREF (newconst );
1561- return ERROR ;
1562- }
1563- PyTuple_SET_ITEM (newconst , -- consts_found , constant );
1564- }
1565- }
1566-
1567- assert (consts_found == 0 );
1568- nop_out (bb , i - 1 , nops );
1569- return instr_make_load_const (intrinsic , newconst , consts , const_cache );
15701570}
15711571
15721572#define MIN_CONST_SEQUENCE_SIZE 3
0 commit comments