[llvm] [RISCV] Fold extract_vector_elt of a load into the scalar load (PR #76151)
Yeting Kuo via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 26 19:56:24 PST 2023
================
@@ -14466,6 +14466,59 @@ static SDValue performINSERT_VECTOR_ELTCombine(SDNode *N, SelectionDAG &DAG,
return DAG.getNode(ISD::CONCAT_VECTORS, DL, VT, ConcatOps);
}
+static SDValue
+performEXTRACT_VECTOR_ELTCombine(SDNode *N, SelectionDAG &DAG,
+ const RISCVSubtarget &Subtarget,
+ const RISCVTargetLowering &TLI) {
+ SDValue InputVec = N->getOperand(0);
+ SDValue EltIdx = N->getOperand(1);
+ SDLoc DL(N);
+
+ EVT InVecVT = InputVec.getValueType();
+ if (InVecVT.isScalableVector())
+ return SDValue();
+
+ if (!InputVec.hasOneUse())
+ return SDValue();
+
+ auto *LoadVec = dyn_cast<LoadSDNode>(InputVec);
+ EVT VecEltVT = InVecVT.getVectorElementType();
+ // extract_vec_elt (load X), C --> scalar load (X+C)
+ if (LoadVec && ISD::isNormalLoad(LoadVec) && LoadVec->isSimple()) {
+ const TargetLowering &TLI = DAG.getTargetLoweringInfo();
+ SDValue NewPtr = TLI.getVectorElementPointer(DAG, LoadVec->getBasePtr(),
+ InVecVT, EltIdx);
+ Align Alignment = LoadVec->getAlign();
+ MachinePointerInfo MPI;
+ if (auto *ConstEltNo = dyn_cast<ConstantSDNode>(EltIdx)) {
+ int Elt = ConstEltNo->getZExtValue();
----------------
yetingk wrote:
int -> unsigned
https://github.com/llvm/llvm-project/pull/76151
More information about the llvm-commits
mailing list