Skip to content

Commit

Permalink
[X86] Don't use popcnt for parity if only bits 7:0 of the input can b…
Browse files Browse the repository at this point in the history
…e non-zero.

Without popcnt we had a special case for using the parity flag from a single test i8 test instruction if only bits 7:0 could be non-zero. That special case is still useful when we have popcnt.

To reach this special case, we enable custom lowering of parity for i16/i32/i64 even when popcnt is enabled. The check for POPCNT being enabled is now after the special case in LowerPARITY.

Fixes PR52093

Differential Revision: https://reviews.llvm.org/D111249
  • Loading branch information
topperc committed Oct 6, 2021
1 parent a4743eb commit 58b68e7
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 262 deletions.
13 changes: 8 additions & 5 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Expand Up @@ -425,6 +425,10 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
setTruncStoreAction(MVT::f128, MVT::f16, Expand);

setOperationAction(ISD::PARITY, MVT::i8, Custom);
setOperationAction(ISD::PARITY, MVT::i16, Custom);
setOperationAction(ISD::PARITY, MVT::i32, Custom);
if (Subtarget.is64Bit())
setOperationAction(ISD::PARITY, MVT::i64, Custom);
if (Subtarget.hasPOPCNT()) {
setOperationPromotedToType(ISD::CTPOP, MVT::i8, MVT::i32);
} else {
Expand All @@ -435,11 +439,6 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
setOperationAction(ISD::CTPOP , MVT::i64 , Expand);
else
setOperationAction(ISD::CTPOP , MVT::i64 , Custom);

setOperationAction(ISD::PARITY, MVT::i16, Custom);
setOperationAction(ISD::PARITY, MVT::i32, Custom);
if (Subtarget.is64Bit())
setOperationAction(ISD::PARITY, MVT::i64, Custom);
}

setOperationAction(ISD::READCYCLECOUNTER , MVT::i64 , Custom);
Expand Down Expand Up @@ -30469,6 +30468,10 @@ static SDValue LowerPARITY(SDValue Op, const X86Subtarget &Subtarget,
return DAG.getNode(ISD::ZERO_EXTEND, DL, VT, Setnp);
}

// If we have POPCNT, use the default expansion.
if (Subtarget.hasPOPCNT())
return SDValue();

if (VT == MVT::i64) {
// Xor the high and low 16-bits together using a 32-bit operation.
SDValue Hi = DAG.getNode(ISD::TRUNCATE, DL, MVT::i32,
Expand Down

0 comments on commit 58b68e7

Please sign in to comment.