Skip to content

Commit 25797cf

Browse files
committed
optimize code struct
1 parent 4a0db15 commit 25797cf

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

Python/optimizer_analysis.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ optimize_uops(
418418
}
419419
#endif
420420

421-
int out_len_before = ctx->tracer->out_len;
422421
switch (opcode) {
423422

424423
#include "optimizer_cases.c.h"
@@ -428,7 +427,7 @@ optimize_uops(
428427
Py_UNREACHABLE();
429428
}
430429
// If no ADD_OP was called during this iteration, copy the original instruction
431-
if (ctx->tracer->out_len == out_len_before) {
430+
if (ctx->tracer->out_len == i) {
432431
ctx->tracer->out_buffer[ctx->tracer->out_len++] = *this_instr;
433432
}
434433
assert(ctx->frame != NULL);
@@ -461,8 +460,15 @@ optimize_uops(
461460
_Py_uop_abstractcontext_fini(ctx);
462461
// Check that the trace ends with a proper terminator
463462
if (ctx->tracer->out_len > 0) {
464-
if (!is_terminator_uop(&ctx->tracer->out_buffer[ctx->tracer->out_len - 1])) {
465-
return 0;
463+
_PyUOpInstruction *last_uop = &ctx->tracer->out_buffer[ctx->tracer->out_len - 1];
464+
if (!is_terminator_uop(last_uop)) {
465+
// Copy remaining uops from original trace until we find a terminator
466+
for (int i = ctx->tracer->out_len; i < trace_len; i++) {
467+
ctx->tracer->out_buffer[ctx->tracer->out_len++] = trace[i];
468+
if (is_terminator_uop(&trace[i])) {
469+
break;
470+
}
471+
}
466472
}
467473
}
468474

0 commit comments

Comments
 (0)