[SelectionDAG][X86] Enable SimplifySetCC CTPOP transforms for vector splats
authorCraig Topper <craig.topper@gmail.com>
Mon, 19 Oct 2020 19:03:04 +0000 (12:03 -0700)
committerCraig Topper <craig.topper@gmail.com>
Mon, 19 Oct 2020 19:56:59 +0000 (12:56 -0700)
commitedd0cb11bd182de8d70b7bbeba73f88d7a3714db
tree4fb4107c049c81484e2fd92ee1995d953ba4dfa2
parente28376ec28b9034a35e01c95ccb4de9ccc6c4954
[SelectionDAG][X86] Enable SimplifySetCC CTPOP transforms for vector splats

This enables these transforms for vectors:
(ctpop x) u< 2 -> (x & x-1) == 0
(ctpop x) u> 1 -> (x & x-1) != 0
(ctpop x) == 1 --> (x != 0) && ((x & x-1) == 0)
(ctpop x) != 1 --> (x == 0) || ((x & x-1) != 0)

All enabled if CTPOP isn't Legal. This differs from the scalar
behavior where the first two are done unconditionally and the
last two are done if CTPOP isn't Legal or Custom. The Legal
check produced better results for vectors based on X86's
custom handling. Might be worth re-visiting scalars here.

I disabled the looking through truncate for vectors. The
code that creates new setcc can use the same result VT as the
original setcc even if we truncated the input. That may work
work for most scalars, but definitely wouldn't work for vectors
unless it was a vector of i1.

Fixes or at least improves PR47825

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D89346
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/test/CodeGen/X86/vector-popcnt-128.ll
llvm/test/CodeGen/X86/vector-popcnt-256.ll
llvm/test/CodeGen/X86/vector-popcnt-512.ll