Skip to content

Commit 660ccf3

Browse files
author
Leon Clark
committed
Address comments.
1 parent 95a75a6 commit 660ccf3

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "X86TargetMachine.h"
2222
#include "llvm/ADT/SmallBitVector.h"
2323
#include "llvm/ADT/SmallSet.h"
24+
#include "llvm/ADT/SmallVector.h"
2425
#include "llvm/ADT/Statistic.h"
2526
#include "llvm/ADT/StringExtras.h"
2627
#include "llvm/ADT/StringSwitch.h"
@@ -37,6 +38,7 @@
3738
#include "llvm/CodeGen/MachineModuleInfo.h"
3839
#include "llvm/CodeGen/MachineRegisterInfo.h"
3940
#include "llvm/CodeGen/SDPatternMatch.h"
41+
#include "llvm/CodeGen/SelectionDAGNodes.h"
4042
#include "llvm/CodeGen/TargetLowering.h"
4143
#include "llvm/CodeGen/WinEHFuncInfo.h"
4244
#include "llvm/IR/CallingConv.h"
@@ -8788,23 +8790,33 @@ static SDValue lowerBuildVectorToBitOp(BuildVectorSDNode *Op, const SDLoc &DL,
87888790
static SDValue lowerBuildVectorAsBlend(BuildVectorSDNode *BVOp, SDLoc const &DL,
87898791
X86Subtarget const &Subtarget,
87908792
SelectionDAG &DAG) {
8791-
if (!Subtarget.hasAVX())
8792-
return {};
8793-
8794-
auto VT = BVOp->getSimpleValueType(0u);
8795-
8796-
if (VT == MVT::v4f64 && BVOp->getNumOperands() == 4u) {
8797-
SDValue Op0 = BVOp->getOperand(0u);
8798-
SDValue Op1 = BVOp->getOperand(1u);
8799-
SDValue Op2 = BVOp->getOperand(2u);
8800-
SDValue Op3 = BVOp->getOperand(3u);
8801-
8802-
// Match X,Y,Y,X inputs.
8803-
if (Op0 == Op3 && Op1 == Op2 && Op0 != Op1) {
8804-
auto NewOp0 = DAG.getSplatBuildVector(VT, DL, Op0);
8805-
auto NewOp1 = DAG.getSplatBuildVector(VT, DL, Op1);
8806-
return DAG.getVectorShuffle(VT, DL, NewOp0, NewOp1, {0, 5, 6, 3});
8807-
}
8793+
MVT VT = BVOp->getSimpleValueType(0u);
8794+
auto const NumElems = VT.getVectorNumElements();
8795+
8796+
if (Subtarget.hasAVX() && VT == MVT::v4f64) {
8797+
// Collect unique operands.
8798+
auto UniqueOps = SmallSet<SDValue, 16u>();
8799+
for (auto &Op : BVOp->ops()) {
8800+
if (isIntOrFPConstant(Op) || Op.get()->isUndef())
8801+
return {};
8802+
UniqueOps.insert(Op);
8803+
}
8804+
// Candidate BUILD_VECTOR must have 2 unique operands.
8805+
if (UniqueOps.size() != 2u)
8806+
return {};
8807+
// Create shuffle mask.
8808+
auto Op0 = BVOp->getOperand(0u);
8809+
auto Mask = std::vector<int>();
8810+
Mask.reserve(NumElems);
8811+
for (auto I = 0u; I < NumElems; ++I) {
8812+
auto &Op = BVOp->getOperand(I);
8813+
Mask.push_back(Op == Op0 ? I : I + NumElems);
8814+
}
8815+
// Create shuffle of splats.
8816+
UniqueOps.erase(Op0);
8817+
auto NewOp0 = DAG.getSplatBuildVector(VT, DL, Op0);
8818+
auto NewOp1 = DAG.getSplatBuildVector(VT, DL, *UniqueOps.begin());
8819+
return DAG.getVectorShuffle(VT, DL, NewOp0, NewOp1, Mask);
88088820
}
88098821

88108822
return {};

0 commit comments

Comments
 (0)