This is a hopefully corrected version of:
bc886e9b587b
I thought the patch was obvious enough to not require pre-commit review the first time, but I made a copy-paste error that created an "add" instead of the intended "sub". The regression tests showed the bug, but I overlooked that too (embarrassing).
So this time, I'm posting for review in case someone (or bots) would like to apply the patch and confirm that the previous errors (there were several independent reports) are no longer there. As I said in a comment on issue #58717, the bug reports confirm that the pattern does occur in many real-world applications, so hopefully, eliminating the multiply results in better code.
I added one more regression test in this version of the patch, and here's an Alive2 proof to show that exact example:
https://alive2.llvm.org/ce/z/dge7VC
Original commit message:
This is a sibling to:
6064e92b0a84
...but we canonicalize the shl+add to shl+xor,
so the pattern is different than I expected:
https://alive2.llvm.org/ce/z/8CX16e
I have not found any patterns that are safe
to propagate no-wrap, so that is not included
here.