This changes the first part of optimizeCompareInstr being split into a loop with a forward scan for cases that re-use zero flags from a producer in case of compare with zero and a backward scan for finding an instruction equivalent to a compare.
The code now uses a single backward scan searching for the next instructions that reads or writes EFLAGS.
Also:
- Add comments giving examples for the 3 cases handled.
- Check MI which contains the result of the zero-compare cases, instead of re-checking IsCmpZero.
- Tweak coding style in some loops.
- Add new MIR based tests that test the optimization in isolation.
This also removes a check for flag readers in situations like this:
= SUB32rr %0, %1, implicit-def $eflags ... we no longer stop when there are $eflag users here CMP32rr %0, %1 ; will be removed ...