Skip to content

x86: CMP/MOV refactoring and expansion

This merge request refactors the SwapMovCmp routine, and calls to it, to be more self-contained, having the preliminary checks built-in to ensure that moving the MOV instruction is actually a sound idea, while also making it more general-purpose so it can handle instructions that are not MOV operations. This feature is primarily for future expansion, but also cleans up the code for the x86 peephole optimizer.

Criteria

Confirm correct compilation and no test regressions, especially with !59 (merged).

Notes

  • No changes in RTL reported under -O4.
  • Compiler may run very slightly slower due to SwapMovCmp being more complicated, since it no longer assumes the second instruction is a MOV operation and does deeper analysis of what's being modified.
  • Though the bug doesn't appear to have been ever triggered, there was a possibility of a MOV instruction writing to a memory location being relocated to before the CMP instruction that also checked against the same memory location. This has now been rectified as operands are now directly compared with MatchOperand calls, thereby catching both identical registers and references.

Merge request reports