Skip to content

Commit 753ac5e

Browse files
author
Leon Clark
committed
Address comments.
1 parent 0edbdd0 commit 753ac5e

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"
@@ -8748,23 +8750,33 @@ static SDValue lowerBuildVectorToBitOp(BuildVectorSDNode *Op, const SDLoc &DL,
87488750
static SDValue lowerBuildVectorAsBlend(BuildVectorSDNode *BVOp, SDLoc const &DL,
87498751
X86Subtarget const &Subtarget,
87508752
SelectionDAG &DAG) {
8751-
if (!Subtarget.hasAVX())
8752-
return {};
8753-
8754-
auto VT = BVOp->getSimpleValueType(0u);
8755-
8756-
if (VT == MVT::v4f64 && BVOp->getNumOperands() == 4u) {
8757-
SDValue Op0 = BVOp->getOperand(0u);
8758-
SDValue Op1 = BVOp->getOperand(1u);
8759-
SDValue Op2 = BVOp->getOperand(2u);
8760-
SDValue Op3 = BVOp->getOperand(3u);
8761-
8762-
// Match X,Y,Y,X inputs.
8763-
if (Op0 == Op3 && Op1 == Op2 && Op0 != Op1) {
8764-
auto NewOp0 = DAG.getSplatBuildVector(VT, DL, Op0);
8765-
auto NewOp1 = DAG.getSplatBuildVector(VT, DL, Op1);
8766-
return DAG.getVectorShuffle(VT, DL, NewOp0, NewOp1, {0, 5, 6, 3});
8767-
}
8753+
MVT VT = BVOp->getSimpleValueType(0u);
8754+
auto const NumElems = VT.getVectorNumElements();
8755+
8756+
if (Subtarget.hasAVX() && VT == MVT::v4f64) {
8757+
// Collect unique operands.
8758+
auto UniqueOps = SmallSet<SDValue, 16u>();
8759+
for (auto &Op : BVOp->ops()) {
8760+
if (isIntOrFPConstant(Op) || Op.get()->isUndef())
8761+
return {};
8762+
UniqueOps.insert(Op);
8763+
}
8764+
// Candidate BUILD_VECTOR must have 2 unique operands.
8765+
if (UniqueOps.size() != 2u)
8766+
return {};
8767+
// Create shuffle mask.
8768+
auto Op0 = BVOp->getOperand(0u);
8769+
auto Mask = std::vector<int>();
8770+
Mask.reserve(NumElems);
8771+
for (auto I = 0u; I < NumElems; ++I) {
8772+
auto &Op = BVOp->getOperand(I);
8773+
Mask.push_back(Op == Op0 ? I : I + NumElems);
8774+
}
8775+
// Create shuffle of splats.
8776+
UniqueOps.erase(Op0);
8777+
auto NewOp0 = DAG.getSplatBuildVector(VT, DL, Op0);
8778+
auto NewOp1 = DAG.getSplatBuildVector(VT, DL, *UniqueOps.begin());
8779+
return DAG.getVectorShuffle(VT, DL, NewOp0, NewOp1, Mask);
87688780
}
87698781

87708782
return {};

0 commit comments

Comments
 (0)