llvm.org GIT mirror llvm / f726aa1
[X86][DAGCombiner] Teach narrowShuffle to use concat_vectors instead of inserting into undef Summary: Concat_vectors is more canonical during early DAG combine. For example, its what's used by SelectionDAGBuilder when converting IR shuffles into SelectionDAG shuffles when element counts between inputs and mask don't match. We also have combines in DAGCombiner than can pull concat_vectors through a shuffle. See partitionShuffleOfConcats. So it seems like concat_vectors is a better operation to use here. I had to teach DAGCombiner's SimplifyVBinOp to also handle concat_vectors with undef. I haven't checked yet if we can remove the INSERT_SUBVECTOR version in there or not. I didn't want to mess with the other caller of getShuffleHalfVectors that's used during shuffle lowering where insert_subvector probably is what we want to produce so I've enabled this via a boolean passed to the function. Reviewers: spatel, RKSimon Reviewed By: RKSimon Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66504 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369872 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 27 days ago
2 changed file(s) with 41 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
1953619536 }
1953719537 }
1953819538
19539 // Make sure all but the first op are undef.
19540 auto ConcatWithUndef = [](SDValue Concat) {
19541 return Concat.getOpcode() == ISD::CONCAT_VECTORS &&
19542 std::all_of(std::next(Concat->op_begin()), Concat->op_end(),
19543 [](const SDValue &Op) {
19544 return Op.isUndef();
19545 });
19546 };
19547
19548 // The following pattern is likely to emerge with vector reduction ops. Moving
19549 // the binary operation ahead of the concat may allow using a narrower vector
19550 // instruction that has better performance than the wide version of the op:
19551 // VBinOp (concat X, undef), (concat Y, undef) --> concat (VBinOp X, Y), VecC
19552 if (ConcatWithUndef(LHS) && ConcatWithUndef(RHS) &&
19553 (LHS.hasOneUse() || RHS.hasOneUse())) {
19554 SDValue X = LHS.getOperand(0);
19555 SDValue Y = RHS.getOperand(0);
19556 EVT NarrowVT = X.getValueType();
19557 if (NarrowVT == Y.getValueType() &&
19558 TLI.isOperationLegalOrCustomOrPromote(Opcode, NarrowVT)) {
19559 // (binop undef, undef) may not return undef, so compute that result.
19560 SDLoc DL(N);
19561 SDValue VecC =
19562 DAG.getNode(Opcode, DL, NarrowVT, DAG.getUNDEF(NarrowVT),
19563 DAG.getUNDEF(NarrowVT));
19564 SmallVector Ops(LHS.getNumOperands(), VecC);
19565 Ops[0] = DAG.getNode(Opcode, DL, NarrowVT, X, Y);
19566 return DAG.getNode(ISD::CONCAT_VECTORS, DL, VT, Ops);
19567 }
19568 }
19569
1953919570 if (SDValue V = scalarizeBinOpOfSplats(N, DAG))
1954019571 return V;
1954119572
1501215012 static SDValue getShuffleHalfVectors(const SDLoc &DL, SDValue V1, SDValue V2,
1501315013 ArrayRef HalfMask, int HalfIdx1,
1501415014 int HalfIdx2, bool UndefLower,
15015 SelectionDAG &DAG) {
15015 SelectionDAG &DAG, bool UseConcat = false) {
1501615016 assert(V1.getValueType() == V2.getValueType() && "Different sized vectors?");
1501715017 assert(V1.getValueType().isSimple() && "Expecting only simple types");
1501815018
1503315033 SDValue Half1 = getHalfVector(HalfIdx1);
1503415034 SDValue Half2 = getHalfVector(HalfIdx2);
1503515035 SDValue V = DAG.getVectorShuffle(HalfVT, DL, Half1, Half2, HalfMask);
15036 if (UseConcat) {
15037 SDValue Op0 = V;
15038 SDValue Op1 = DAG.getUNDEF(HalfVT);
15039 if (UndefLower)
15040 std::swap(Op0, Op1);
15041 return DAG.getNode(ISD::CONCAT_VECTORS, DL, VT, Op0, Op1);
15042 }
15043
1503615044 unsigned Offset = UndefLower ? HalfNumElts : 0;
1503715045 return DAG.getNode(ISD::INSERT_SUBVECTOR, DL, VT, DAG.getUNDEF(VT), V,
1503815046 DAG.getIntPtrConstant(Offset, DL));
3397333981 // the wide shuffle that we started with.
3397433982 return getShuffleHalfVectors(SDLoc(Shuf), Shuf->getOperand(0),
3397533983 Shuf->getOperand(1), HalfMask, HalfIdx1,
33976 HalfIdx2, false, DAG);
33984 HalfIdx2, false, DAG, /*UseConcat*/true);
3397733985 }
3397833986
3397933987 static SDValue combineShuffle(SDNode *N, SelectionDAG &DAG,