Skip to content

Commit 58b68e7

Browse files
committed
[X86] Don't use popcnt for parity if only bits 7:0 of the input can be 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
1 parent a4743eb commit 58b68e7

File tree

2 files changed

+126
-262
lines changed

2 files changed

+126
-262
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,10 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
425425
setTruncStoreAction(MVT::f128, MVT::f16, Expand);
426426

427427
setOperationAction(ISD::PARITY, MVT::i8, Custom);
428+
setOperationAction(ISD::PARITY, MVT::i16, Custom);
429+
setOperationAction(ISD::PARITY, MVT::i32, Custom);
430+
if (Subtarget.is64Bit())
431+
setOperationAction(ISD::PARITY, MVT::i64, Custom);
428432
if (Subtarget.hasPOPCNT()) {
429433
setOperationPromotedToType(ISD::CTPOP, MVT::i8, MVT::i32);
430434
} else {
@@ -435,11 +439,6 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
435439
setOperationAction(ISD::CTPOP , MVT::i64 , Expand);
436440
else
437441
setOperationAction(ISD::CTPOP , MVT::i64 , Custom);
438-
439-
setOperationAction(ISD::PARITY, MVT::i16, Custom);
440-
setOperationAction(ISD::PARITY, MVT::i32, Custom);
441-
if (Subtarget.is64Bit())
442-
setOperationAction(ISD::PARITY, MVT::i64, Custom);
443442
}
444443

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

30471+
// If we have POPCNT, use the default expansion.
30472+
if (Subtarget.hasPOPCNT())
30473+
return SDValue();
30474+
3047230475
if (VT == MVT::i64) {
3047330476
// Xor the high and low 16-bits together using a 32-bit operation.
3047430477
SDValue Hi = DAG.getNode(ISD::TRUNCATE, DL, MVT::i32,

0 commit comments

Comments
 (0)