Skip to content

Commit 1ab2d3b

Browse files
DinoVfacebook-github-bot
authored andcommitted
LOAD_GLOBAL opt
Summary: 3.14 can avoid a `PUSH_NULL` for `LOAD_GLOBAL` by setting a flag on the `LOAD_GLOBAL` instruction Reviewed By: martindemello Differential Revision: D80764208 fbshipit-source-id: 809e25ffa66e87440640a707c91884ee2f11f596
1 parent 30d1e9f commit 1ab2d3b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cinderx/PythonLib/cinderx/compiler/flow_graph_optimizer.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,19 @@ def optimize_compare_op(
909909
instr.ioparg |= 16
910910
next_instr.set_to_nop()
911911

912+
def optimize_load_global(
913+
self: FlowGraphOptimizer,
914+
instr_index: int,
915+
instr: Instruction,
916+
next_instr: Instruction | None,
917+
target: Instruction | None,
918+
block: Block,
919+
) -> int | None:
920+
if next_instr is not None and next_instr.opname == "PUSH_NULL":
921+
instr.oparg = (instr.oparg, 1)
922+
instr.ioparg |= 1
923+
next_instr.set_to_nop()
924+
912925
handlers: dict[str, Handler] = {
913926
**FlowGraphOptimizer312.handlers,
914927
"LOAD_CONST": opt_load_const,
@@ -917,4 +930,6 @@ def optimize_compare_op(
917930
"BUILD_LIST": optimize_lists_and_sets,
918931
"BUILD_SET": optimize_lists_and_sets,
919932
"COMPARE_OP": optimize_compare_op,
933+
"LOAD_GLOBAL": optimize_load_global,
920934
}
935+
del handlers["PUSH_NULL"]

0 commit comments

Comments
 (0)