totalspectrum/spin2cpp

New optimization is buggy

Closed this issue · 2 comments

Optimization introduced in 72c5cb9 is bugged:

  • InstrSetsAnyFlags is only checked on the first instruction. Some merges are actually incorrect if the second instruction sets C (shifts are correct, but only on P2 and if the second shift amount is not zero. Logic ops are always correct like that, add/sub never).
  • I'm pretty sure most of these instructions are handled elsewhere but better and having two pieces of code touching them just causes debugging headaches.

Aargh, thanks for catching that; I also missed a check for volatile instructions. There is already code that handles this for the add/sub cases, and I guess we could comment those out, but I did want the shl/shr cases handled because they come up sometimes in code that handles bytes and shorts.

Removed the redundant add/sub optimizations.