[llvm] [RISCV] Fold extract_vector_elt of a load into the scalar load (PR #76151)

Liao Chunyu via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 24 19:15:40 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()) {
----------------
ChunyuLiao wrote:

I've found some testcase that EltIdx isn't constant, look better for vectors. https://alive2.llvm.org/ce/z/ELEdqx

https://github.com/llvm/llvm-project/pull/76151


More information about the llvm-commits mailing list