1 hour ago · Tech · hide · 0 comments

After reading Chris Fallin’s aegraph post, new ZJIT contributor dak2 landed a block-local version of the canonicalize function in #16828. The pseudocode of the block-local canonicalize function looks like this: for block in function.reverse_post_order(): rewrite_map = {} for insn in block.insns: insn.operands.map_in_place(lambda o: rewrite_map.get(o, o)) if insn.opcode == "GuardType": rewrite_map[insn.val] = insn As a refresher, this turns IR like this: v0:Object = ... v1:Int = GuardType v0, Int ... do something with v1 v2:Int = GuardType v0, Int ... do something with v2 into this: v0:Object = ... v1:Int = GuardType v0, Int ... do something with v1 v2:Int = GuardType v1, Int ... do something with v2 Note that the second use of v0 has been turned into v1. This is important because a later constant-folding pass can observe that the input v1 of GuardType v1, Int is already an Int and can therefore replace all uses of v2 with v1 and delete the guard. Because in this local version we make…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.