[all-commits] [llvm/llvm-project] ad3d6f: [SelectionDAG][X86][ARM][AArch64] Add ISD opcode f...

topperc via All-commits all-commits at lists.llvm.org
Sat Sep 12 11:43:26 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: ad3d6f993d9f7ff3a54c5a716ccc918026fa0252
      https://github.com/llvm/llvm-project/commit/ad3d6f993d9f7ff3a54c5a716ccc918026fa0252
  Author: Craig Topper <craig.topper at intel.com>
  Date:   2020-09-12 (Sat, 12 Sep 2020)

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

  Log Message:
  -----------
  [SelectionDAG][X86][ARM][AArch64] Add ISD opcode for __builtin_parity. Expand it to shifts and xors.

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
before operation legalization. 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

Reviewed By: efriedma

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




More information about the All-commits mailing list