[DAGCombiner] make matching bit-hack form of usubsat more flexible
authorSanjay Patel <spatel@rotateright.com>
Mon, 25 Oct 2021 12:57:10 +0000 (08:57 -0400)
committerSanjay Patel <spatel@rotateright.com>
Mon, 25 Oct 2021 13:01:52 +0000 (09:01 -0400)
commit6e46b66e2aa7ccfc65d26d1a640e0365a2bdae02
treead4b93a0ad0622a0610eee8d5685b2a91804b07f
parentf9089accbac128213542703256e65ec64cba17d1
[DAGCombiner] make matching bit-hack form of usubsat more flexible

(i8 X ^ 128) & (i8 X s>> 7) --> usubsat X, 128

As suggested in D112085, we can substitute 'xor' with 'add'
in this pattern, and it is logically equivalent:
https://alive2.llvm.org/ce/z/eJtWWC

We canonicalize to 'xor' in IR, but SDAG does not do that
(and it probably should not - https://llvm.org/PR52267 ), so
it is possible to see either pattern in codegen. Note that
'sub' is a another potential pattern, but that is
canonicalized to 'add' in DAGCombiner, so we don't need to
worry about that variation.

Differential Revision: https://reviews.llvm.org/D112377
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/AMDGPU/usubsat.ll
llvm/test/CodeGen/X86/psubus.ll