[llvm] [RISCV] Fold extract_vector_elt of a load info the scalar load (PR #76151)
Wang Pengcheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 21 21:25:19 PST 2023
================
@@ -14466,6 +14466,40 @@ 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();
+ auto *CIdx = dyn_cast<ConstantSDNode>(EltIdx);
+ // extract_vec_elt (load X), C --> scalar load (X+C)
+ if (LoadVec && CIdx && ISD::isNormalLoad(LoadVec) && LoadVec->isSimple()) {
----------------
wangpc-pp wrote:
I think we can also optimize the case that `EltIdx` isn't constant.
https://github.com/llvm/llvm-project/pull/76151
More information about the llvm-commits
mailing list