[PATCH] D87209: [SelectionDAG][X86][ARM][AArch64] Add ISD opcode for __builtin_parity. Expand it to shifts and xors.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 6 12:26:50 PDT 2020


craig.topper created this revision.
craig.topper added reviewers: spatel, RKSimon, efriedma, lebedev.ri.
Herald added subscribers: danielkiss, ecnelises, hiraditya, kristof.beyls.
Herald added a project: LLVM.
craig.topper requested review of this revision.

Clang emits (and (ctpop X), 1) for __builtin_parity. If ctpop
isn't natively supported by the target, this leads to poor codegen
due to the expansion of ctpop being more complex than what is needed
for parity.

This adds a DAG combine to convert the pattern to ISD::PARITY of
CTPOP is not supported for this type. Type legalization is updated
to handled Expanding and Promoting this operation. If after type
legalization, CTPOP is supported for this type, LegalizeDAG will
turn it back into CTPOP+AND. Otherwise LegalizeDAG will emit a
series of shifts and xors followed by an AND with 1.

I've avoided vectors in this patch to avoid more legalization
complexity for this patch.

X86 previously had a custom DAG combiner for this. This is now
moved to Custom lowering for the new opcode. There is a minor
regression in vector-reduce-xor-bool.ll, but a follow up patch
can easily fix that.

Fixes PR47433


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87209

Files:
  llvm/include/llvm/CodeGen/ISDOpcodes.h
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
  llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
  llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
  llvm/lib/CodeGen/TargetLoweringBase.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/test/CodeGen/AArch64/parity.ll
  llvm/test/CodeGen/ARM/parity.ll
  llvm/test/CodeGen/X86/parity.ll
  llvm/test/CodeGen/X86/vector-reduce-xor-bool.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D87209.290149.patch
Type: text/x-patch
Size: 32170 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200906/c9fea501/attachment.bin>


More information about the llvm-commits mailing list