Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit e7ec66e

Browse files
committed
ARM64: spot a vector_shuffle that maps to INS and expand.
Tests will be coming very shortly when all the optimisations needed to support AArch64's neon-copy.ll file are committed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206572 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 8405c94 commit e7ec66e

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

lib/Target/ARM64/ARM64ISelLowering.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4093,6 +4093,45 @@ static bool isTRN_v_undef_Mask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) {
40934093
return true;
40944094
}
40954095

4096+
static bool isINSMask(ArrayRef<int> M, int NumInputElements,
4097+
bool &BulkIsLeft, int &Anomaly) {
4098+
if (M.size() != static_cast<size_t>(NumInputElements))
4099+
return false;
4100+
4101+
int NumLHSMatch = 0, NumRHSMatch = 0;
4102+
int LastLHSMismatch = -1, LastRHSMismatch = -1;
4103+
4104+
for (int i = 0; i < NumInputElements; ++i) {
4105+
if (M[i] == -1) {
4106+
++NumLHSMatch;
4107+
++NumRHSMatch;
4108+
continue;
4109+
}
4110+
4111+
if (M[i] == i)
4112+
++NumLHSMatch;
4113+
else
4114+
LastLHSMismatch = i;
4115+
4116+
if (M[i] == i + NumInputElements)
4117+
++NumRHSMatch;
4118+
else
4119+
LastRHSMismatch = i;
4120+
}
4121+
4122+
if (NumLHSMatch == NumInputElements - 1) {
4123+
BulkIsLeft = true;
4124+
Anomaly = LastLHSMismatch;
4125+
return true;
4126+
} else if (NumRHSMatch == NumInputElements - 1) {
4127+
BulkIsLeft = false;
4128+
Anomaly = LastRHSMismatch;
4129+
return true;
4130+
}
4131+
4132+
return false;
4133+
}
4134+
40964135
/// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit
40974136
/// the specified operations to build the shuffle.
40984137
static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS,
@@ -4362,6 +4401,31 @@ SDValue ARM64TargetLowering::LowerVECTOR_SHUFFLE(SDValue Op,
43624401
return DAG.getNode(Opc, dl, V1.getValueType(), V1, V1);
43634402
}
43644403

4404+
bool DstIsLeft;
4405+
int Anomaly;
4406+
int NumInputElements = V1.getValueType().getVectorNumElements();
4407+
if (isINSMask(ShuffleMask, NumInputElements, DstIsLeft, Anomaly)) {
4408+
SDValue DstVec = DstIsLeft ? V1 : V2;
4409+
SDValue DstLaneV = DAG.getConstant(Anomaly, MVT::i64);
4410+
4411+
SDValue SrcVec = V1;
4412+
int SrcLane = ShuffleMask[Anomaly];
4413+
if (SrcLane >= NumInputElements) {
4414+
SrcVec = V2;
4415+
SrcLane -= VT.getVectorNumElements();
4416+
}
4417+
SDValue SrcLaneV = DAG.getConstant(SrcLane, MVT::i64);
4418+
4419+
EVT ScalarVT = VT.getVectorElementType();
4420+
if (ScalarVT.getSizeInBits() < 32)
4421+
ScalarVT = MVT::i32;
4422+
4423+
return DAG.getNode(
4424+
ISD::INSERT_VECTOR_ELT, dl, VT, DstVec,
4425+
DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, ScalarVT, SrcVec, SrcLaneV),
4426+
DstLaneV);
4427+
}
4428+
43654429
// If the shuffle is not directly supported and it has 4 elements, use
43664430
// the PerfectShuffle-generated table to synthesize it from other shuffles.
43674431
unsigned NumElts = VT.getVectorNumElements();

0 commit comments

Comments
 (0)