Skip to content

Expand peephole pass has matched two pattern but diff instruction list #917

@wangnianwu

Description

@wangnianwu

pseudo code

I have two pattern rules like this.

  • First case
    I need to remove the instruction 'iget-wide '
iput-wide v1, v0, Lcom/example/myapplication/ui/home/Peephole;->put_wide_value:J
iget-wide v1, v0, Lcom/example/myapplication/ui/home/Peephole;->put_wide_value:J 
return-void

Pattern A:

iput_field(Register::A, Register::B, reference)
iget_field(Register::A, Register::B, reference)
  • Second case
    I need to replace the second instruction 'iget-wide ' to 'move v2, v1'
iput-wide v1, v0, Lcom/example/myapplication/ui/home/Peephole;->put_wide_value:J
iget-wide v2, v0, Lcom/example/myapplication/ui/home/Peephole;->put_wide_value:J 
return-void

Pattern B:

iput_field(Register::A, Register::B, reference)
iget_field(Register::C, Register::B, reference)

Problem

The instruction list at this:

iput-wide v1, v0, Lcom/example/myapplication/ui/home/Peephole;->put_wide_value:J
iget-wide v2, v0, Lcom/example/myapplication/ui/home/Peephole;->put_wide_value:J 
return-void

has been matched by the pattern A and B.

Analyze

From redex source code at try_match method in peephole pass

    auto match_reg = [&](Register pattern_reg, reg_t insn_reg) {
      // This register has been observed already. Check whether they are same.
      if (matched_regs.find(pattern_reg) != end(matched_regs)) {
        return matched_regs.at(pattern_reg) == insn_reg;
      }

      // Newly observed. Remember it.
      matched_regs.emplace(pattern_reg, insn_reg);
      return true;
    };

The pattern_reg and insn_reg is not one to one. The insn_reg can set to multi Register value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions