diff options
author | Craig Topper <craig.topper@intel.com> | 2020-09-12 11:42:18 -0700 |
---|---|---|
committer | Craig Topper <craig.topper@intel.com> | 2020-09-12 11:42:18 -0700 |
commit | ad3d6f993d9f7ff3a54c5a716ccc918026fa0252 (patch) | |
tree | 9818de24cfdb626c61456c5763d6d1f16bf139b2 /llvm/lib/CodeGen/TargetLoweringBase.cpp | |
parent | d85ac6d577ac5d4a7812e6cd3b0171f5e356c805 (diff) | |
download | llvm-ad3d6f993d9f7ff3a54c5a716ccc918026fa0252.zip llvm-ad3d6f993d9f7ff3a54c5a716ccc918026fa0252.tar.gz llvm-ad3d6f993d9f7ff3a54c5a716ccc918026fa0252.tar.bz2 |
[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
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringBase.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringBase.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp index 958bb79..7ef37db 100644 --- a/llvm/lib/CodeGen/TargetLoweringBase.cpp +++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp @@ -692,6 +692,7 @@ void TargetLoweringBase::initActions() { setOperationAction(ISD::CTTZ_ZERO_UNDEF, VT, Expand); setOperationAction(ISD::BITREVERSE, VT, Expand); + setOperationAction(ISD::PARITY, VT, Expand); // These library functions default to expand. setOperationAction(ISD::FROUND, VT, Expand); |