summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2025-01-06 22:01:07 (GMT)
committerGitHub <noreply@github.com>2025-01-06 22:01:07 (GMT)
commit2434fd2d50b8b770585ad5949a664e4bbab4bde1 (patch)
tree8685e8f13c843ca527020363bc372259fa78d7f3 /Python
parentb6c919b674549d519efbbc378588ca6d3efc7242 (diff)
downloadcpython-2434fd2d50b8b770585ad5949a664e4bbab4bde1.zip
cpython-2434fd2d50b8b770585ad5949a664e4bbab4bde1.tar.gz
cpython-2434fd2d50b8b770585ad5949a664e4bbab4bde1.tar.bz2
GH-128533: Add `NOT_TAKEN` instruction after bytecode optimization. (GH-128554)
Diffstat (limited to 'Python')
-rw-r--r--Python/codegen.c8
-rw-r--r--Python/flowgraph.c9
2 files changed, 4 insertions, 13 deletions
diff --git a/Python/codegen.c b/Python/codegen.c
index 14f9f5a..61707ba 100644
--- a/Python/codegen.c
+++ b/Python/codegen.c
@@ -406,13 +406,7 @@ codegen_addop_j(instr_sequence *seq, location loc,
assert(IS_JUMP_TARGET_LABEL(target));
assert(OPCODE_HAS_JUMP(opcode) || IS_BLOCK_PUSH_OPCODE(opcode));
assert(!IS_ASSEMBLER_OPCODE(opcode));
- if (_PyInstructionSequence_Addop(seq, opcode, target.id, loc) != SUCCESS) {
- return ERROR;
- }
- if (IS_CONDITIONAL_JUMP_OPCODE(opcode)) {
- return _PyInstructionSequence_Addop(seq, NOT_TAKEN, 0, NO_LOCATION);
- }
- return SUCCESS;
+ return _PyInstructionSequence_Addop(seq, opcode, target.id, loc);
}
#define ADDOP_JUMP(C, LOC, OP, O) \
diff --git a/Python/flowgraph.c b/Python/flowgraph.c
index 64df629..017216a 100644
--- a/Python/flowgraph.c
+++ b/Python/flowgraph.c
@@ -522,14 +522,15 @@ no_redundant_jumps(cfg_builder *g) {
static int
normalize_jumps_in_block(cfg_builder *g, basicblock *b) {
cfg_instr *last = basicblock_last_instr(b);
- if (last == NULL || !is_jump(last) ||
- IS_UNCONDITIONAL_JUMP_OPCODE(last->i_opcode)) {
+ if (last == NULL || !IS_CONDITIONAL_JUMP_OPCODE(last->i_opcode)) {
return SUCCESS;
}
assert(!IS_ASSEMBLER_OPCODE(last->i_opcode));
bool is_forward = last->i_target->b_visited == 0;
if (is_forward) {
+ RETURN_IF_ERROR(
+ basicblock_addop(b, NOT_TAKEN, 0, last->i_loc));
return SUCCESS;
}
@@ -557,10 +558,6 @@ normalize_jumps_in_block(cfg_builder *g, basicblock *b) {
if (backwards_jump == NULL) {
return ERROR;
}
- assert(b->b_next->b_iused > 0);
- assert(b->b_next->b_instr[0].i_opcode == NOT_TAKEN);
- b->b_next->b_instr[0].i_opcode = NOP;
- b->b_next->b_instr[0].i_loc = NO_LOCATION;
RETURN_IF_ERROR(
basicblock_addop(backwards_jump, NOT_TAKEN, 0, last->i_loc));
RETURN_IF_ERROR(