[DAGCombiner] try to form test+set out of shift+mask patterns
authorSanjay Patel <spatel@rotateright.com>
Mon, 2 Sep 2019 14:52:09 +0000 (14:52 +0000)
committerSanjay Patel <spatel@rotateright.com>
Mon, 2 Sep 2019 14:52:09 +0000 (14:52 +0000)
commit1324c4c450f2748ff8ca42955724e5e523f4528e
tree2008eaec0370bd2ba8b6aab4e8c26ce8d38b8d66
parent35b459907622bd1f2e84c8580913afe2b22a3779
[DAGCombiner] try to form test+set out of shift+mask patterns

The motivating bugs are:
https://bugs.llvm.org/show_bug.cgi?id=41340
https://bugs.llvm.org/show_bug.cgi?id=42697

As discussed there, we could view this as a failure of IR canonicalization,
but then we would need to implement a backend fixup with target overrides
to get this right in all cases. Instead, we can just view this as a codegen
opportunity. It's not even clear for x86 exactly when we should favor
test+set; some CPUs have better theoretical throughput for the ALU ops than
bt/test.

This patch is made more complicated than I expected because there's an early
DAGCombine for 'and' that can change types of the intermediate ops via
trunc+anyext.

Differential Revision: https://reviews.llvm.org/D66687

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@370668 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
test/CodeGen/Hexagon/tstbit.ll
test/CodeGen/X86/test-vs-bittest.ll