[llvm] [LoongArch] Optimize extractelement containing variable index (PR #151475)
Lu Weining via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 3 18:11:11 PDT 2025
================
@@ -2614,21 +2614,71 @@ LoongArchTargetLowering::lowerEXTRACT_VECTOR_ELT(SDValue Op,
SDValue Idx = Op->getOperand(1);
unsigned NumElts = VecTy.getVectorNumElements();
SDLoc DL(Op);
+ MVT GRLenVT = Subtarget.getGRLenVT();
assert(VecTy.is256BitVector() && "Unexpected EXTRACT_VECTOR_ELT vector type");
if (isa<ConstantSDNode>(Idx) && Idx->getAsZExtVal() < NumElts)
return Op;
- // TODO: Deal with other legal 256-bits vector types?
- if (!isa<ConstantSDNode>(Idx) &&
- (VecTy == MVT::v8i32 || VecTy == MVT::v8f32)) {
- SDValue SplatIdx = DAG.getSplatBuildVector(MVT::v8i32, DL, Idx);
- SDValue SplatValue =
- DAG.getNode(LoongArchISD::XVPERM, DL, VecTy, Vec, SplatIdx);
-
- return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, SplatValue,
- DAG.getConstant(0, DL, Subtarget.getGRLenVT()));
+ if (!isa<ConstantSDNode>(Idx)) {
----------------
SixWeining wrote:
```
if (isa<ConstantSDNode>(Idx)) {
if (Idx->getAsZExtVal() < NumElts)
return Op;
return SDValue();
}
switch(xxx) {
...
}
```
https://github.com/llvm/llvm-project/pull/151475
More information about the llvm-commits
mailing list