Skip to content

Commit 60c4561

Browse files
committed
address comments
1 parent 485757a commit 60c4561

File tree

1 file changed

+73
-79
lines changed

1 file changed

+73
-79
lines changed

llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

Lines changed: 73 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,93 +2612,87 @@ LoongArchTargetLowering::lowerEXTRACT_VECTOR_ELT(SDValue Op,
26122612
SDValue Vec = Op->getOperand(0);
26132613
EVT VecTy = Vec->getValueType(0);
26142614
SDValue Idx = Op->getOperand(1);
2615-
unsigned NumElts = VecTy.getVectorNumElements();
26162615
SDLoc DL(Op);
26172616
MVT GRLenVT = Subtarget.getGRLenVT();
26182617

26192618
assert(VecTy.is256BitVector() && "Unexpected EXTRACT_VECTOR_ELT vector type");
26202619

2621-
if (isa<ConstantSDNode>(Idx) && Idx->getAsZExtVal() < NumElts)
2620+
if (isa<ConstantSDNode>(Idx))
26222621
return Op;
26232622

2624-
if (!isa<ConstantSDNode>(Idx)) {
2625-
switch (VecTy.getSimpleVT().SimpleTy) {
2626-
default:
2627-
llvm_unreachable("Unexpected type");
2628-
case MVT::v32i8:
2629-
case MVT::v16i16: {
2630-
// Consider the source vector as v8i32 type.
2631-
SDValue NewVec = DAG.getBitcast(MVT::v8i32, Vec);
2632-
2633-
// Compute the adjusted index and use it to broadcast the vector.
2634-
// The original desired i8/i16 element is now replicated in each
2635-
// i32 lane of the splatted vector.
2636-
SDValue NewIdx = DAG.getNode(
2637-
LoongArchISD::BSTRPICK, DL, GRLenVT, Idx,
2638-
DAG.getConstant(31, DL, GRLenVT),
2639-
DAG.getConstant(((VecTy == MVT::v32i8) ? 2 : 1), DL, GRLenVT));
2640-
SDValue SplatIdx = DAG.getSplatBuildVector(MVT::v8i32, DL, NewIdx);
2641-
SDValue SplatValue =
2642-
DAG.getNode(LoongArchISD::XVPERM, DL, MVT::v8i32, NewVec, SplatIdx);
2643-
SDValue SplatVec = DAG.getBitcast(VecTy, SplatValue);
2644-
2645-
// Compute the local index of the original i8/i16 element within the
2646-
// i32 element and then use it to broadcast the vector. Each elements
2647-
// of the vector will be the desired element.
2648-
SDValue LocalIdx = DAG.getNode(
2649-
ISD::AND, DL, GRLenVT, Idx,
2650-
DAG.getConstant(((VecTy == MVT::v32i8) ? 3 : 1), DL, GRLenVT));
2651-
SDValue ExtractVec =
2652-
DAG.getNode(LoongArchISD::VREPLVE, DL, VecTy, SplatVec, LocalIdx);
2653-
2654-
return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, ExtractVec,
2655-
DAG.getConstant(0, DL, GRLenVT));
2656-
}
2657-
case MVT::v8i32:
2658-
case MVT::v8f32: {
2659-
SDValue SplatIdx = DAG.getSplatBuildVector(MVT::v8i32, DL, Idx);
2660-
SDValue SplatValue =
2661-
DAG.getNode(LoongArchISD::XVPERM, DL, VecTy, Vec, SplatIdx);
2662-
2663-
return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, SplatValue,
2664-
DAG.getConstant(0, DL, GRLenVT));
2665-
}
2666-
case MVT::v4i64:
2667-
case MVT::v4f64: {
2668-
// Consider the source vector as v8i32 type.
2669-
SDValue NewVec = DAG.getBitcast(MVT::v8i32, Vec);
2670-
2671-
// Split the original element index into low and high parts:
2672-
// Lo = Idx * 2, Hi = Idx * 2 + 1.
2673-
SDValue SplatIdx = DAG.getSplatBuildVector(MVT::v8i32, DL, Idx);
2674-
SDValue SplatIdxLo =
2675-
DAG.getNode(LoongArchISD::VSLLI, DL, MVT::v8i32, SplatIdx,
2676-
DAG.getConstant(1, DL, GRLenVT));
2677-
SDValue SplatIdxHi =
2678-
DAG.getNode(ISD::ADD, DL, MVT::v8i32, SplatIdxLo,
2679-
DAG.getSplatBuildVector(MVT::v8i32, DL,
2680-
DAG.getConstant(1, DL, GRLenVT)));
2681-
2682-
// Use the broadcasted index to broadcast the low and high parts of the
2683-
// vector separately.
2684-
SDValue SplatVecLo =
2685-
DAG.getNode(LoongArchISD::XVPERM, DL, MVT::v8i32, NewVec, SplatIdxLo);
2686-
SDValue SplatVecHi =
2687-
DAG.getNode(LoongArchISD::XVPERM, DL, MVT::v8i32, NewVec, SplatIdxHi);
2688-
2689-
// Combine the low and high i32 parts to reconstruct the original i64/f64
2690-
// element.
2691-
SDValue SplatValue = DAG.getNode(LoongArchISD::VILVL, DL, MVT::v8i32,
2692-
SplatVecHi, SplatVecLo);
2693-
SDValue ExtractVec = DAG.getBitcast(VecTy, SplatValue);
2694-
2695-
return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, ExtractVec,
2696-
DAG.getConstant(0, DL, GRLenVT));
2697-
}
2698-
}
2623+
switch (VecTy.getSimpleVT().SimpleTy) {
2624+
default:
2625+
llvm_unreachable("Unexpected type");
2626+
case MVT::v32i8:
2627+
case MVT::v16i16: {
2628+
// Consider the source vector as v8i32 type.
2629+
SDValue NewVec = DAG.getBitcast(MVT::v8i32, Vec);
2630+
2631+
// Compute the adjusted index and use it to broadcast the vector.
2632+
// The original desired i8/i16 element is now replicated in each
2633+
// i32 lane of the splatted vector.
2634+
SDValue NewIdx = DAG.getNode(
2635+
LoongArchISD::BSTRPICK, DL, GRLenVT, Idx,
2636+
DAG.getConstant(31, DL, GRLenVT),
2637+
DAG.getConstant(((VecTy == MVT::v32i8) ? 2 : 1), DL, GRLenVT));
2638+
SDValue SplatIdx = DAG.getSplatBuildVector(MVT::v8i32, DL, NewIdx);
2639+
SDValue SplatValue =
2640+
DAG.getNode(LoongArchISD::XVPERM, DL, MVT::v8i32, NewVec, SplatIdx);
2641+
SDValue SplatVec = DAG.getBitcast(VecTy, SplatValue);
2642+
2643+
// Compute the local index of the original i8/i16 element within the
2644+
// i32 element and then use it to broadcast the vector. Each elements
2645+
// of the vector will be the desired element.
2646+
SDValue LocalIdx = DAG.getNode(
2647+
ISD::AND, DL, GRLenVT, Idx,
2648+
DAG.getConstant(((VecTy == MVT::v32i8) ? 3 : 1), DL, GRLenVT));
2649+
SDValue ExtractVec =
2650+
DAG.getNode(LoongArchISD::VREPLVE, DL, VecTy, SplatVec, LocalIdx);
2651+
2652+
return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, ExtractVec,
2653+
DAG.getConstant(0, DL, GRLenVT));
2654+
}
2655+
case MVT::v8i32:
2656+
case MVT::v8f32: {
2657+
SDValue SplatIdx = DAG.getSplatBuildVector(MVT::v8i32, DL, Idx);
2658+
SDValue SplatValue =
2659+
DAG.getNode(LoongArchISD::XVPERM, DL, VecTy, Vec, SplatIdx);
2660+
2661+
return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, SplatValue,
2662+
DAG.getConstant(0, DL, GRLenVT));
2663+
}
2664+
case MVT::v4i64:
2665+
case MVT::v4f64: {
2666+
// Consider the source vector as v8i32 type.
2667+
SDValue NewVec = DAG.getBitcast(MVT::v8i32, Vec);
2668+
2669+
// Split the original element index into low and high parts:
2670+
// Lo = Idx * 2, Hi = Idx * 2 + 1.
2671+
SDValue SplatIdx = DAG.getSplatBuildVector(MVT::v8i32, DL, Idx);
2672+
SDValue SplatIdxLo = DAG.getNode(LoongArchISD::VSLLI, DL, MVT::v8i32,
2673+
SplatIdx, DAG.getConstant(1, DL, GRLenVT));
2674+
SDValue SplatIdxHi =
2675+
DAG.getNode(ISD::ADD, DL, MVT::v8i32, SplatIdxLo,
2676+
DAG.getSplatBuildVector(MVT::v8i32, DL,
2677+
DAG.getConstant(1, DL, GRLenVT)));
2678+
2679+
// Use the broadcasted index to broadcast the low and high parts of the
2680+
// vector separately.
2681+
SDValue SplatVecLo =
2682+
DAG.getNode(LoongArchISD::XVPERM, DL, MVT::v8i32, NewVec, SplatIdxLo);
2683+
SDValue SplatVecHi =
2684+
DAG.getNode(LoongArchISD::XVPERM, DL, MVT::v8i32, NewVec, SplatIdxHi);
2685+
2686+
// Combine the low and high i32 parts to reconstruct the original i64/f64
2687+
// element.
2688+
SDValue SplatValue = DAG.getNode(LoongArchISD::VILVL, DL, MVT::v8i32,
2689+
SplatVecHi, SplatVecLo);
2690+
SDValue ExtractVec = DAG.getBitcast(VecTy, SplatValue);
2691+
2692+
return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, ExtractVec,
2693+
DAG.getConstant(0, DL, GRLenVT));
2694+
}
26992695
}
2700-
2701-
return SDValue();
27022696
}
27032697

27042698
SDValue

0 commit comments

Comments
 (0)