Skip to main content

peephole_fuse_load_imm_alu

Function peephole_fuse_load_imm_alu 

Source
pub fn peephole_fuse_load_imm_alu(
    code: &mut [u8],
    bitmask: &mut [u8],
    jump_table: &[u32],
) -> usize
Expand description

Peephole pass: fuse load_imm(51) + ThreeReg ALU into TwoRegOneImm immediate form.

Scans the PVM code for consecutive pairs where:

  1. First instruction is load_imm (opcode 51)
  2. Second instruction is a ThreeReg ALU op with an immediate-form equivalent
  3. The load destination register equals the ALU output register (dead after ALU)
  4. The load value fits in i32 (4-byte immediate)
  5. Neither instruction is a branch target

When fusable, rewrites the pair in-place: the first instruction becomes the TwoRegOneImm form with a 4-byte immediate, and all remaining bytes through the end of the second instruction become bitmask=0 continuation bytes.