Skip to content

Commit a3060f0

Browse files
committed
[X86] combineConcatVectorOps - concatenate AVX512 vselect nodes. NFC.
This also requires us to constant fold vXi1 concat_vector nodes
1 parent 4a96893 commit a3060f0

File tree

6 files changed

+2042
-2219
lines changed

6 files changed

+2042
-2219
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55774,6 +55774,22 @@ static SDValue combineConcatVectorOps(const SDLoc &DL, MVT VT,
5577455774
}
5577555775
break;
5577655776
case ISD::VSELECT:
55777+
if (!IsSplat && Subtarget.hasAVX512() &&
55778+
(VT.is256BitVector() ||
55779+
(VT.is512BitVector() && Subtarget.useAVX512Regs())) &&
55780+
(EltSizeInBits >= 32 || Subtarget.hasBWI())) {
55781+
EVT SelVT = Ops[0].getOperand(0).getValueType();
55782+
if (SelVT.getVectorElementType() == MVT::i1) {
55783+
SelVT = EVT::getVectorVT(*DAG.getContext(), MVT::i1,
55784+
Ops.size() * SelVT.getVectorNumElements());
55785+
if (DAG.getTargetLoweringInfo().isTypeLegal(SelVT))
55786+
return DAG.getNode(Op0.getOpcode(), DL, VT,
55787+
ConcatSubOperand(SelVT.getSimpleVT(), Ops, 0),
55788+
ConcatSubOperand(VT, Ops, 1),
55789+
ConcatSubOperand(VT, Ops, 2));
55790+
}
55791+
}
55792+
[[fallthrough]];
5577755793
case X86ISD::BLENDV:
5577855794
if (!IsSplat && VT.is256BitVector() && Ops.size() == 2 &&
5577955795
(EltSizeInBits >= 32 || Subtarget.hasInt256()) &&
@@ -55830,13 +55846,28 @@ static SDValue combineCONCAT_VECTORS(SDNode *N, SelectionDAG &DAG,
5583055846
EVT VT = N->getValueType(0);
5583155847
EVT SrcVT = N->getOperand(0).getValueType();
5583255848
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
55849+
SmallVector<SDValue, 4> Ops(N->op_begin(), N->op_end());
5583355850

55834-
// Don't do anything for i1 vectors.
55835-
if (VT.getVectorElementType() == MVT::i1)
55851+
if (VT.getVectorElementType() == MVT::i1) {
55852+
// Attempt to constant fold.
55853+
unsigned SubSizeInBits = SrcVT.getSizeInBits();
55854+
APInt Constant = APInt::getZero(VT.getSizeInBits());
55855+
for (unsigned I = 0, E = Ops.size(); I != E; ++I) {
55856+
auto *C = dyn_cast<ConstantSDNode>(peekThroughBitcasts(Ops[I]));
55857+
if (!C) break;
55858+
Constant.insertBits(C->getAPIntValue(), I * SubSizeInBits);
55859+
if (I == (E - 1)) {
55860+
EVT IntVT = EVT::getIntegerVT(*DAG.getContext(), VT.getSizeInBits());
55861+
if (TLI.isTypeLegal(IntVT))
55862+
return DAG.getBitcast(VT, DAG.getConstant(Constant, SDLoc(N), IntVT));
55863+
}
55864+
}
55865+
55866+
// Don't do anything else for i1 vectors.
5583655867
return SDValue();
55868+
}
5583755869

5583855870
if (Subtarget.hasAVX() && TLI.isTypeLegal(VT) && TLI.isTypeLegal(SrcVT)) {
55839-
SmallVector<SDValue, 4> Ops(N->op_begin(), N->op_end());
5584055871
if (SDValue R = combineConcatVectorOps(SDLoc(N), VT.getSimpleVT(), Ops, DAG,
5584155872
DCI, Subtarget))
5584255873
return R;

0 commit comments

Comments
 (0)