[PATCH] D89412: [TargetLowering] Replace Log2_32_Ceil with Log2_32 in SimplifySetCC ctpop combine.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 14 10:55:41 PDT 2020


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

This combine can look through (trunc (ctpop X)). When doing this
it tries to make sure the trunc doesn't lose any information
from the ctpop. It does this by checking that the truncated type
has more bits that Log2_32_Ceil of the ctpop type. The Ceil is
unnecessary and pessimizes non-power of 2 types.

For example, ctpop of i256 requires 9 bits to represent the max
value of 256. But ctpop of i255 only requires 8 bits to represent
the max result of 255. Log2_32_Ceil of 256 and 255 both return 8
while Log2_32 returns 8 for 256 and 7 for 255

The code with popcnt enabled is a regression for this test case,
but it does match what already happens with i256 truncated to i9.
Since power of 2 is more likely, I don't think it should block
this change.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D89412

Files:
  llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
  llvm/test/CodeGen/X86/ctpop-combine.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89412.298189.patch
Type: text/x-patch
Size: 5891 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201014/10a920c0/attachment.bin>


More information about the llvm-commits mailing list