Fix rotate optimization zero case bug

It is not possible to replace two shifts with a rotate when the shift
distance is zero and the operation is ADD/XOR.

This problem was previously spotted and partially fixed in:
148894a4519be445789f43c4e27fc0a8e9e72700. That patch fixed the negation
pattern however it missed the sub pattern which still failed when the
shift distance was zero. In order to ensure this doesn't get missed
again, the structure has been refactored to ensure the shift distance
is always checked.

This patch therefore applies the same fix to the sub pattern that was
applied to the neg pattern. It also adds a check for the constant
pattern although in this case we expect that the shift will have been
optimized away earlier in the pass.

Also fix a limitation that only the sub pattern would be tried even if
the neg pattern could be applied in the case of mixed instructions. Now
always try to apply both patterns until a match is found.

Test: 557-checker-instruct-simplifier-ror
Cherrypick-From: https://partner-android-review.googlesource.com/q/commit:9685d95058da8d9c51223910eb541a6c27c33ed2
Flag: NONE Partner contribution
Change-Id: I350433a060607158aa8624179e228295f88ecab3
2 files changed