[SDAG] fold sub-of-shift to add-of-shift
authorSanjay Patel <spatel@rotateright.com>
Fri, 18 Feb 2022 16:43:03 +0000 (11:43 -0500)
committerSanjay Patel <spatel@rotateright.com>
Fri, 18 Feb 2022 16:55:50 +0000 (11:55 -0500)
commita2963d871ee5c2786de409b42f67ffcc39e53184
tree65855c38ce23a8d39402833e192354ffc8ab32ca
parentbf296ea6bbb13177dea9e5a72c3e446d5c5a1d81
[SDAG] fold sub-of-shift to add-of-shift

This fold is done in IR:
https://alive2.llvm.org/ce/z/jWyFrP

There is an x86 test that shows an improvement
from the added flexibility of using add (commutative).

The other diffs are presumed neutral.

Note that this could also be folded to an 'xor',
but I'm not sure if that would be universally better
(eg, x86 can convert adds more easily into LEA).

This helps prevent regressions from a potential fold for
issue #53829.
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/AArch64/srem-seteq-vec-splat.ll
llvm/test/CodeGen/X86/combine-srem.ll
llvm/test/CodeGen/X86/imul.ll
llvm/test/CodeGen/X86/srem-seteq-vec-splat.ll