[PATCH] D89346: [SelectionDAG][X86] Enable SimplifySetCC CTPOP transforms for vector splats

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 13 15:12:24 PDT 2020


craig.topper created this revision.
craig.topper added reviewers: spatel, RKSimon.
Herald added subscribers: pengfei, hiraditya.
Herald added a reviewer: ecnelises.
Herald added a project: LLVM.
craig.topper requested review of this revision.

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.

I moved the Log2_32 check for the truncate up to the if
that looks through the truncate as that seemed more obvious to me
than trying to determine if we looked through a truncate and then
checking the types. The original code used Log2_32_Ceil, but
Log2_32 is more correct for non power of 2 types.

Fixes or at least improves PR47825


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89346

Files:
  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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89346.297972.patch
Type: text/x-patch
Size: 301520 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201013/196bba52/attachment-0001.bin>


More information about the llvm-commits mailing list