Skip to content

Commit 92a3130

Browse files
committed
using lambda
1 parent e4fdb63 commit 92a3130

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,25 +2319,6 @@ static SDValue lowerVECTOR_SHUFFLE_XVPICKOD(const SDLoc &DL, ArrayRef<int> Mask,
23192319
return DAG.getNode(LoongArchISD::VPICKOD, DL, VT, V2, V1);
23202320
}
23212321

2322-
// Check if exactly one element of the Mask is replaced by 'Replaced', while
2323-
// all other elements are either 'Base + i' or undef (-1). On success, return
2324-
// the index of the replaced element. Otherwise, just return -1.
2325-
static int checkReplaceOne(ArrayRef<int> Mask, int Base, int Replaced) {
2326-
int MaskSize = Mask.size();
2327-
int Idx = -1;
2328-
for (int i = 0; i < MaskSize; ++i) {
2329-
if (Mask[i] == Base + i || Mask[i] == -1)
2330-
continue;
2331-
if (Mask[i] != Replaced)
2332-
return -1;
2333-
if (Idx == -1)
2334-
Idx = i;
2335-
else
2336-
return -1;
2337-
}
2338-
return Idx;
2339-
}
2340-
23412322
/// Lower VECTOR_SHUFFLE into XVINSVE0 (if possible).
23422323
static SDValue
23432324
lowerVECTOR_SHUFFLE_XVINSVE0(const SDLoc &DL, ArrayRef<int> Mask, MVT VT,
@@ -2352,14 +2333,32 @@ lowerVECTOR_SHUFFLE_XVINSVE0(const SDLoc &DL, ArrayRef<int> Mask, MVT VT,
23522333
int MaskSize = Mask.size();
23532334
assert(MaskSize == (int)VT.getVectorNumElements() && "Unexpected mask size");
23542335

2336+
// Check if exactly one element of the Mask is replaced by 'Replaced', while
2337+
// all other elements are either 'Base + i' or undef (-1). On success, return
2338+
// the index of the replaced element. Otherwise, just return -1.
2339+
auto checkReplaceOne = [&](int Base, int Replaced) -> int {
2340+
int Idx = -1;
2341+
for (int i = 0; i < MaskSize; ++i) {
2342+
if (Mask[i] == Base + i || Mask[i] == -1)
2343+
continue;
2344+
if (Mask[i] != Replaced)
2345+
return -1;
2346+
if (Idx == -1)
2347+
Idx = i;
2348+
else
2349+
return -1;
2350+
}
2351+
return Idx;
2352+
};
2353+
23552354
// Case 1: the lowest element of V2 replaces one element in V1.
2356-
int Idx = checkReplaceOne(Mask, 0, MaskSize);
2355+
int Idx = checkReplaceOne(0, MaskSize);
23572356
if (Idx != -1)
23582357
return DAG.getNode(LoongArchISD::XVINSVE0, DL, VT, V1, V2,
23592358
DAG.getConstant(Idx, DL, GRLenVT));
23602359

23612360
// Case 2: the lowest element of V1 replaces one element in V2.
2362-
Idx = checkReplaceOne(Mask, MaskSize, 0);
2361+
Idx = checkReplaceOne(MaskSize, 0);
23632362
if (Idx != -1)
23642363
return DAG.getNode(LoongArchISD::XVINSVE0, DL, VT, V2, V1,
23652364
DAG.getConstant(Idx, DL, GRLenVT));

0 commit comments

Comments
 (0)