Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11582,11 +11582,13 @@ SDValue TargetLowering::expandVECTOR_COMPRESS(SDNode *Node,
// ... if it is not a splat vector, we need to get the passthru value at
// position = popcount(mask) and re-load it from the stack before it is
// overwritten in the loop below.
EVT PopcountVT = ScalarVT.changeTypeToInteger();
SDValue Popcount = DAG.getNode(
ISD::TRUNCATE, DL, MaskVT.changeVectorElementType(MVT::i1), Mask);
Popcount = DAG.getNode(ISD::ZERO_EXTEND, DL,
MaskVT.changeVectorElementType(ScalarVT), Popcount);
Popcount = DAG.getNode(ISD::VECREDUCE_ADD, DL, ScalarVT, Popcount);
Popcount =
DAG.getNode(ISD::ZERO_EXTEND, DL,
MaskVT.changeVectorElementType(PopcountVT), Popcount);
Popcount = DAG.getNode(ISD::VECREDUCE_ADD, DL, PopcountVT, Popcount);
SDValue LastElmtPtr =
getVectorElementPointer(DAG, StackPtr, VecVT, Popcount);
LastWriteVal = DAG.getLoad(
Expand Down Expand Up @@ -11625,8 +11627,10 @@ SDValue TargetLowering::expandVECTOR_COMPRESS(SDNode *Node,

// Re-write the last ValI if all lanes were selected. Otherwise,
// overwrite the last write it with the passthru value.
LastWriteVal =
DAG.getSelect(DL, ScalarVT, AllLanesSelected, ValI, LastWriteVal);
SDNodeFlags Flags{};
Flags.setUnpredictable(true);
LastWriteVal = DAG.getSelect(DL, ScalarVT, AllLanesSelected, ValI,
LastWriteVal, Flags);
Chain = DAG.getStore(
Chain, DL, LastWriteVal, OutPtr,
MachinePointerInfo::getUnknownStack(DAG.getMachineFunction()));
Expand Down
23 changes: 23 additions & 0 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2321,6 +2321,29 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
}
}

// vpcompress depends on various AVX512 extensions.
if (Subtarget.hasAVX512()) {
// Legal in AVX512F
for (MVT VT : {MVT::v16i32, MVT::v16f32, MVT::v8i64, MVT::v8f64})
setOperationAction(ISD::VECTOR_COMPRESS, VT, Legal);

// Legal in AVX512F + AVX512VL
if (Subtarget.hasVLX())
for (MVT VT : {MVT::v8i32, MVT::v8f32, MVT::v4i32, MVT::v4f32, MVT::v4i64,
MVT::v4f64, MVT::v2i64, MVT::v2f64})
setOperationAction(ISD::VECTOR_COMPRESS, VT, Legal);

// Legal in AVX512F + AVX512VBMI2
if (Subtarget.hasVBMI2())
for (MVT VT : {MVT::v32i16, MVT::v64i8})
setOperationAction(ISD::VECTOR_COMPRESS, VT, Legal);

// Legal in AVX512F + AVX512VL + AVX512VBMI2
if (Subtarget.hasVBMI2() && Subtarget.hasVLX())
for (MVT VT : {MVT::v16i8, MVT::v8i16, MVT::v32i8, MVT::v16i16})
setOperationAction(ISD::VECTOR_COMPRESS, VT, Legal);
}

if (!Subtarget.useSoftFloat() &&
(Subtarget.hasAVXNECONVERT() || Subtarget.hasBF16())) {
addRegisterClass(MVT::v8bf16, Subtarget.hasAVX512() ? &X86::VR128XRegClass
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Target/X86/X86InstrAVX512.td
Original file line number Diff line number Diff line change
Expand Up @@ -10543,6 +10543,12 @@ multiclass compress_by_vec_width_lowering<X86VectorVTInfo _, string Name> {
def : Pat<(X86compress (_.VT _.RC:$src), _.ImmAllZerosV, _.KRCWM:$mask),
(!cast<Instruction>(Name#_.ZSuffix#rrkz)
_.KRCWM:$mask, _.RC:$src)>;
def : Pat<(_.VT (vector_compress _.RC:$src, _.KRCWM:$mask, undef)),
(!cast<Instruction>(Name#_.ZSuffix#rrkz)
_.KRCWM:$mask, _.RC:$src)>;
def : Pat<(_.VT (vector_compress _.RC:$src, _.KRCWM:$mask, _.RC:$passthru)),
(!cast<Instruction>(Name#_.ZSuffix#rrk)
_.RC:$passthru, _.KRCWM:$mask, _.RC:$src)>;
}

multiclass compress_by_elt_width<bits<8> opc, string OpcodeStr,
Expand Down
Loading