Skip to content

Commit cc4b9ce

Browse files
add pop_top
1 parent b4b2106 commit cc4b9ce

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Tools/cases_generator/optimizer_generator.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,18 @@ def replace_opcode_if_evaluates_pure(
233233
else:
234234
emitter.emit(f"{outp.name} = sym_new_const(ctx, PyStackRef_AsPyObjectBorrow({outp.name}_stackref));\n")
235235

236+
if len(used_stack_inputs) == 1 and len(self.original_uop.stack.outputs) == 1:
237+
outp = self.original_uop.stack.outputs[0]
238+
if not outp.peek:
239+
emitter.emit(f"""
240+
if (sym_is_const(ctx, {used_stack_inputs[0].name})) {{
241+
PyObject *result = sym_get_const(ctx, {used_stack_inputs[0].name});
242+
if (_Py_IsImmortal(result)) {{
243+
// Replace with _POP_LOAD_CONST_INLINE_BORROW since we have one input and an immortal result
244+
REPLACE_OP(this_instr, _POP_LOAD_CONST_INLINE_BORROW, 0, (uintptr_t)result);
245+
}}
246+
}}""")
247+
236248
if len(used_stack_inputs) == 2 and len(self.original_uop.stack.outputs) == 1:
237249
outp = self.original_uop.stack.outputs[0]
238250
if not outp.peek:

0 commit comments

Comments
 (0)